[Tutorial] Simple Commands [ZCMD] - Explained!
#1

Simple Commands


This tutorial will teach you the following:

• How to create a command that checks your id
• How to create a command that spawns JetPack
• How to create me command
______________________________________________

Explanation:

pawn Код:
CMD:myid(playerid, params[])
{
    new string[90]; //this is enough for the line "Your id is %d" - we will gonna format the word "Your id is %d"
    format(string, sizeof(string), "Your id is %d", playerid); //will gonna format the word "Your id is %d" with string/playerid and gonna use on SendClientMessage - %d - Inserts an integer (whole) number
    SendClientMessage(playerid, -1, string); //this will be sent to the player who type /myid with the format string
    return 1;
}

CMD:jetpack(playerid, params[])
{
    new string[90],pname[MAX_PLAYER_NAME]; //string 90 is enough for line "%s has spawned jetpack"/we will define pname with GetPlayerName
    GetPlayerName(playerid, pname, sizeof(pname)); //pname is define here
    format(string, sizeof(string), "%s has spawned jetpack", pname); //will gonna format the word "%s has spawn jetpack" with string/pname and gonna use on SendClientMessageToAll - %s - Inserts a string.
    SendClientMessageToAll(-1, string); //this will be sent to the everyone with format string.
    SetPlayerSpecialAction(playerid, 2); //Spawns a jetpack to the player
    return 1;
}

CMD:me(playerid, params[])
{
    new string[128],pname[MAX_PLAYER_NAME]; //this is enough for the line "%s %s"/we will gonna define pname with GetPlayerName
    GetPlayerName(playerid, pname, MAX_PLAYER_NAME); //pname is defined here with GetPlayerName
    if(isnull(params)) return SendClientMessage(playerid, COLOR_RED, "SYNTAX: /me <text>"); //if player didn't type something this message will be showed example if you type: /me only the word will be showed
    format(string, sizeof(string), "[ME]: %s %s", pname, params); //will gonna format the word "[ME]: %s %s" with string/pname/params and gonna use on SendClientMessageToAll - %s - inserts a string.
    SendClientMessageToAll(-1, string); //this will be sent to the everyone with format string.
    return 1;
}
the explanation is in command. i hope i helped
tell me if the command is not working and i will change the thread.
Reply
#2

Should this be a reference to this one or what? https://sampforum.blast.hk/showthread.php?tid=319000

By the way, why you define a that big string? For the first and the second command, 64 would be enough, and "myid" isn't really neccessary, 'cause you can see your ID when you press "Tab" at all...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)