PDA

View Full Version : [Tutorial] [tut] IsPlayerInArea


Lazarus
21/02/2009, 01:21 AM
If you don't want to go through the irritable making of a valid IsPlayerInArea function, you could always use:
[FS] IsPlayerInArea Maker - SeifArea - Get IsPlayerInArea easy! (http://forum.sa-mp.com/index.php?action=profile;u=32458)

_________________________________________________

IsPlayerInArea

Syntax
IsPlayerInArea asks for:
playerid, Float:minx, Float:maxx, Float:miny, Float:maxy

Reality
Let's put it into graph terms...

600 |
500 |
400 |
/*Y*/ 300 |
200 |
100 |_________________________________________________ ________
0 100 200 300 400 500 600
/*X <- read X first*/

When you /save in sa-mp, your given the X, Y, and Z position. We're not going to work with Z, no worries :P.

Go to your first position in SA-MP, and save. Then go to your second position.

Lets just say:
600 |
500 | 1 //you saved here first
400 |
/*Y*/ 300 | 2 //you saved here second
200 |
100 |_________________________________________________ ________
0 100 200 300 400 500 600
/*X*/

Coordinates
Coordinates are written as:
(X, Y)
Your first save would be:
(200, 500) <- MAX
And your second save:
(500, 300) <- MIN

Now you rearrange them to the IsPlayerInArea syntax:
Min X: 500
Max X: 200,
Min Y: 300
Max Y: 500,
Take note of the s and s. Their not actually in the code, just matching them so you know whats going where.

Then you simply insert them:
IsPlayerInArea(playerid, 500, 200, 300, 500)

That will check if the player is in:
600 |
500 | (200, 500)/*-------------------------*/
400 | /*---THIS-AREA-------------*/
/*Y*/ 300 | /*-------------------------*/(500, 300)
200 |
100 |_________________________________________________ ________
0 100 200 300 400 500 600
/*X*/

Returns
IsPlayerInArea returns 0 (false) if they are not in the area, and 1 (true) if they are.

Examples
if(IsPlayerInArea(playerid, 500, 200, 300, 500) == true)
{
Kick(playerid);
}
Kick them if they are (true) in that area.

if(IsPlayerInArea(playerid, 500, 200, 300, 500) == false)
{
GivePlayerMoney(playerid, 100);
}
Give them $100 if they are not.

_________________________________________________

IsPlayerInArea
IsPlayerInArea(playerid, Float:minx, Float:maxx, Float:miny, Float:maxy)
{
new Float:x, Float:y, Float:z;
GetPlayerPos(playerid, x, y, z);
if (x > minx && x < maxx && y > miny && y < maxy) return 1;
return 0;
}

Rofl, I hope I didn't fail horribly.

x-cutter
21/02/2009, 01:40 AM
I'm sorry, but you did...









































not!

You should reference Seif's IsPlayerInArea Maker filterscript though

Lazarus
21/02/2009, 01:47 AM
Good idea ;).

Norn
21/02/2009, 03:06 AM
if(!IsPlayerInArea(playerid, 500, 200, 300, 500))
{
GivePlayerMoney(playerid, 100);
}

Another way to use == false. (For those that don't know).

Ritchie999
02/11/2009, 04:22 PM
epic bump for an epic fail, the link you posted in the tutorial takes us to Zezombia's profile

Petrikk
03/02/2011, 11:58 AM
does anyone has a link of this INC i need it realy hard

deviljingoku
13/02/2011, 07:39 PM
i got this error:- error 017: undefined symbol "IsPlayerInArea"

Steven82
14/02/2011, 06:11 AM
Did we really feel like bumping this?