Areacheck
From SA-MP Wiki
First, you should know, that this script works like this...
_________________ Point 2; | | | This is | | the area that | | you want | | to define! | |________________| Point 1;
Now, this script will be useful, in situations where you want to detect if a player has entered in certain area, like for example and "Admin area".
I will show you some photos of how to do this
Ok, here you have a photo of the Golf Club located on Las Venturas. In my case, I made this area privated, with some REALLY nice tuned cars inside, only for Admin use. So, how to do this?. Easy.
The first thing to do, is to get the X and Y coordinates of the WHITE CROSS and the GREEN CROSS (the ones that defines our area corner.
One easy way to get those coordinates, is to add in your gamemode/filterscript a little command to get player position, like this.
public OnPlayerCommandText(playerid, cmdtext[]) { if (strcmp("/pos", cmdtext, true) == 0) { new string1[256]; new Float:X,Float:Y,Float:Z; GetPlayerPos(playerid,X,Y,Z); format(string1,sizeof(string1),"Position = X: %.0f , Y: %.0f , Z: %.0f",X,Y,Z); SendClientMessage(playerid,COLOR_GREEN,string1); return 1; } return 0; }
Now, when you type /pos, you will get a message saying "Position = number, number, number". And then, with that data, we can move on to the next step.
Now that we know how to retrieve player's position, we should take our player to the White and Green crosses and get the X and Y coordinate of each one. Once you finish this, we're ready to script the function.
First, you will need to forward you function.
forward isPlayerInArea();
Next add a timer which activates the function.
SetTimer("isPlayerInArea", 1000, 1);
Ok, we have just set the timer to check if a player entered the area every 1 second.
Next we're going to create the public declaration.
public isPlayerInArea() { new Float:X, Float:Y, Float:Z; //We use this to store player position for(new i=0; i < MAX_PLAYERS; i++) //This line defines a name for all player, the name is "i" { GetPlayerPos(i, X, Y, Z); //Here we are storing the player position on the variables X, Y, and Z defined previously if (X <= -3915 && X >= -3694 && Y <= 401 && Y >= 37) /* This line is the important one!. Here, is where you change those numbers, by the ones you get from the /pos command. As you can see, those coordinates, are only the X and Y ones, the Z doesnt matter*/ { SetPlayerHealth(i, -999999.9); //This will ensure, that our player gets killed if he tries to enter } } }
Now, if a player enters the area, between X= -3915 and -3694 || Y= 401 and 37. He will die.
Ok, that's all, and I really hope that this tutorial would help someone.
Web