13.06.2015, 20:29
(
Last edited by bgedition; 01/05/2016 at 06:15 PM.
)
Hello there,
I'm making this tutorial because three days ago I was looking for exactly the same command but I found nothing.
Now, finally I made this command and I want so share it to all of you. It is very simple, only 11 lines, we are forcing only commands made with ZCMD. I think you will like it. Lets do it.. And If I have any mistakes, please tell me to fix them. Enjoy
Requirements:
1. ZCMD by ZeeX.
2. SSCANF by Y_Less.
The tutorial...
Line 1: - Creating the command.
Code:
CMD:forcecmd(playerid, params[]) {
'forcecmd' is the new command.
'playerid' in the brackets is the player who is using this command.
'params[]' is string, this will store the parameters after the command.
Line2: - creating variables...
Code:
new TargetID, Command[34], Params[129], string[50];
'TargetID' We will use this to store the player's id of the player you want.
'Command[34]' There will be stored the command you want to use onto 'TargetID'. Max lenght 34 characters.
'Params[129]' There will be stored the parameters of the command you want to use onto a player.
'string[50]' There will be stored the formated command that is using from 'zcmd' include.
Line 3: - Checking if the player who is using 'forcecmd' is admin (RCON).
Code:
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1 , "{E03636}[ERROR]: {FFFFFF}You are not authorized to use this command!");
Line 4: - sscanf part
Code:
if(sscanf(params, "us[32]S()[128]", TargetID, Command, Params)) return SendClientMessage(playerid, -1, "{36E0B9}[USAGE]: {FFFFFF}/forcecmd <PlayerID/PartOfName> <Command> <Params>");
Line 5: Checking ids
Code:
if(playerid == TargetID) return SendClientMessage(playerid, -1, "{E0AE36}[WARNING]: {FFFFFF}You cannot use this command on yourself.");
Line 6: - Checking for TargetID if is connected.
Code:
if(!IsPlayerConnected(TargetID)) return SendClientMessage(playerid, -1, "{E03636}[ERROR]: {FFFFFF}This player is not connected.");
Line 7: - Some details.
Code:
if(Command[0] == '/') strdel(Command, 0, 1);
Line 8: - Formating the command.
Code:
format(string, sizeof(string), "cmd_%s", Command);
Line 9: - If the 'Command' is unknown for the server.
Code:
if(!CallLocalFunction(string, "ds", TargetID, "\1")) return SendClientMessage(playerid, -1, "{E03636}[ERROR]: {FFFFFF}This command is unknown.");
Line 10: Return value.
Code:
return 1;
Line 11: The closing bracket.
Code:
}
And now, the final result should be:
Code:
CMD:forcecmd(playerid, params[]) { new TargetID, Command[34], Params[129], string[50]; if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1 , "{E03636}[ERROR]: {FFFFFF}You are not authorized to use this command!"); if(sscanf(params, "us[32]S()[128]", TargetID, Command, Params)) return SendClientMessage(playerid, -1, "{36E0B9}[USAGE]: {FFFFFF}/forcecmd <PlayerID/PartOfName> <Command> <Params>"); if(playerid == TargetID) return SendClientMessage(playerid, -1, "{E0AE36}[WARNING]: {FFFFFF}You cannot use this command on yourself."); if(!IsPlayerConnected(TargetID)) return SendClientMessage(playerid, -1, "{E03636}[ERROR]: {FFFFFF}This player is not in this server."); if(Command[0] == '/') strdel(Command, 0, 1); format(string, sizeof(string), "cmd_%s", Command); if(!CallLocalFunction(string, "ds", TargetID, isnull(Params) ? ("\1") : Params)) return SendClientMessage(playerid, -1, "{E03636}[ERROR]: {FFFFFF}This command is unknown."); }