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
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

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)
(200¹, 500¹) <- MAX
(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?