SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 16/09/2015, 01:37 PM   #1
xTURBOx
Huge Clucker
 
xTURBOx's Avatar
 
Join Date: Aug 2015
Location: Earth
Posts: 378
Reputation: 49
Default How to make teleport cmd and teleport dialog[ZCMD]

How to make teleport cmd and teleport dialog[ZCMD]

Introduction
Hello guys this is my first tutorial on samp forum hope you like,enjoy and learn from it.
So lets get started....
Includes
Firstly add these includes

PHP Code:
#include <a_samp>
#include <zcmd> 
Getting the coordinates
First we need to get the teleport coordinates to do that:
  1. Go to any server(or debug)
  2. Go to your desired place
  3. type /rs (this saves only the raw position unlike /save, thus making it a lot eaiser)
  4. close gta and goto Documents\GTA San Andreas User Files\SAMP
  5. open the file named rawpositions.txt(coordinates will be saved in this file)

we will first make Teleport command
Teleport Command



Making the command
As we are using zcmd
PHP Code:
CMD:sfairport(playerid,params[])
{
         
//function
         
return 1;

you can replace sfairport with your desired command name

Function SetPlayerPos
so now use the function SetPlayerPos
PHP Code:
SetPlayerPos(playerid,YOURCOORDINATESHERE);//set the player position 
replace YOURCOORDINATESHERE with your coordinates
PHP Code:
SetPlayerPos(playerid,-1534.4138,-75.4995,14.1484,307.1554);//set the player position
//-1534.4138,-75.4995,14.1484,307.1554 is my coordinates for sfairport 
use it with zcmd we made above it will be
PHP Code:
CMD:sfairport(playerid,params[])
{
      
SetPlayerPos(playerid,-1534.4138,-75.4995,14.1484,307.1554);
      return 
1;

Checking if the player is in any vehicle
we will use
PHP Code:
IsPlayerInAnyVehicle(playerid
^ that code to check if the player is in any vehicle, it will be used with
PHP Code:
        new vehicleid GetPlayerVehicleID(playerid);
        
SetVehiclePos(vehicleid,-1534.4138,-75.4995,14.1484,307.1554); 
which will make it
PHP Code:
if(IsPlayerInAnyVehicle(playerid))
        {
        new 
vehicleid GetPlayerVehicleID(playerid);
        
SetVehiclePos(vehicleid,-1534.4138,-75.4995,14.1484,307.1554);

so our code till now will be
PHP Code:
CMD:sfairport(playerid,params[])
{
     
//checks whether the player is in any vehicle
    
if(IsPlayerInAnyVehicle(playerid))
    {
        new 
vehicleid GetPlayerVehicleID(playerid);
        
//set vehicle position if he is in a vehicle
        
SetVehiclePos(vehicleid,-1534.4138,-75.4995,14.1484,307.1554);
        }
        
//if the player is on foot
        
else
        {
        
SetPlayerPos(playerid,-1534.4138,-75.4995,14.1484,307.1554);
                 }
          return 
1;

Adding Function SetPlayerInterior
Why are we using this?
so the player wont be bugged when he teleport from a interior(eg: ammunation)
PHP Code:
SetPlayerInterior(playerid,0);//set the player interior ( so that he wont be bugged if teleported from another interior)eg:teleport from inside the ammunation 
so our code now will be
PHP Code:
CMD:sfairport(playerid,params[]) 

     
//checks whether the player is in any vehicle 
    
if(IsPlayerInAnyVehicle(playerid)) 
    { 
        new 
vehicleid GetPlayerVehicleID(playerid); 
        
//set vehicle position if he is in a vehicle 
        
SetVehiclePos(vehicleid,-1534.4138,-75.4995,14.1484,307.1554); 
        } 
        
//if the player is on foot 
        
else 
        { 
        
SetPlayerPos(playerid,-1534.4138,-75.4995,14.1484,307.1554); 
        
SetPlayerInterior(playerid,0);//set the player interior ( so that he wont be bugged if teleported from another interior)eg:teleport from inside the ammunation
                 

          return 
1

Adding ClientMessage and GameText
PHP Code:
SendClientMessage(playerid,COLOR,Message); 
and
PHP Code:
GameTextForPlayer(playerid,Message,time,style
As i am making for sfairport i will be using this
PHP Code:
SendClientMessage(playerid,COLOR_GREEN,"You have been teleported to sanfierro airport successfully!");
        
GameTextForPlayer(playerid"~b~Welcome to~r~ sf airport!"30003); 
Note:Dont forget to define any color you use
So the code will be:
PHP Code:
CMD:sfairport(playerid,params[])
{
     
//checks whether the player is in any vehicle
    
if(IsPlayerInAnyVehicle(playerid))
    {
        new 
vehicleid GetPlayerVehicleID(playerid);
        
//set vehicle position if he is in a vehicle
        
SetVehiclePos(vehicleid,-1534.4138,-75.4995,14.1484,307.1554);
        
//Gametext and client message for the player
        
SendClientMessage(playerid,COLOR_GREEN,"You have been teleported to sanfierro airport successfully!");
        
GameTextForPlayer(playerid"~b~Welcome to~r~ sf airport!"30003);
        }
        
//if the player is on foot
        
else
        {
        
SetPlayerPos(playerid,-1534.4138,-75.4995,14.1484,307.1554);//set the player position
        
SetPlayerInterior(playerid,0);//set the player interior ( so that he wont be bugged if teleported from another interior)eg:teleport from inside the ammunation
        //client message and game text
        
SendClientMessage(playerid,COLOR_GREEN,"You have been teleported to sanfierro airport successfully!");
        
GameTextForPlayer(playerid"~b~Welcome to~r~ sf airport!"30003);
        }
    return 
1;
    } 
Teleport Dialog

like teleport cmd you will first need the coordinates.

before we go any further let me explain the difference between Teleport Dialog and Teleport Command

Whats the difference between teleport dialog and teleport command?
In teleport command you get teleport straight to the location once you use the command, but in teleport dialog when you type the command of the dialog you get options to select where you want to teleport.
Note:^^ thats just explanation in my view

You would know how to get coordinates if you read the top part of the post

Usually a teleport dialog contains more than one option, so i will make mine with three options

Making the command to show the dialog
of course, you will need a command to show the teleport dialog, so lets start with it
PHP Code:
CMD:teleports(playerid,params[])
{
               
//function

i want my command to be "/teleports" ,but you can change it to anything you want..

Using the Function ShowPlayerDialog
we will use ShowPlayerDialog to show the dialog to the player using it
usage of showlayerdialog is (playerid, dialogid, style, caption[], info[], button1[], button2[])
example
PHP Code:
ShowPlayerDialog(playerid,56,DIALOG_STYLE_MSGBOX,"Title","info(what you want to show)","close",""); 
NOTE:Leaving "" for the second button wont show it
NOTE:Use a dialog id that you dont use in the script

we will use the following code
PHP Code:
ShowPlayerDialog(playerid,2316,DIALOG_STYLE_LIST,"Teleports","San fierro Airport\nWang Cars\nOttocars","Select","Close"); 
NOTE:using "\n" moves the text after it to the next line
example
PHP Code:
ShowPlayerDialog(playerid,dialogid,DIALOG_STYLE_MSGBOX,"Title","Line 1\n line 2\n line 3","Select","Close"); 
will give us
Code:
Line 1
line 2
line 3
so our dialog code will be
PHP Code:
CMD:teleports(playerid,params[])
{
    
ShowPlayerDialog(playerid,2316,DIALOG_STYLE_LIST,"Teleports","San fierro Airport\nWang Cars\nOttocars","Select","Close");

Using the callback ondialogresponse
This will be the main part of the script. what happens when player selects a item from the list dialog is determined by what you do here, so lets get started

First go ahead and add the callback like this
PHP Code:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[]) 

Now we will check whether the player is using our teleport dialog
PHP Code:
if(dialogid == 2316
^ that code checks the dialogid change it to your dialogid <============== IMPORTANT
For your ease you can also define dialogs(i will not explain that)

PHP Code:
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 2316)
    { 
Now we need to use the following...
PHP Code:
if(response
it will check whether if the player clicked the first button or the second one or double clicked the option, in our case it will check whether the player double clicked a teleport location or clicked select button or clicked close button

PHP Code:
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 2316)
    {
        if(
response)
        { 
Now we will use the following....
PHP Code:
switch(listitem
this allows us to use "case 1:", "case 2:" and so on, in another words it checks which item from the list is selected

PHP Code:
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 2316)
    {
        if(
response)
        {
            switch(
listitem)
            { 
Now for actual thing to do on ondialogresponse
PHP Code:
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 2316)
    {
        if(
response)
        {
            switch(
listitem)
            {
                case 
0:
                case 
1:
                case 
2:
            }
        }
        return 
1;
    }
    return 
0;

on case 0: we add teleport function to sf airport
on case 1: to wang cars and so on

so the final code will be
PHP Code:
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 2316)
    {
        if(
response)
        {
            switch(
listitem)
            {
                case 
0:SetPlayerPos(playerid,-1534.4138,-75.4995,14.1484,307.1554);
                case 
1:SetPlayerPos(playerid,-1978.0193,276.1283,35.1719,333.1878);
                case 
2:SetPlayerPos(playerid,-1637.3621,1208.9797,7.1797,109.3371);
            }
        }
        return 
1;
    }
    return 
0;

__________________

Last edited by xTURBOx; 28/09/2015 at 12:25 PM.
xTURBOx is offline   Reply With Quote
Old 16/09/2015, 08:24 PM   #2
DoubleNicca
Little Clucker
 
DoubleNicca's Avatar
 
Join Date: Sep 2015
Location: Turkish KEBAB!
Posts: 5
Reputation: 0
Default Re: How to make teleport cmd and teleport dialog[ZCMD]

Basic and nice Tutorial man, thanks.
__________________
Code:
My Works; 
[FilterScript] dMySkin - Dialog MySkin System
[FilterScript] dFish - Fisherman System [%50]
DoubleNicca is offline   Reply With Quote
Old 16/09/2015, 08:43 PM   #3
jlalt
Banned
 
Join Date: Oct 2014
Location: Iran
Posts: 1,277
Reputation: 366
Default Re: How to make teleport cmd and teleport dialog[ZCMD]

Quote:
How to make teleport cmd and teleport dialog
where is the dialog O.O?
jlalt is offline   Reply With Quote
Old 17/09/2015, 10:20 AM   #4
xTURBOx
Huge Clucker
 
xTURBOx's Avatar
 
Join Date: Aug 2015
Location: Earth
Posts: 378
Reputation: 49
Default Re: How to make teleport cmd and teleport dialog[ZCMD]

Quote:
Originally Posted by jlalt View Post
where is the dialog O.O?
didnt you read "NOTE:Teleport dialog will be added tommorow i dont have time to do it now" written at the bottom of the post
__________________
xTURBOx is offline   Reply With Quote
Old 28/09/2015, 12:26 PM   #5
xTURBOx
Huge Clucker
 
xTURBOx's Avatar
 
Join Date: Aug 2015
Location: Earth
Posts: 378
Reputation: 49
Default Re: How to make teleport cmd and teleport dialog[ZCMD]

Added the tutorial to teleport dialog (see the first post)
sorry to add it after a long time, i was a little busy
__________________
xTURBOx is offline   Reply With Quote
Old 28/09/2015, 03:22 PM   #6
JaydenJason
Gangsta
 
JaydenJason's Avatar
 
Join Date: Oct 2014
Location: Netherlands
Posts: 687
Reputation: 51
Default Re: How to make teleport cmd and teleport dialog[ZCMD]

Why does SetPlayerPos have 5 parameters? You included the angle to the parameters as well.

The CMD gives a warning as well, it has no return value.
JaydenJason is offline   Reply With Quote
Old 28/09/2015, 05:41 PM   #7
Ritzy2K
High-roller
 
Ritzy2K's Avatar
 
Join Date: Jun 2014
Location: India
Posts: 1,552
Reputation: 170
Default Re: How to make teleport cmd and teleport dialog[ZCMD]

This is a very basic tutorial, assuming it is made for newbies. You should probably explain the arguements of functions, +rep for your effort though. Not Bad for first tutorial.
Ritzy2K is offline   Reply With Quote
Old 28/09/2015, 05:43 PM   #8
Bolex_
Gangsta
 
Bolex_'s Avatar
 
Join Date: Aug 2015
Location: Croatia.
Posts: 590
Reputation: 117
Default Re: How to make teleport cmd and teleport dialog[ZCMD]

So Why you post this if you are not finish
Bolex_ 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
[Tutorial] How to make a teleport menu in dialog jackx3rx Tutorials 6 30/12/2014 11:29 PM
[Tutorial] How to make "Teleport In Dialog" Devilxz97 Tutorials 6 05/08/2013 08:26 AM
[Tutorial] Criando um teleport em dialog com ZCMD. Đeagle Lançamentos/Releases 22 11/03/2012 01:07 AM
[Include] [INC]Teleport include. Make teleport in 1 line! AiVAMAN Includes 2 05/09/2009 02:41 PM


All times are GMT. The time now is 12:16 PM.


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