[Tutorial] ZCMD How to create Goto command
#1

Hi guys, this is my first tutorial, I'll show you how to create a Goto command with ZCMD:
First of all, your includes should be:
Код:
#include <a_samp>
#include <zcmd>
#include <sscanf2> //SSCANF PLUGIN NEED TO BE IN THE STRING "plugins" OF YOUR server.cfg (I know there isn't this string, just write under everything: plugins sscanf)
Now the code:
GOTO:
First of all you need to use the CMD string:
Код:
CMD:goto(playerid, params[])
{
     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You need to be RCON for use this command"); //This is the line that define if the player is an admin or not, notice: the "!" is same as "if is not" (you can change with your enums);
     return 1;
}
Now I'll show you what this mean:
"CMD:" everyone know this xD;
"goto" it's the Command where we'll use (sorry for my bad english, I'm italian and 13 °>°) with the slash (like "/goto");
"playerid" is the ID who use the command, in this case playerid, is "you";
"params[]" is the param that define our params, like ID, pn, an, ecc."
Now the "new":
Код:
CMD:goto(playerid, params[])
{
     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You need to be RCON for use this command");
     new ID; //This is the player target (like targetid)
     new pn[MAX_PLAYER_NAME]; //This is the param of ID and it is used for define who was the target
     new an[MAX_PLAYER_NAME];//Same as above but this is used for "me" (playerid), MAX_PLAYER_NAME is the param that get our name
     new str[128]; //This is the string that we'll use in "format"
     return 1;
}
Ah, we are near the finish line!
Now the command!
Код:
CMD:goto(playerid, params[])
{
     if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "You need to be RCON for use this command");
     new ID;
     new pn[MAX_PLAYER_NAME]; 
     new an[MAX_PLAYER_NAME];
     new str[128]; 
     if(sscanf(params, "u", ID)) return SendClientMessage(playerid, 0xFF0000AA, "USAGE: /goto [ID]"); //This is a long line, "sscanf" is the plugin that search the missing params, "params" is the param that define params LOL, "u" is the PARAM that define the MISSING ID, ID is the param for the targetid
     if(!IsPlayerConnected(ID)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR: This player is not connected");//Same as !IsPlayerAdmin, but instead of "playerid" we put "ID" because it's the targetid
     GetPlayerName(playerid, an, MAX_PLAYER_NAME);//Define the playerid's param
     GetPlayerName(ID, pn, MAX_PLAYER_NAME);//Define the ID's param
     new Float:x; //Defining float X
     new Float:y; //Same
     new Float:z; //Same
     GetPlayerPos(ID, x, y, z); //This line get the "ID" position
     SetPlayerPos(playerid, x+1, y+1, z); //This line set the "playerid" position from "ID" position, with some changes(x+1, y+1);
     format(str, sizeof(str), "You have been teleported to %s", pn); //Showed before, this is the line that give the message to playerid)
     SendClientMessage(playerid, 0x00FF00AA, str); //This line give the message to playerid
     if(IsPlayerInAnyVehicle(playerid)) //Mhh, let's give you a question, what should this callback do?
     {
          GetPlayerPos(ID, x, y, z);
          SetVehiclePos(playerid, x+1, y+1, z); //And this one? :D
     }
     return 1;
}
IF YOU WANNA TELEPORT INSIDE A VEHICLE THEN:
add under if(IsPlayerInAnyVehicle(ID))
Код:
GetVehiclePos(ID, x, y, z);
PutPlayerInVehicle(playerid, ID, 2);//"2" is the seatid
TESTED: WORKED
Finish, I remember, I'm 13 and I'm italian, my english should not be good!
Reply
#2

Nice Tutorial
Reply
#3

Thanks
Reply
#4

Isn't it easier to get the positions like this :
Код:
new Float:pos[3];
GetPlayerPos(ID, pos[0], pos[1], pos[2]);
then doing it like this :
Код:
new Float:x; //Defining float X
new Float:y; //Same
new Float:z; //Same
GetPlayerPos(ID, x, y, z); //This line get the "ID" position
Reply
#5

Yes it is Markon
Reply
#6

no, the best way is to define the floats, because they get already the floats
Reply
#7

Nice, but if you make a whole tutorial for only one cmd, can't you make it a little advanced, like when you use goto to a player who's inside a vehicle, you will be teleported inside that vehicle instead of on top of it. For example.
Reply
#8

yeah, asd
Reply
#9

There are some errors!

goto.pwn(117) : error 029: invalid expression, assumed zero
goto.pwn(117) : error 001: expected token: ",", but found ";"
goto.pwn(121) : warning 203: symbol is never used: "vehicleid"
goto.pwn(106) : warning 203: symbol is never used: "health"

Pastebin: http://pastebin.com/Z6cE4h0a (for line numbers)
Reply
#10

Quote:
Originally Posted by MarkoN
Посмотреть сообщение
Isn't it easier to get the positions like this :
Код:
new Float:pos[3];
GetPlayerPos(ID, pos[0], pos[1], pos[2]);
then doing it like this :
Код:
new Float:x; //Defining float X
new Float:y; //Same
new Float:z; //Same
GetPlayerPos(ID, x, y, z); //This line get the "ID" position
Same thing, really...
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)