[Tutorial] How to make Entrances and Exits
#1

Tutorial
How to create an Entrances and Exits (With and Without Command)


Method 1
Step 1 - With Command.

Firstly, i would reccomend having a pickup at your entrance point where the command must be typed in order to SetPlayerPos into the interior you would like your player to enter. To create a pickup you can easily follow my tutorial by clicking THIS link here. Now! im assuming you have done your pickup now lets move onto the bigboy stuff. I will show you how to make the command in both STRCMP and ZCMD.

STRCMP method

We will now create an /enter command using nothing other than strcmp. I personally am not an STRCMP command maker as it is not as fast as ZCMD. so in order to work STRCMP nothing special is required besides your basic scripting kit (pawno compiler and a few includes that come with it). Now lets work the magic underneath your.
Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
What is this - OnPlayerCommand text is where we create our strcmp commands, and what OnPlayerCommandText does is all in its name. It will do what you follow underneath the command so it will do the following you put ON the players command text. The callback is called up when the player when the player enters a command that you have created underneath the bracket above the return call. Now when opening new.pwn it gives us an example method of a code that does nothing but we will be using it as a template and the coding all together looks like (on new.pwn)

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/mycommand", cmdtext, true, 10) == 0)
    {
        // Do something here
        return 1;
    }
    return 0;
}

As you see the // Do something here, that is where we will be scripting in. and we will be changing the mycommand to the command text you would like your enter command to be so in our case we will be making the command /enter, therefore we must change the


Код:
if (strcmp("/mycommand", cmdtext, true, 10) == 0) 

INTO

if (strcmp("/enter", cmdtext, true, 10) == 0)
Congratulations, we have now changed the command text and now it will do the following we add together when the player is typing /enter at the point he should be typing it. Now its time to make some coding so follow below!

Example of an Enter Command (will explain each part and what it does)

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/enter", cmdtext, true, 10) == 0)
    {
        if(IsPlayerInRangeOfPoint(playerid,RADUIS, X, Y, Z))
        {
            SetPlayerPos(playerid, X, Y, Z);
            SetPlayerInterior(playerid, INTERIORID);
            SetPlayerVirtualWorld(playerid, VIRTUALWORLD); // Optional
            SetCameraBehindPlayer(playerid);
        }
        return 1;
    }
    return 0;
}
So what does the above exactly do? Let me explain:

if(IsPlayerInRangeOfPoint(playerid,RADIUS, X, Y, Z); // Here basically you will have to fill in where X,Y,Z and RADIUS is into the X,Y,Z positions of where the player must be when typing this command also including the radius (distant) the player must be when typing the command it will be the furthest distant that the player may stand from the X Y Z positions so this command can function. This posiition coordinates may be from your pickup coordinate so the player must be at the pickup when typing this command.

SetPlayerPos(playerid, X, Y, Z); // This has it in its name, When the command is performed and the player IsInRangeOfPoint of the entrance area, this function will SET the players Position from where they are currently standing into the position that we will define in the X Y Z coordinates - This is what you will fill in.

SetPlayerInterior(playerid, INTERIORID); // This also has it in its name, When the command is performed it will Set the interior for the player with the INTERIORID that you will define, 0 is the default Interior, you may also call this the Universe ID but it is defined as SetPlayerInterior and it will SET the players INTERIORID on the command's perform.

SetPlayerVirtualWorld(playerid,VIRTUALWORLD); // Optional, only because you will be setting the VIRTUALWORLD of the player, I suggest nothing at VirtualWorld 0 as it collides with the weather and for example when it is raining the inside will also be raining making it not really nice. It will SET the VIRTUALWORLD of the player to what you define where VIRTUALWORLD is after the playerid.

SetCameraBehindPlayer(playerid); // This is also optional if you want the Players Camera to be SET behind the player when he is inside an interior. It has it in its name and is pretty basic too. When doing this make sure you only have playerid); at the end so it Sets the CameraBehindPlayer the one who has performed the command at the specific point.

returns // Making the returns to 0 will make it so that when the player has typed the command incorrect such as /ente with the R missing out, it will automatically displayer SERVER: Unknown Command to the player who has performed the misspelled/incorrect command.

Now we have an Enter command, it is time to make an Exit command using STRCMP, remember there is still ZCMD to go, so i hope you like reading

Now we will create an EXIT command using STRCMP. so underneath the enter command do the following only this time changeing both Coordinates/VirtualWorlds/Interiors also the RangePoints. So below i will show you the coding and explain each part and its roles. This is the same as the Enter Command so copy the functions of the Enter command only deleting the VirtualWorld,Interior,IsInRangeOfPoint etc. So we now have


pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp("/enter", cmdtext, true, 10) == 0)
    {
        if(IsPlayerInRangeOfPoint(playerid,RADIUS X, Y, Z))
        {
            SetPlayerPos(playerid, X, Y, Z);
            SetPlayerInterior(playerid, INTERIORID);
            SetPlayerVirtualWorld(playerid, VIRTUALWORLD); // Optional
            SetCameraBehindPlayer(playerid);
        }
        return 1;
    }
    if (strcmp("/enter", cmdtext, true, 10) == 0)
    {
        if(IsPlayerInRangeOfPoint(playerid,RADIUS, X, Y, Z))
        {
            SetPlayerPos(playerid, X, Y, Z);
            SetPlayerInterior(playerid, INTERIORID);
            SetPlayerVirtualWorld(playerid, VIRTUALWORLD); // Optional
            SetCameraBehindPlayer(playerid);
            return 1;
        }
    }
    return 0;
}
Again at this stage we refer to the functions of what each do only this time we will be changing it. So this time the things that will change

