[Tutorial] Teleport command with extras
#1

Creating teleports is easy, if you don't know I will show you.
In this tutorial I will create a teleport command to bayside.

First of all go into your filterscript/gamemode and go to.

pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
You can press Ctrl + F to search to find this if it is easier.

Now create a new line after the { under OnPlayerCommandText.

Now we are going to add what we will type in, for it to recongnize the teleport.
So add this.
I will leave /bayside in because I am making mine teleport to Bayside, if you want to go some were else just change the /bayside
pawn Код:
if(strcmp("/bayside", cmdtext, true) == 0)
    {
Now create a new line.

Under that your next line will be the players position, the place were the player will be teleported to.
You can get your co-ordinates for the places by going to a server or your home server or in debug mode and press /save at the place you want. To save your exact co-ordinates.

So lets get back to the tutorial.
We have this.
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp("/bayside", cmdtext, true) == 0)
    {
The next line will be this.
pawn Код:
SetPlayerPos(playerid,
After the playerid, (remember to always have that space after the comma). We will add the co-ordinates.

I am doing bayside.

The co-ordinates are sperated into 3 categories.
Float X
Float Y
Float Z

My Co-ordinates are these.
Float X: -2271.0764,
Float Y: 2317.8457,
Float Z: 4.8202

Lets add them to the
pawn Код:
SetPlayerPos(playerid,
So this is how it will be.

SetPlayerPos(playerid, Float, Float:y, Float:z);
Change the Float X,Y and Z to your co-ordinates.

SetPlayerPos(playerid, -2271.0764, 2317.8457, 4.8202);

So now our command looks like this.

pawn Код:
if(strcmp("/bayside", cmdtext, true) == 0)
    {
        SetPlayerPos(playerid, -2271.0764, 2317.8457, 4.8202);
Now we are going to add the players facing angle, the angle the player will be facing when he teleports to the location.

To do this we add a line under SetPlayerPos and put this.
pawn Код:
SetPlayerFacingAngle(playerid,
Angles are from 0-360 degress. Pick your desired angle.
I will choose 180 degrees, so simply just type your angle after the playerid,

It will look like this.
Don't forget the closed bracket and semi colon after your angle
pawn Код:
SetPlayerFacingAngle(playerid, 180);
So far this is how the command should look.
pawn Код:
if(strcmp("/bayside", cmdtext, true) == 0)
    {
        SetPlayerPos(playerid, -2271.0764, 2317.8457, 4.8202);
        SetPlayerFacingAngle(playerid, 180);
Now we are going to add the client message, which will be sent to the player when he teleports there.
Once again, create a new line under the last one we did.

Now to start the client message put this under SetPlayerFacingAngle.
pawn Код:
SendClientMessage(playerid, 0x00FFFFAA, "");
To put your message in, type your message in between the quotation marks.
So this is mine.
pawn Код:
SendClientMessage(playerid, 0x00FFFFAA, "Your have been teleported to Bayside.");
Now this is my whole command so far.

pawn Код:
if(strcmp("/bayside", cmdtext, true) == 0)
    {
        SetPlayerPos(playerid, -2271.0764, 2317.8457, 4.8202);
        SetPlayerFacingAngle(playerid, 180);
        SendClientMessage(playerid, 0x00FFFFAA, "Your have been teleported to Bayside.");
We now finish off the command by adding. Under the command.
pawn Код:
return 1;
    }
Finally it should look like this.

pawn Код:
if(strcmp("/bayside", cmdtext, true) == 0)
    {
        SetPlayerPos(playerid, -2271.0764, 2317.8457, 4.8202);
        SetPlayerFacingAngle(playerid, 180);
        SendClientMessage(playerid, 0x00FFFFAA, "You have been teleported to Bayside.");
        return 1;
    }

//-------------------------EXTRAS-----------------------------EXTRAS-----------------------------------------
//-------------------------EXTRAS-----------------------------EXTRAS-----------------------------------------


I will show you some extras that you can do to your teleport command.

First of, give the player a weapon.

Anywere in your command, above the return 1 and below the if(strcmp("/bayside", cmdtext, true) == 0)
Add this line.
pawn Код:
GivePlayerWeapon(playerid, , );
We will first get the weapon ID by going to this webpage https://sampwiki.blast.hk/wiki/Weapons
I will choose a sniper.
So my ID I need to get is ID 34.

Now back to the code, add your weapon ID after the first comma in the command (add a space aswell)
So it will look like this.

pawn Код:
GivePlayerWeapon(playerid, 34, );
Now we want to add how much ammo the player will get once he has teleported. So after the 2nd comma and space add a number. I will add 100.
It will look like this.

pawn Код:
GivePlayerWeapon(playerid, 34, 100);
Now we will add it to our command.

pawn Код:
if(strcmp("/bayside", cmdtext, true) == 0)
    {
        SetPlayerPos(playerid, -2271.0764, 2317.8457, 4.8202);
        SetPlayerFacingAngle(playerid, 180);
        GivePlayerWeapon(playerid, 34, 100);
        SendClientMessage(playerid, 0x00FFFFAA, "You have been teleported to Bayside.");
        return 1;
    }
Now you may want to reset all the players weapons on teleport.
So just simply add this to a line in your teleport command.

pawn Код:
ResetPlayerWeapons(playerid);
Now your command will look like this.

pawn Код:
if(strcmp("/bayside", cmdtext, true) == 0)
    {
        SetPlayerPos(playerid, -2271.0764, 2317.8457, 4.8202);
        SetPlayerFacingAngle(playerid, 180);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 34, 100);
        SendClientMessage(playerid, 0x00FFFFAA, "You have been teleported to Bayside.");
        return 1;
    }
So, so far in my commands, the player gets teleported to Bayside, his facing angle is 180 degrees, he gets a client message, his weapons get reset and he gets given a sniper with 100 ammo.

I will end this tutorial with adding the player to a virtual world.
Again, add this code into your command so far.
pawn Код:
SetPlayerVirtualWorld(playerid, );
Now after the comma and space add a virtual world, the default for everyone is 0, so make it something other than 0.
I will use 5 for my example.

Should then look like this.

pawn Код:
SetPlayerVirtualWorld(playerid, 5);
Now the whole command will look like this.

pawn Код:
if(strcmp("/bayside", cmdtext, true) == 0)
    {
        SetPlayerPos(playerid, -2271.0764, 2317.8457, 4.8202);
        SetPlayerFacingAngle(playerid, 180);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 34, 100);
        SetPlayerVirtualWorld(playerid, 5);
        SendClientMessage(playerid, 0x00FFFFAA, "You have been teleported to Bayside.");
        return 1;
    }


One last extra for today.
You want two commands to go to the same place like /bayside and /bs

Just do this.

This is our first line
pawn Код:
if(strcmp("/bayside", cmdtext, true) == 0)
Then we copy this next to the first line
pawn Код:
|| (strcmp("/bs", cmdtext, true) == 0))
It should look like this.
pawn Код:
if((strcmp("/bayside", cmdtext, true) == 0) || (strcmp("/bs", cmdtext, true) == 0))
Now for the whole command should look like this.

pawn Код:
if((strcmp("/bayside", cmdtext, true) == 0) || (strcmp("/bs", cmdtext, true) == 0))
    {
        SetPlayerPos(playerid, -2271.0764, 2317.8457, 4.8202);
        SetPlayerFacingAngle(playerid, 180);
        ResetPlayerWeapons(playerid);
        GivePlayerWeapon(playerid, 34, 100);
        SetPlayerVirtualWorld(playerid, 5);
        SendClientMessage(playerid, 0x00FFFFAA, "You have been teleported to Bayside.");
        return 1;
    }


Edit: A tutorial I made to teleport your player to a location and get a vehicle https://sampforum.blast.hk/showthread.php?tid=230467

Thank you, I hope I have helped.

I know people will say "or this is easy" but for new people, it isn't, so anyone out there who doesn't know what to do.
I hope I have helped.
Reply
#2

Nice Tutorial...helped many beginners
Reply
#3

tutorial very well done ..
congratulations
Reply
#4

But strcmps have gone off use. Most people switch to zcmd or ycmd or dcmd. So you can add them too.
Reply
#5

LOL Why would you reset a players weapon then give one, the one you give probably gets reset to...
Reply
#6

Quote:
Originally Posted by alpha500delta
Посмотреть сообщение
LOL Why would you reset a players weapon then give one, the one you give probably gets reset to...
This is a tutorial teaching beginners simple commands and what not. So they don't necessarily have to use that, don't forget I used them as a example.

Like a person could have sawns,macs,ak47 and they might want to go to a snipe deathmatch.

So you could reset all players weapons and give them a sniper... So think before you post.
Reply
#7

why teleport making is so complicated?, by the way it's a nice tutorial
Reply
#8

Adding teleporting players in their vehicles to the tut, will round it off nicley.

Peace...
Reply
#9

Quote:
Originally Posted by Stigg
Посмотреть сообщение
Adding teleporting players in their vehicles to the tut, will round it off nicley.

Peace...
Already done something similar.

https://sampforum.blast.hk/showthread.php?tid=230467




Anybody want me to add anything else?
Just ask.
Reply
#10

[QUOTE=captainjohn;1086084]Already done something similar.

https://sampforum.blast.hk/showthread.php?tid=230467



Yeah i see, that bit of info would better in this tutorial, along with teleporting payers in vehicles.
Then you will have a good around teleporting tutorial for beginners. A one stop shop.

Peace...
Reply
#11

WHY STRCMP?

ZCMD is the best for commands
Reply
#12

pls help
mine now looks like this
1445public OnPlayerCommandText(playerid,cmdtext[]){
{
if(strcmp("/bayside", cmdtext, true) == 0)
{
SetPlayerPos(playerid, -2271.0764, 2317.8457, 4.8202);
SetPlayerFacingAngle(playerid, 180);
SendClientMessage(playerid, 0x00FFFFAA, "hey hey");
return 1;
1153 }

when i try to compile it, i get this error


C:\Users\Sander\Desktop\server\gamemodes\lstdm.pwn (1154) : error 030: compound statement not closed at the end of file (started at line 1147)
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase


1 Error.
Reply
#13

You forgot to add a bracket...
Reply
#14

Quote:
Originally Posted by black_dota
Посмотреть сообщение
WHY STRCMP?

ZCMD is the best for commands
answer: because of the newbies& it isn't a ZCMD tutorial
&
y_commands are faster than ZCMD
Reply
#15

Quote:
Originally Posted by black_dota
Посмотреть сообщение
WHY STRCMP?

ZCMD is the best for commands
answer: because of the newbies& it isn't a ZCMD tutorial (or am i wrong?)
&
y_commands are faster than ZCMD
Reply
#16

public OnPlayerCommandText(playerid,cmdtext[]){

if (strcmp("/kill",cmdtext,true)==0){
SetPlayerHealth(playerid,0);
}

if (strcmp("/open",cmdtext,true)==0){
if(IsPlayerAdmin(playerid))
MoveObject(3,1811.688721,-1895.821533,12.580940,1);
}

if (strcmp("/close",cmdtext,true)==0){
if(IsPlayerAdmin(playerid))
MoveObject(3,1811.688721,-1885.821533,12.580940,1);
}

return 1;
}
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger){
new modid;
modid = GetVehicleModel(vehicleid);
if (modid == 520) {
if (IsPlayerAdmin(playerid)){
SetVehicleParamsForPlayer(vehicleid,playerid,0,0); }
else{
SetVehicleParamsForPlayer(vehicleid,playerid,0,1);
}
}}

could u pls at an teleport to this so i have an example how to do ?
Reply
#17

Quote:
Originally Posted by sander3223
Посмотреть сообщение
could u pls at an teleport to this so i have an example how to do ?
Sorry I didn't understand this question, please elaborate or re-phrase it.
Reply
#18

Dude that is what this tutorial is for! You can learn how to do it yourself using this
Also:

pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger){
new modid;
modid = GetVehicleModel(vehicleid);
if (modid == 520) {
if (IsPlayerAdmin(playerid)){
SetVehicleParamsForPlayer(vehicleid,playerid,0,0); }
else{
SetVehicleParamsForPlayer(vehicleid,playerid,0,1);
}
}} //phail
Reply
#19

Nice but simple
Reply
#20

I saw lots of noobs don't read the wiki. Good tutorial.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)