[Tutorial] Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands]
#1

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.
pawn Код:
AddPlayerClass(105,1367.5817,-1279.9658,13.5469,271.7646,0,0,0,0,0,0); // AmmunationEntrance
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:
Код:
(model, type, Float:X, Float:Y, Float:Z, Virtualworld)
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:
pawn Код:
public OnGameModeInit()
{
    AddStaticPickup(1239, 1, 1366.3108,-1279.5417,13.5469, -1);//AmmunationEntrance
    //Your other OnGameModeInit code.
    return 1;
}
Moving on to the commands
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;
}
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
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;
}
The end. That really is all there is to it, looks like I was thorough enough with everthing. I hope I helped!
Reply


Messages In This Thread
Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by zDevon - 31.03.2012, 02:32
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by Luis- - 31.03.2012, 02:38
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by shayan122 - 05.07.2012, 18:21
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by Bug. - 13.09.2012, 13:12
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by xMCx - 13.09.2012, 15:35
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by Bug. - 24.09.2012, 22:19
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by zDevon - 24.09.2012, 22:44
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by Shane_Kingston - 30.09.2012, 03:37
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by x96664 - 26.11.2012, 18:34
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by Red_Dragon. - 26.11.2012, 18:53
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by Bug. - 27.11.2012, 15:26
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by Red_Dragon. - 27.11.2012, 17:34
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by Socan - 27.11.2012, 18:36
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by atiqfajar - 12.12.2012, 11:24
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by zDevon - 12.12.2012, 13:09
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by SilencedPistol - 16.02.2013, 04:59
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by Toxik - 30.06.2014, 08:26
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by fullaninho - 25.06.2015, 23:30
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by fullaninho - 26.06.2015, 00:02
Re: Simple Entry and Exit Points [Adding icons + Creating /enter and /exit commands] - by AndreiWow - 18.07.2015, 21:32

Forum Jump:


Users browsing this thread: 2 Guest(s)