CommandText = This will change from /enter into /exit as it makes sence you will also be wanting an exit command from the interior back to the pickup point right?

IsPlayerInRangeOfPoint = I would suggest that we use the X,Y,Z coordinate from the SetPlayerPos you defined at the Enter Command so this time we are working reverse. This time the position that you set for the enter will now be the position that you will need to be at to /exit from.

SetPlayerPos = This time we would set this to the IsPlayerInRangePoint at the entrance so when the player is typing exit at the new InRangeOfPoint at /exit, he will be set at the position where the enter was thus making him spawn at the start.

VirtualWorld = We will now make this 0 as it is the default Virtual World

Interior = I would also suggest making this 0 as it is the default

CameraBehindPlayer - This is also Optional too and we must now know at this point what it does as it is explained above on this tutorial.

Having altered the information at the Exit command also, i am now pleased to say that you have successfully created your self an Enter and an Exit command command for a building using STRCMP. below will show how to make it using ZCMD which is a faster command processor than STRCMP and is highly reccommended but do not worry, if you do not understand ZCMD simply use the STRCMP method above.


ZCMD Method - Same but slightly different


In order to use ZCMD we must firstly have the ZCMD include, once having it and stored in the includes library we may now include it at the top of our script as so:


pawn Код:
#include <ZCMD> // Not caps Sensitive do not worry.

Now we must make the commands but we will not be adding these under OnPlayerCommandText, infact we will be placing them ANYWHERE in the script but not under any calls. So below is an Example, from there onwards i will explain each function as i have above.


pawn Код:
CMD:enter(playerid, params[])
{
    if(IsPlayerInRangeOfPoint(playerid, RADIUS, X, Y, Z))
    {
        SetPlayerPos(playerid, X, Y, Z);
        SetPlayerInterior(playerid, INTERIORID);
        SetPlayerVirtualWorld(playerid, VIRTUALWORLD);
        SetCameraBehindPlayer(playerid); //Optional
    }
    if(IsPlayerInRangeOfPoint(playerid, RADIUS, X, Y, Z)) // Same thing, just changine X,Y,Z and Int and VW
    {
        SetPlayerPos(playerid, X, Y, Z);
        SetPlayerInterior(playerid, INTERIORID);
        SetPlayerVirtualWorld(playerid, VIRTUALWORLD);
        SetCameraBehindPlayer(playerid); //Optional
    }
    return 1;
}

