SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 23/02/2011, 11:57 AM   #1
captainjohn
Huge Clucker
 
captainjohn's Avatar
 
Join Date: Jul 2010
Location: United Kingdom
Posts: 430
Reputation: 28
Default Teleport command with extras [DETAILED]

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 Code:
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 Code:
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 Code:
public OnPlayerCommandText(playerid, cmdtext[])
{
    if(strcmp("/bayside", cmdtext, true) == 0)
    {

The next line will be this.
pawn Code:
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 Code:
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 Code:
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 Code:
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 Code:
SetPlayerFacingAngle(playerid, 180);

So far this is how the command should look.
pawn Code:
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 Code:
SendClientMessage(playerid, 0x00FFFFAA, "");

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

pawn Code:
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 Code:
return 1;
    }

Finally it should look like this.

pawn Code:
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 Code:
GivePlayerWeapon(playerid, , );

We will first get the weapon ID by going to this webpage http://wiki.sa-mp.com/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 Code:
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 Code:
GivePlayerWeapon(playerid, 34, 100);
Now we will add it to our command.

pawn Code:
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 Code:
ResetPlayerWeapons(playerid);
Now your command will look like this.

pawn Code:
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 Code:
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 Code:
SetPlayerVirtualWorld(playerid, 5);

Now the whole command will look like this.

pawn Code:
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 Code:
if(strcmp("/bayside", cmdtext, true) == 0)

Then we copy this next to the first line
pawn Code:
|| (strcmp("/bs", cmdtext, true) == 0))

It should look like this.
pawn Code:
if((strcmp("/bayside", cmdtext, true) == 0) || (strcmp("/bs", cmdtext, true) == 0))

Now for the whole command should look like this.

pawn Code:
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 http://forum.sa-mp.com/showthread.php?t=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.

Last edited by captainjohn; 23/02/2011 at 05:58 PM.
captainjohn is offline   Reply With Quote
Old 23/02/2011, 02:59 PM   #2
[Ips]Guh
Gangsta
 
[Ips]Guh's Avatar
 
Join Date: Apr 2010
Location: Brazil
Posts: 852
Reputation: 50
Default Re: Teleport command with extras

Nice Tutorial...helped many beginners
[Ips]Guh is offline   Reply With Quote
Old 23/02/2011, 03:18 PM   #3
Falcon.
High-roller
 
Falcon.'s Avatar
 
Join Date: Jul 2010
Location: Brazil
Posts: 1,743
Reputation: 147
Default Re: Teleport command with extras

tutorial very well done ..
congratulations
__________________
....
Falcon. is offline   Reply With Quote
Old 23/02/2011, 03:33 PM   #4
deather
Huge Clucker
 
deather's Avatar
 
Join Date: Dec 2009
Location: India
Posts: 376
Reputation: 2
Default Re: Teleport command with extras

But strcmps have gone off use. Most people switch to zcmd or ycmd or dcmd. So you can add them too.
deather is offline   Reply With Quote
Old 23/02/2011, 04:29 PM   #5
alpha500delta
High-roller
 
alpha500delta's Avatar
 
Join Date: Feb 2010
Posts: 1,301
Reputation: 91
Default Re: Teleport command with extras

LOL Why would you reset a players weapon then give one, the one you give probably gets reset to...
__________________
Skype: Alpha500delta | Steam: Alpha500delta
alpha500delta is offline   Reply With Quote
Old 23/02/2011, 05:01 PM   #6
captainjohn
Huge Clucker
 
captainjohn's Avatar
 
Join Date: Jul 2010
Location: United Kingdom
Posts: 430
Reputation: 28
Default Re: Teleport command with extras

Quote:
Originally Posted by alpha500delta View Post
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.
captainjohn is offline   Reply With Quote
Old 23/02/2011, 05:12 PM   #7
LZLo
Gangsta
 
LZLo's Avatar
 
Join Date: Jul 2010
Location: Central Europe
Posts: 542
Reputation: 21
Default Re: Teleport command with extras

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

CCFH 2.0 is out now! (http://img339.imageshack.us/slidesho...908079fgd.smil)
DOUBLE LANGUAGE! (ENGLISH& Hungarian)!
PAWN scripting since 2006

I would mention something. If i could help please just click near my profile.
LZLo is offline   Reply With Quote
Old 23/02/2011, 05:37 PM   #8
Stigg
High-roller
 
Stigg's Avatar
 
Join Date: Aug 2010
Location: Other side of the Universe.
Posts: 2,084
Reputation: 111
Default Re: Teleport command with extras

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

Peace...
__________________

Peace...

Stigg is offline   Reply With Quote
Old 23/02/2011, 05:40 PM   #9
captainjohn
Huge Clucker
 
captainjohn's Avatar
 
Join Date: Jul 2010
Location: United Kingdom
Posts: 430
Reputation: 28
Default Re: Teleport command with extras

Quote:
Originally Posted by Stigg View Post
Adding teleporting players in their vehicles to the tut, will round it off nicley.

Peace...
Already done something similar.

http://forum.sa-mp.com/showthread.php?t=230467




Anybody want me to add anything else?
Just ask.
captainjohn is offline   Reply With Quote
Old 23/02/2011, 05:54 PM   #10
Stigg
High-roller
 
Stigg's Avatar
 
Join Date: Aug 2010
Location: Other side of the Universe.
Posts: 2,084
Reputation: 111
Default Re: Teleport command with extras

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

http://forum.sa-mp.com/showthread.php?t=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...
__________________

Peace...

Stigg 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
Need Help With This Teleport Command! Elmerz_com Help Archive 14 18/01/2011 08:24 PM
A teleport command! davaj Help Archive 5 20/08/2009 12:48 PM


All times are GMT. The time now is 09:45 PM.


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