Lazarus
21/02/2009, 12: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.
[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.