CMD:exit(playerid, params[])
{
        if(IsPlayerInRangeOfPoint(playerid, RADIUS, X, Y, Z))
    {
        SetPlayerPos(playerid, X, Y, Z);
        SetPlayerInterior(playerid, INTERIORID);
        SetPlayerVirtualWorld(playerid, VIRTUALWORLD);
        SetCameraBehindPlayer(playerid); //Optional
    }
    if(IsPlayerInRangeOfPoint(playerid, RADIUS, X, Y, Z)) // Same thing, just changine X,Y,Z and Int and VW
    {
        SetPlayerPos(playerid, X, Y, Z);
        SetPlayerInterior(playerid, INTERIORID);
        SetPlayerVirtualWorld(playerid, VIRTUALWORLD);
        SetCameraBehindPlayer(playerid); //Optional
    }
    return 1;
}
Above is an example of an Enter and an Exit command, you may use it as a template as ive included a second enter + exit point and in order to do it simply copy the same thing wether its under the Exit command or the Enter command only the IsPlayerInRangeOfPoint till the } bracket. The same is for the STRCMP method, you just copy and paste from IsPlayerInRAngeOfPoint till the } only changing Coordinates and Interior + VirtualWorld information

Now what does the language above mean?

Referring to the STRCMP method.

if(IsPlayerInRangeOfPoint(playerid,RADIUS, X, Y, Z); // Here basically you will have to fill in where X,Y,Z and RADIUS is into the X,Y,Z positions of where the player must be when typing this command also including the radius (distant) the player must be when typing the command it will be the furthest distant that the player may stand from the X Y Z positions so this command can function. This posiition coordinates may be from your pickup coordinate so the player must be at the pickup when typing this command.

SetPlayerPos(playerid, X, Y, Z); // This has it in its name, When the command is performed and the player IsInRangeOfPoint of the entrance area, this function will SET the players Position from where they are currently standing into the position that we will define in the X Y Z coordinates - This is what you will fill in.

SetPlayerInterior(playerid, INTERIORID); // This also has it in its name, When the command is performed it will Set the interior for the player with the INTERIORID that you will define, 0 is the default Interior, you may also call this the Universe ID but it is defined as SetPlayerInterior and it will SET the players INTERIORID on the command's perform.

SetPlayerVirtualWorld(playerid,VIRTUALWORLD); // Optional, only because you will be setting the VIRTUALWORLD of the player, I suggest nothing at VirtualWorld 0 as it collides with the weather and for example when it is raining the inside will also be raining making it not really nice. It will SET the VIRTUALWORLD of the player to what you define where VIRTUALWORLD is after the playerid.

SetCameraBehindPlayer(playerid); // This is also optional if you want the Players Camera to be SET behind the player when he is inside an interior. It has it in its name and is pretty basic too. When doing this make sure you only have playerid); at the end so it Sets the CameraBehindPlayer the one who has performed the command at the specific point.

returns // Making the returns to 0 will make it so that when the player has typed the command incorrect such as /ente with the R missing out, it will automatically displayer SERVER: Unknown Command to the player who has performed the misspelled/incorrect command

Now doing this will have your command done and now you have made your self an Exit and an Enter command by learning how to do it in both ZCMD and STRCMP. Now lets move onto the Pickup Method!


Method 2 - Pickup Method

To learn howto create a pickup AGAIN please click to view my tutorial. and to get to that link please click HERE! Now that you have learnt how to create a pickup using my Tutorial, we will now learn how to make your pickup Enter the player into an Interior and we do the same for Exterior only Reverse Same as Command but without a Command.

We will add the coding underneath the


pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
NOTE: we must have made the pickup as a variable so we will define it as a variable so then we can define it in the PickupPickup sector. Again, learn how to do that by clicking on HERE!

Now underneath that public call we would be doing the following, i will give an example for an exit and an Entrance, filling in the coordinates and such is down to you.


pawn Код:
public OnPlayerPickUpPickup(playerid, pickupid)
{
    if(pickupid == PickupEnter)
    {
        SetPlayerPos(playerid, X, Y, Z);
        SetPlayerInterior(playerid, INTERIORID);
        SetPlayerVirtualWorld(playerid, VIRTUALWORLD);
        SetCameraBehindPlayer(playerid); //Optional
    }
    if(pickupid == PickupExit)
    {
        SetPlayerPos(playerid, X, Y, Z);
        SetPlayerInterior(playerid, INTERIORID);
        SetPlayerVirtualWorld(playerid, VIRTUALWORLD);
        SetCameraBehindPlayer(playerid); //Optional
    }
    return 1;
}

Making sure that you have followed my guide and created the pickup as a variable we will add it under OnPlayerPickupPickup so it enters our player like so. This time we will not be needing IsPlayerInRangeOfPoint because once the player has walked into the pickup he/she will automatically be entered without typing a thing into the Positioning you have set for him/her to be in. So what does the above do?

SetPlayerPos(playerid, X, Y, Z); // This has it in its name, When the command is performed and the player IsInRangeOfPoint of the entrance area, this function will SET the players Position from where they are currently standing into the position that we will define in the X Y Z coordinates - This is what you will fill in.

SetPlayerInterior(playerid, INTERIORID); // This also has it in its name, When the command is performed it will Set the interior for the player with the INTERIORID that you will define, 0 is the default Interior, you may also call this the Universe ID but it is defined as SetPlayerInterior and it will SET the players INTERIORID on the command's perform.

SetPlayerVirtualWorld(playerid,VIRTUALWORLD); // Optional, only because you will be setting the VIRTUALWORLD of the player, I suggest nothing at VirtualWorld 0 as it collides with the weather and for example when it is raining the inside will also be raining making it not really nice. It will SET the VIRTUALWORLD of the player to what you define where VIRTUALWORLD is after the playerid.

SetCameraBehindPlayer(playerid); // This is also optional if you want the Players Camera to be SET behind the player when he is inside an interior. It has it in its name and is pretty basic too. When doing this make sure you only have playerid); at the end so it Sets the CameraBehindPlayer the one who has performed the command at the specific point.

Same responsibilites as above. Exactly the same when making the Exit pickup too only altering its X Y Z coordinates and altering the Interior and VirtualWorld data

I hope now you know how to make an Entrance and an Exit using STRCMP,ZCMD OR Pickup!

Reply
#2

Awesome 10/10

Have a REP
Reply
#3

Thank you
Reply
#4

Good job but you forgot the RADIUS in some IsPlayerInRangeOfPoint, if you don't fix it, some people will get error, tag mistach error but nice tutorial
Reply
#5

Thanks for the tip, ill do that now
Reply
#6

Great job Phoenix. You explained it very well

Repppped
Reply
#7

Thanks Dr.P, Explained it as much as i can and gave two methods of making it, took time but im glad if it helps people that need it
Reply
#8

That's pretty nice method. Anyways isn't it also possible to make a variable or something about the locations and then read them from there?
Reply
#9

Method's you mean? I explained how to make them via commands and Via Pickups using variables.
Reply
#10

Nice tutorial, but an even better method for the enter command is this:

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if (strcmp(cmdtext, "/enter", true) == 0)
    {
        if(IsPlayerInRangeOfPoint(playerid,RADIUS X, Y, Z))
        {
            SetPlayerPos(playerid, X, Y, Z);
            SetPlayerInterior(playerid, INTERIORID);
            SetPlayerVirtualWorld(playerid, VIRTUALWORLD); // Optional
            SetCameraBehindPlayer(playerid);
            return 1;
        }
        else if (IsPlayerInRangeOfPoint(playerid,RADIUS, X, Y, Z))
        {
            SetPlayerPos(playerid, X, Y, Z);
            SetPlayerInterior(playerid, INTERIORID);
            SetPlayerVirtualWorld(playerid, VIRTUALWORLD); // Optional
            SetCameraBehindPlayer(playerid);
            return 1;
        }
        return 1;
    }
    return 0;
}
No need for two or more "enters", just re-check where the player is.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)