SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 03/02/2018, 12:51 AM   #1
Redirect Left
High-roller
 
Redirect Left's Avatar
 
Join Date: Mar 2007
Location: Yorkshire, England
Posts: 1,024
Reputation: 371
Default Split Square Into Smaller Squares

Hi

I'm looking for some code to basically split a square into lots of equal sized squares, rectangles would also work.
I need this so I can quickly and rapidly make a set of gangzones.

If I can figure out how to make a function, input the max x & y, and minimum x & y, and it out puts a bunch of co-ords for the max x & y and min x & y of smaller squares, for the gangzones.

Anyone any idea how I would achieve this sort of math in Pawn?

- Cheers
__________________
Redirect Left, y'know? The one who started the Sumo Server craze? that's me, click here to play it!
I also run Mini-Missions, again, only 9 years after my last run at it! Life is ace, aint it?!
Redirect Left is offline   Reply With Quote
Old 03/02/2018, 12:59 AM   #2
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,651
Reputation: 558
Default Re: Split Square Into Smaller Squares

You basically just have to split the rectangle/square into X parts, take that length and multiply it by X + the base coords to get the Xth square coordinates.

eg.

To split a 100.0, 100.0 sqaure into 10 squares you need to divide the coords by 10, which results in 10.0, 10.0.
To get the 5th square on the X axis you would do 5x 10.0 to get the minX value, add 10.0 to get maxX for that square.

That would result in the coords 50.0, 0.0, 60.0, 10.0 (minX, maxX, minY, maxY).

Code:
splitsquares(Float:sizeX = 100.0, Float:sizeY = 100.0, num = 5)
{
new Float:offsetX = sizeX / num, Float:offsetY = sizeY / num;

for(new x = 0; x < num; x ++) for(new y = 0; y < num; y ++)
{
new Float:minX = x * offsetX, Float:maxX = minX + sizeX;
new Float:minY = y * offsetY, Float:maxY = minY + sizeY;

// Do stuff with minX, maxX, minY, maxY...
}
}
NaS is offline   Reply With Quote
Old 03/02/2018, 01:17 AM   #3
Marricio
Gangsta
 
Join Date: Dec 2010
Posts: 719
Reputation: 96
Default Re: Split Square Into Smaller Squares

Quote:
Originally Posted by NaS View Post
Code:
splitsquares(Float:sizeX = 100.0, Float:sizeY = 100.0, num = 5)
{
new Float:offsetX = sizeX / num, Float:offsetY = sizeY / num;

for(new x = 0; x < num; x ++) for(new y = 0; y < num; y ++)
{
new Float:minX = x * offsetX, Float:maxX = minX + sizeX;
new Float:minY = y * offsetY, Float:maxY = minY + sizeY;

// Do stuff with minX, maxX, minY, maxY...
}
}
Correct me if wrong, but isn't that code going to generate 25 squares?

EDIT: I mean, I don't think that would work with a strict amount of squares.
Marricio is offline   Reply With Quote
Old 03/02/2018, 01:19 AM   #4
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,651
Reputation: 558
Default Re: Split Square Into Smaller Squares

Quote:
Originally Posted by Marricio View Post
Correct me if wrong, but isn't that code going to generate 25 squares?
Yes, because 5x5 is 25 (which is correct for 5x5 zones).
NaS is offline   Reply With Quote
Old 03/02/2018, 01:20 AM   #5
Marricio
Gangsta
 
Join Date: Dec 2010
Posts: 719
Reputation: 96
Default Re: Split Square Into Smaller Squares

Quote:
Originally Posted by NaS View Post
Yes, because 5x5 is 25.
Welp, I'm assuming the "n" argument in your function is actually the square amount.
Marricio is offline   Reply With Quote
Old 03/02/2018, 01:28 AM   #6
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,651
Reputation: 558
Default Re: Split Square Into Smaller Squares

Quote:
Originally Posted by Marricio View Post
Welp, I'm assuming the "n" argument in your function is actually the square amount.
Oh yea it's the amount of squares on the axes, if it should be for different amount of rectangles per axis it just requires a second num variable, one for X and one for Y.
NaS is offline   Reply With Quote
Old 03/02/2018, 05:58 PM   #7
Redirect Left
High-roller
 
Redirect Left's Avatar
 
Join Date: Mar 2007
Location: Yorkshire, England
Posts: 1,024
Reputation: 371
Default Re: Split Square Into Smaller Squares

Would be nice if I could also specify the amount of squares to create - which would in turn also control how big each square is. IE 100 squares will be a lot smaller than 50 squares.

I'm all a little confused, algebra is not forté at all
Really grateful for your replies so far.
__________________
Redirect Left, y'know? The one who started the Sumo Server craze? that's me, click here to play it!
I also run Mini-Missions, again, only 9 years after my last run at it! Life is ace, aint it?!
Redirect Left is offline   Reply With Quote
Old 03/02/2018, 06:26 PM   #8
NaS
High-roller
 
NaS's Avatar
 
Join Date: Mar 2008
Location: 🇩🇪
Posts: 1,651
Reputation: 558
Default Re: Split Square Into Smaller Squares

Quote:
Originally Posted by Redirect Left View Post
Would be nice if I could also specify the amount of squares to create - which would in turn also control how big each square is. IE 100 squares will be a lot smaller than 50 squares.

I'm all a little confused, algebra is not forté at all
Really grateful for your replies so far.
If you want 5 from an equation 5*5, you must get the square root. So, to get the number 5 like in my example, you have to calculate the square root of 25.

If you want 64 squares, it's 8 since 8*8 = 64, etc.
NaS is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Off] Game about Squares Nekos Português/Portuguese 10 09/08/2014 07:05 AM
[Map] Looking for a smaller map, roleplay Lorenzo* Maps 5 10/02/2013 02:33 PM
[Solved] Help needed with squares around TD boxes... Miguel Help Archive 5 24/05/2010 12:37 AM
As the radar hide squares? linoxtrala Help Archive 2 15/12/2009 03:48 PM


All times are GMT. The time now is 04:37 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.