[HELP]how to make a dcmd command with multiples parameters?
#1

i need help to make a commands with multiple parameters i tried with the wiki but it don't explain with multiple parameters
help please
thanks
Reply
#2

Help yourself with sscanf.
Reply
#3

example PM dcmd.
pawn Код:
dcmd_pm(playerid, params[])
{
 new otherid, result[256], string[256];
 if(sscanf(params, "us", otherid, result) SendClientMessage(playerid, RED, "Usage: /PM [ID] [MSG]");
 // The "us" part is the format of the input. u is for username or playerid and s is for string which is the message.
 else
 {
   format(string, sizeof(string), "PM(%d): %s", playerid, result);
   SendClientMessage(otherid, YELLOW, string);
 }
 return 1;
}
Reply
#4

... Why you shouldn't make your strings 256 cells big

pawn Код:
dcmd_pm(playerid, params[])
{
 new otherid, result[100], string[128];
 if(sscanf(params, "us", otherid, result) SendClientMessage(playerid, RED, "Usage: /PM [ID] [MSG]");
 else if(otherid == INVALID_PLAYER_ID) SendClientMessage(playerid, RED, "Error: Player not found.");
 else
 {
   format(string, sizeof(string), "PM(%d): %s", playerid, result);
   SendClientMessage(otherid, YELLOW, string);
   SendClientMessage(playerid, YELLOW, string);
 }
 return 1;
}
You can read more about this here: https://sampwiki.blast.hk/wiki/Fast_Commands
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)