31.03.2012, 02:32
Introduction
This short and sweet tutorial was designed for the beginner scripter. By the end of this tutorial you should be able to create both entrances and exits for structures all over your server! I will explain everything as thoroughly as I feel it needs to be. If you feel that there is an aspect that needs expanding on, please post here, and I will do so.
References
During this tutorial we will use all of the below functions at one point or another, so it would behoove you to familiarize yourself with them before continuing on.
https://sampwiki.blast.hk/wiki/AddStaticPickup
https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint
https://sampwiki.blast.hk/wiki/SetPlayerPos
https://sampwiki.blast.hk/wiki/SetPlayerInterior
https://sampwiki.blast.hk/wiki/AddPlayerClass
Getting the coordinates for your entrance
The first step in creating an entry or exit point is gaining the coordinates (x, y, and z values) for the points. For this you will use /save. Go in-game, and move to the building you would like to script an entrance/exit for. We will use the Commerce Ammunation as an example. Once in front of the door, use /save [Position name]. For our example, /save AmmunationEntrance. Our exit coordinates will be found later.
Getting the coordinates for your entrance - pt. 2.
Once you've completed the above, /q, and navigate to your documents. Open the SAMP folder found in your San Andreas user files (In my case, C:\Users\Devon\Documents\GTA San Andreas User Files\SAMP) and look for a savedpositions.txt. Open the file and inside you will see a new AddPlayerClass (Or AddStaticVehicle, if you /save'd inside a car) line for each time you've used the /save command. The further down the list of lines the more recent the line was written. We will look for our AmmunationEntrance line that we made earlier.
Now, we only need the X, Y, and Z coordinates for our goal. When looking at the AddPlayerClass reference from above, we can see that the second, third, and fourth parameters of AddPlayerClass are the values we need. Select and copy those values.
Creating the Icon
Open your script and find your OnGameModeInit callback. This is where we will be creating our entrance icons, or pickups. We will use AddStaticPickup to do this. The parameters for AddStaticPickup are:
Within the model parameter, enter any value you find here: http://weedarr.wikidot.com/pickups. We will use the "i" icon, ID 1239.
The different icon types are found here: http://weedarr.wikidot.com/pickups. We will use type 1, as it causes the icon to simply spawn and to stay present no matter what.
The Float:X, Float:Y, and Float:Z are the values you copied from the savedpositions.txt earlier in this tutorial. For these three parameters, you will right-click and paste them onto your AddStaticPickup line.
The last parameter is the virtualworld value. Unless you have a complete understanding of how virtual worlds work and know what you are doing, enter -1 in this field to show the icon in all worlds. The below AddStaticPickup line is what you should have at this point:
Moving on to the commands
Now for the commands themselves. /enter and /exit.
Here we used three main functions. The first, IsPlayerInRangeOfPoint, the wiki link of which is posted in the references section above, is used to detect if the player is near (3.0 unit radius in this case) the specified point. We put this function to use to detect first if the player is near the Ammunation door, for /enter, and second to detect if the player is in the interior of Ammunation, for /exit.
Next was SetPlayerPos. In /enter, we set the position of playerid (the user of /enter) to the coordinates of the Ammunation interior, and in /exit, to set the position of playerid (the user of /exit) to the coordinates we saved earlier, the Ammunation front door. You may find the coordinates of every interior here: http://weedarr.wikidot.com/interior. The same place where you find the ID for each interior, an ID that we used in our next function:
SetPlayerInterior. In /enter, we found and set the player to not only the coordinates of the Ammunation interior, but also to the Ammunation interior ID (1). 0, the default (no interior) interior ID, was set on /exit, to remove the player from the Ammunation interior's world and replace him to your realm.
Adding multiple entry and exit points.
To add a second, third, and even a fourth entry and exit point it really is no pain at all. Repeat the steps from above with your new building's X, Y, and Z coordinates and copy your already-existing enter and exit lines, changing obviously the interior ids (unless they are the same) and the IsPlayerInRangeOfPoint and SetPlayerPos coordinates.
An example of the above, excluding the AddStaticPickup bits
The end. That really is all there is to it, looks like I was thorough enough with everthing. I hope I helped!
This short and sweet tutorial was designed for the beginner scripter. By the end of this tutorial you should be able to create both entrances and exits for structures all over your server! I will explain everything as thoroughly as I feel it needs to be. If you feel that there is an aspect that needs expanding on, please post here, and I will do so.
References
During this tutorial we will use all of the below functions at one point or another, so it would behoove you to familiarize yourself with them before continuing on.
https://sampwiki.blast.hk/wiki/AddStaticPickup
https://sampwiki.blast.hk/wiki/IsPlayerInRangeOfPoint
https://sampwiki.blast.hk/wiki/SetPlayerPos
https://sampwiki.blast.hk/wiki/SetPlayerInterior
https://sampwiki.blast.hk/wiki/AddPlayerClass
Getting the coordinates for your entrance
The first step in creating an entry or exit point is gaining the coordinates (x, y, and z values) for the points. For this you will use /save. Go in-game, and move to the building you would like to script an entrance/exit for. We will use the Commerce Ammunation as an example. Once in front of the door, use /save [Position name]. For our example, /save AmmunationEntrance. Our exit coordinates will be found later.
Getting the coordinates for your entrance - pt. 2.
Once you've completed the above, /q, and navigate to your documents. Open the SAMP folder found in your San Andreas user files (In my case, C:\Users\Devon\Documents\GTA San Andreas User Files\SAMP) and look for a savedpositions.txt. Open the file and inside you will see a new AddPlayerClass (Or AddStaticVehicle, if you /save'd inside a car) line for each time you've used the /save command. The further down the list of lines the more recent the line was written. We will look for our AmmunationEntrance line that we made earlier.
pawn Код:
AddPlayerClass(105,1367.5817,-1279.9658,13.5469,271.7646,0,0,0,0,0,0); // AmmunationEntrance
Creating the Icon
Open your script and find your OnGameModeInit callback. This is where we will be creating our entrance icons, or pickups. We will use AddStaticPickup to do this. The parameters for AddStaticPickup are:
Код:
(model, type, Float:X, Float:Y, Float:Z, Virtualworld)
The different icon types are found here: http://weedarr.wikidot.com/pickups. We will use type 1, as it causes the icon to simply spawn and to stay present no matter what.
The Float:X, Float:Y, and Float:Z are the values you copied from the savedpositions.txt earlier in this tutorial. For these three parameters, you will right-click and paste them onto your AddStaticPickup line.
The last parameter is the virtualworld value. Unless you have a complete understanding of how virtual worlds work and know what you are doing, enter -1 in this field to show the icon in all worlds. The below AddStaticPickup line is what you should have at this point:
pawn Код:
public OnGameModeInit()
{
AddStaticPickup(1239, 1, 1366.3108,-1279.5417,13.5469, -1);//AmmunationEntrance
//Your other OnGameModeInit code.
return 1;
}
Now for the commands themselves. /enter and /exit.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/enter", true))
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, 1366.3108,-1279.5417,13.5469))
{
SetPlayerPos(playerid, 286.148986,-40.644397,1001.515625);//AmmunationEntrance
SetPlayerInterior(playerid, 1);
}
}
if(!strcmp(cmdtext, "/exit", true))
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, 286.148986,-40.644397,1001.515625))
{
SetPlayerPos(playerid, 1366.3108,-1279.5417,13.5469);//AmmunationExit
SetPlayerInterior(playerid, 0);
}
}
return 1;
}
Next was SetPlayerPos. In /enter, we set the position of playerid (the user of /enter) to the coordinates of the Ammunation interior, and in /exit, to set the position of playerid (the user of /exit) to the coordinates we saved earlier, the Ammunation front door. You may find the coordinates of every interior here: http://weedarr.wikidot.com/interior. The same place where you find the ID for each interior, an ID that we used in our next function:
SetPlayerInterior. In /enter, we found and set the player to not only the coordinates of the Ammunation interior, but also to the Ammunation interior ID (1). 0, the default (no interior) interior ID, was set on /exit, to remove the player from the Ammunation interior's world and replace him to your realm.
Adding multiple entry and exit points.
To add a second, third, and even a fourth entry and exit point it really is no pain at all. Repeat the steps from above with your new building's X, Y, and Z coordinates and copy your already-existing enter and exit lines, changing obviously the interior ids (unless they are the same) and the IsPlayerInRangeOfPoint and SetPlayerPos coordinates.
An example of the above, excluding the AddStaticPickup bits
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
if(!strcmp(cmdtext, "/enter", true))
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, 1366.3108,-1279.5417,13.5469))
{
SetPlayerPos(playerid, 286.148986,-40.644397,1001.515625);//AmmunationEntrance
SetPlayerInterior(playerid, 1);
}
if(IsPlayerInRangeOfPoint(playerid, 3.0, 2229.5374,-1721.7302,13.5658))
{
SetPlayerPos(playerid, 773.579956,-77.096694,1000.655029);//GantonGymEntrance
SetPlayerInterior(playerid, 7);
}
if(IsPlayerInRangeOfPoint(playerid, 3.0, 1284.6202,-1585.2909,13.5469))
{
SetPlayerPos(playerid, -2029.798339,-106.675910,1035.171875);//LicenseCenterEntrance
SetPlayerInterior(playerid, 3);
}
}
if(!strcmp(cmdtext, "/exit", true))
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, 286.148986,-40.644397,1001.515625))
{
SetPlayerPos(playerid, 1366.3108,-1279.5417,13.5469);//AmmunationExit
SetPlayerInterior(playerid, 0);
}
if(IsPlayerInRangeOfPoint(playerid, 3.0, 286.148986,-40.644397,1001.515625))
{
SetPlayerPos(playerid, 1366.3108,-1279.5417,13.5469);//AmmunationExit
SetPlayerInterior(playerid, 0);
}
if(IsPlayerInRangeOfPoint(playerid, 3.0, 773.579956,-77.096694,1000.655029))
{
SetPlayerPos(playerid, 2229.5374,-1721.7302,13.5658);//GantonGymExit
SetPlayerInterior(playerid, 0);
}
if(IsPlayerInRangeOfPoint(playerid, 3.0, -2029.798339,-106.675910,1035.171875))
{
SetPlayerInterior(playerid, 0);
SetPlayerPos(playerid, 1284.6202,-1585.2909,13.5469);//LicenseCenterExit
}
}
return 1;
}