16.09.2015, 13:37
(
Последний раз редактировалось xTURBOx; 28.09.2015 в 12:25.
)
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>
First we need to get the teleport coordinates to do that:
- Go to any server(or debug)
- Go to your desired place
- type /rs (this saves only the raw position unlike /save, thus making it a lot eaiser)
- close gta and goto Documents\GTA San Andreas User Files\SAMP
- open the file named rawpositions.txt(coordinates will be saved in this file)
Teleport Command
Making the command
As we are using zcmd
PHP код:
CMD:sfairport(playerid,params[])
{
//function
return 1;
}
Function SetPlayerPos
so now use the function SetPlayerPos
PHP код:
SetPlayerPos(playerid,YOURCOORDINATESHERE);//set the player position
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
PHP код:
CMD:sfairport(playerid,params[])
{
SetPlayerPos(playerid,-1534.4138,-75.4995,14.1484,307.1554);
return 1;
}
we will use
PHP код:
IsPlayerInAnyVehicle(playerid)
PHP код:
new vehicleid = GetPlayerVehicleID(playerid);
SetVehiclePos(vehicleid,-1534.4138,-75.4995,14.1484,307.1554);
PHP код:
if(IsPlayerInAnyVehicle(playerid))
{
new vehicleid = GetPlayerVehicleID(playerid);
SetVehiclePos(vehicleid,-1534.4138,-75.4995,14.1484,307.1554);
}
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;
}
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
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;
}
PHP код:
SendClientMessage(playerid,COLOR,Message);
PHP код:
GameTextForPlayer(playerid,Message,time,style)
PHP код:
SendClientMessage(playerid,COLOR_GREEN,"You have been teleported to sanfierro airport successfully!");
GameTextForPlayer(playerid, "~b~Welcome to~r~ sf airport!", 3000, 3);
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!", 3000, 3);
}
//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!", 3000, 3);
}
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
}
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: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");
example
PHP код:
ShowPlayerDialog(playerid,dialogid,DIALOG_STYLE_MSGBOX,"Title","Line 1\n line 2\n line 3","Select","Close");
Код:
Line 1 line 2 line 3
PHP код:
CMD:teleports(playerid,params[])
{
ShowPlayerDialog(playerid,2316,DIALOG_STYLE_LIST,"Teleports","San fierro Airport\nWang Cars\nOttocars","Select","Close");
}
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(playerid, dialogid, response, listitem, inputtext[])
PHP код:
if(dialogid == 2316)
For your ease you can also define dialogs(i will not explain that)
PHP код:
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 2316)
{
PHP код:
if(response)
PHP код:
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 2316)
{
if(response)
{
PHP код:
switch(listitem)
PHP код:
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 2316)
{
if(response)
{
switch(listitem)
{
PHP код:
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
if(dialogid == 2316)
{
if(response)
{
switch(listitem)
{
case 0:
case 1:
case 2:
}
}
return 1;
}
return 0;
}
on case 1: to wang cars and so on
so the final code will be
PHP код:
OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
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;
}