[Tutorial] How to make teleport cmd and teleport dialog[ZCMD]
#1

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 код:
#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 код:
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 код:
SetPlayerPos(playerid,YOURCOORDINATESHERE);//set the player position 
replace YOURCOORDINATESHERE with your coordinates
PHP код:
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 код:
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 код:
IsPlayerInAnyVehicle(playerid
^ that code to check if the player is in any vehicle, it will be used with
PHP код:
        new vehicleid GetPlayerVehicleID(playerid);
        
SetVehiclePos(vehicleid,-1534.4138,-75.4995,14.1484,307.1554); 
which will make it
PHP код:
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 код:
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 код:
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 код:
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 код:
SendClientMessage(playerid,COLOR,Message); 
and
PHP код:
GameTextForPlayer(playerid,Message,time,style
As i am making for sfairport i will be using this
PHP код:
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 код:
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 код:
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 код:
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 код:
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 код:
ShowPlayerDialog(playerid,dialogid,DIALOG_STYLE_MSGBOX,"Title","Line 1\n line 2\n line 3","Select","Close"); 
will give us
Код:
Line 1
line 2
line 3
so our dialog code will be
PHP код:
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 код:
public OnDialogResponse(playeriddialogidresponselistiteminputtext[]) 
Now we will check whether the player is using our teleport dialog
PHP код:
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 код:
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 2316)
    { 
Now we need to use the following...
PHP код:
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 код:
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 2316)
    {
        if(
response)
        { 
Now we will use the following....
PHP код:
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 код:
OnDialogResponse(playeriddialogidresponselistiteminputtext[])
{
    if(
dialogid == 2316)
    {
        if(
response)
        {
            switch(
listitem)
            { 
Now for actual thing to do on ondialogresponse
PHP код:
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 код:
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;

Reply
#2

Basic and nice Tutorial man, thanks.
Reply
#3

Quote:

How to make teleport cmd and teleport dialog
where is the dialog O.O?
Reply
#4

Quote:
Originally Posted by jlalt
Посмотреть сообщение
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
Reply
#5

Added the tutorial to teleport dialog (see the first post)
sorry to add it after a long time, i was a little busy
Reply
#6

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.
Reply
#7

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.
Reply
#8

So Why you post this if you are not finish
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)