SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 16/08/2011, 03:47 PM   #1
PhoenixB
Huge Clucker
 
PhoenixB's Avatar
 
Join Date: Mar 2011
Location: Pawno.exe
Posts: 421
Reputation: 46
Post How to make Entrances and Exits

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.
Code:
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 Code:
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


Code:
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 Code:
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 Code:
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 Code:
#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 Code:
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 Code:
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 Code:
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!


Last edited by PhoenixB; 16/08/2011 at 05:05 PM.
PhoenixB is offline   Reply With Quote
Old 16/08/2011, 04:11 PM   #2
seanny
High-roller
 
seanny's Avatar
 
Join Date: Oct 2010
Location: Derry City, Northern Ireland
Posts: 1,495
Reputation: 41
Default Re: How to make Entrances and Exits

Awesome 10/10

Have a REP
seanny is online now   Reply With Quote
Old 16/08/2011, 04:13 PM   #3
PhoenixB
Huge Clucker
 
PhoenixB's Avatar
 
Join Date: Mar 2011
Location: Pawno.exe
Posts: 421
Reputation: 46
Default Re: How to make Entrances and Exits

Thank you
PhoenixB is offline   Reply With Quote
Old 16/08/2011, 04:59 PM   #4
Naruto_Emilio
Banned
 
Join Date: Apr 2011
Location: North Africa
Posts: 1,537
Reputation: 365
Default Re : How to make Entrances and Exits

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
Naruto_Emilio is offline   Reply With Quote
Old 16/08/2011, 05:04 PM   #5
PhoenixB
Huge Clucker
 
PhoenixB's Avatar
 
Join Date: Mar 2011
Location: Pawno.exe
Posts: 421
Reputation: 46
Default Re: How to make Entrances and Exits

Thanks for the tip, ill do that now
PhoenixB is offline   Reply With Quote
Old 16/08/2011, 05:07 PM   #6
dr.pepper
Huge Clucker
 
dr.pepper's Avatar
 
Join Date: Jul 2009
Posts: 317
Reputation: 38
Default Re: How to make Entrances and Exits

Great job Phoenix. You explained it very well

Repppped
dr.pepper is offline   Reply With Quote
Old 16/08/2011, 05:11 PM   #7
PhoenixB
Huge Clucker
 
PhoenixB's Avatar
 
Join Date: Mar 2011
Location: Pawno.exe
Posts: 421
Reputation: 46
Default Re: How to make Entrances and Exits

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
PhoenixB is offline   Reply With Quote
Old 17/08/2011, 10:47 AM   #8
Coffeemonster
Big Clucker
 
Join Date: Nov 2010
Posts: 144
Reputation: 2
Default Re: How to make Entrances and Exits

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?
Coffeemonster is offline   Reply With Quote
Old 17/08/2011, 05:15 PM   #9
PhoenixB
Huge Clucker
 
PhoenixB's Avatar
 
Join Date: Mar 2011
Location: Pawno.exe
Posts: 421
Reputation: 46
Default Re: How to make Entrances and Exits

Method's you mean? I explained how to make them via commands and Via Pickups using variables.
PhoenixB is offline   Reply With Quote
Old 04/09/2011, 05:38 AM   #10
Jack_Leslie
High-roller
 
Jack_Leslie's Avatar
 
Join Date: Feb 2011
Location: Australia
Posts: 1,212
Reputation: 98
Default Re: How to make Entrances and Exits

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

pawn Code:
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.
__________________
lol
Jack_Leslie is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[FilterScript] [FS] [eSystem]: Entrances and Exits builder v0.1 Martin_M Filterscripts 25 29/10/2012 02:26 PM
Nice way to make entrances? ajwar Help Archive 6 14/02/2011 05:33 PM
How to make entrances Egypt1123 Help Archive 8 30/11/2009 10:36 AM
How Can I Make Pick Ups Enterance And Exits Smokey619 Help Archive 16 18/10/2009 10:14 PM
Entrances and Exits. cepiokas Help Archive 3 09/10/2009 02:15 PM


All times are GMT. The time now is 04:36 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.