[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
#2

Nicely done mate. Properly explained, should help some new scripters!
Reply
#3

Thanks man but how can i add Simple red checkpoint without /enter /exit command?

just when he enter checkpoint go in building/or out of it...
Reply
#4

Good.
Reply
#5

thanks easy but really good explaining
Reply
#6

Hey, i have problem with cmd i have no errors but
When use (/enter) i says : SERVER:UnKnow Command.
Reply
#7

Quote:
Originally Posted by Bug.
Посмотреть сообщение
Hey, i have problem with cmd i have no errors but
When use (/enter) i says : SERVER:UnKnow Command.
Try returning 1 inside the command.
Reply
#8

Good man i will give you +1 rep
Reply
#9

It's well explained!
Reply
#10

Thats what i have been looking for a long time. Thanks alot !!
Reply
#11

How to make a new "IsPlayerInRangeOfPoint", i IG "/save", and is not work!
Reply
#12

How can i add words above the pickup
Reply
#13

Nice ! Well explained! Keep up the good work.
Reply
#14

Quote:
Originally Posted by shayan122
Посмотреть сообщение
Thanks man but how can i add Simple red checkpoint without /enter /exit command?

just when he enter checkpoint go in building/or out of it...
put it under public OnPlayerEnterCheckpoint
Reply
#15

Quote:
Originally Posted by Red_Dragon.
View Post
How can i add words above the pickup
Create a 3D text label (https://sampwiki.blast.hk/wiki/Create3DTextLabel) under OnGameModeInit using the same coords as your /enter and /exit commands.
Reply
#16

Can you sort this command out for me? I have no errors, I've returned everything, I can do the /enter but not the /exit. Can somebody write a CMD in ZCMD format for me please? Thanks.

I need it both in World 0 as it's from one part of the mapping I have to another.

Entrance Co-Ords: AddPlayerClass(0,2538.7358,-2529.8491,13.6254,180.7422,0,0,0,0,0,0); //

Exit Co-Ords: AddPlayerClass(0,2538.7598,-2533.5776,13.7359,1.8646,0,0,0,0,0,0); //

Thank you, rep to anybody who does one.
Reply
#17

better make it without command/key
just when u get in point u tp inside or outside an interior
Reply
#18

I can't put at the end return 0; because pawno gives me the warning 225, but I also can't use that script without returning to 0 because it cancels the other commands, how can I solve the problem?
Reply
#19

I no longer need help, I've solved the problem like this:

public OnPlayerCommandText(playerid, cmdtext[])
{

if(strcmp(cmdtext, "/enterb", true) ==0)
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, 1298.2000,-798.5759,84.1406))
{
SetPlayerPos(playerid, 1299.14,-794.77,1084.00);//mansгo entrar
SetPlayerInterior(playerid, 5);
return 1;
}
}

if(strcmp(cmdtext, "/exitb", true) ==0)
{
if(IsPlayerInRangeOfPoint(playerid, 3.0, 1299.14,-794.77,1084.00))
{
SetPlayerPos(playerid, 1298.2000,-798.5759,84.1406);//mansгo sair
SetPlayerInterior(playerid, 0);
return 1;
}
}
return 0;
}

It probably wasn't working well currently because this script wasn't made for this version of samp, but is well made and it doesn't need to be much changed and the changes are easy to make, I've started scripting about 3 to 4 weeks ago (I'm a beginner) and it took me shortly to solve the problem. It's a great script, It helped me a lot creating entrances for places in the game. Thanks
Reply
#20

Thanks alot, great tutorial.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)