Creating a Command reason -
stormchaser206 - 06.04.2012
I am trying to create a cmdreason thing. I see it in other gamemodes, but when i try it in mine, it doesn't work.
Like:
/test [Reason]
and that reason would be cmdreason. Any help??
Re: Creating a Command reason -
ReneG - 06.04.2012
What do you mean by command reason?
Respuesta: Creating a Command reason -
Chris1337 - 06.04.2012
you mean creating a string?
Respuesta: Creating a Command reason -
TiNcH010 - 06.04.2012
pawn Код:
if(!strcmp("/test", cmd, true))
{
tmp = strtok(cmdtext, idx);
new str[128];
format(str, sizeof(str), "Reason: %s", tmp);
SendClientMessage(playerid, -1, str);
return 1;
}
?
Respuesta: Creating a Command reason -
Chris1337 - 06.04.2012
Quote:
Originally Posted by TiNcH010
pawn Код:
if(!strcmp("/test", cmd, true)) { tmp = strtok(cmdtext, idx); new str[128]; format(str, sizeof(str), "Reason: %s", tmp); SendClientMessage(playerid, -1, str); return 1; }
?
|
why string in 128 , why not 64?
Respuesta: Creating a Command reason -
TiNcH010 - 06.04.2012
Quote:
Originally Posted by axxelac
why string in 128 , why not 64?
|
Because if he want write too long..
Or you can try this:
pawn Код:
if(!strcmp("/test", cmdtext, true))
{
new str[128];
format(str, sizeof(str), "Reason: %s", cmdtext[1]);
SendClientMessage(playerid, -1, str);
return 1;
}
Re: Creating a Command reason -
[HiC]TheKiller - 07.04.2012
Take a look at a command processor like ZCMD, it's much easier for beginners.
https://sampforum.blast.hk/showthread.php?tid=91354
Re: Creating a Command reason -
stormchaser206 - 08.04.2012
I meant a reason, like this:
(Ignore the ID part) You wanted a reason for a ban.
So: /ban ID
REASON
The reason part is the one i need help on. I need to add that
Re: Creating a Command reason - kikito - 08.04.2012
Quote:
Originally Posted by stormchaser206
I meant a reason, like this:
(Ignore the ID part) You wanted a reason for a ban.
So: /ban ID REASON
The reason part is the one i need help on. I need to add that
|
Use sscanf.
If not, you can check the gamemodes on the gamemodes category, and take the /ban comand.
Re: Creating a Command reason -
ReneG - 08.04.2012
Using strtok to check parameters is an impractical way of making commands.
Here you can see a ban command be made in 20 lines.
pawn Код:
CMD:ban(playerid,params[])
{
new string[128],
reason[50],
target;
if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, -1, "You are not allowed to use this command.");
if(sscanf(params,"us[50]",target,reason)) return SendClientMessage(playerid, -1, "USAGE: /ban [playerid] [reason]");
else
{
new
name[24],
targetname[24];
GetPlayerName(playerid,name,sizeof(name));
GetPlayerName(target,targetname,sizeof(targetname));
format(string,sizeof(string),"Administrator %s has banned %s. Reason: %s",name,targetname,reason);
SendClientMessageToAll(-1, string);
Ban(target);
}
return 1;
}