[Question] Space in Commands
#5

I am away from a compiler, so I cannot compile and test this. If you are willing to do the legwork, I can fix any errors with it.

pawn Код:
dcmd_money(playerid, params[])
{
   // Declare a new string to hold the player input.
   new stringParameter[128];

   // Ensure that sscanf has received valid parameters. I have added the space following the "s" to trick sscanf into thinking there are more parameters.
   // Ex: "/money dm test", sscanf will stop processing after the space, and "test" will be discarded. If you instead are interested in the entire string (including spaces),
   // use "s" or "z". Details are at the links I've provided.
   if(sscanf(params, "s ", stringParameter)) return SendClientMessage(playerid, RED, "[ERROR]: You must enter a string!");

   // Search for the text in the parameter. The function declaration is as follows:
   // strfind(const string[], const sub[], bool: ignorecase=false, index=0)
   // Parameters followed with an equals sign are OPTIONAL.
   if(strfind(stringParameter, "dm", true) != -1) GivePlayerMoney(playerid, 100);  

   return 1;
}
https://sampwiki.blast.hk/w/index.php?title=Fast_Commands
https://sampwiki.blast.hk/wiki/Sscanf

These links both helped immensely when writing this code. The wiki should be the first resource you refer to while coding.
Reply


Messages In This Thread
[Question] Space in Commands - by Lorrden - 04.06.2009, 14:26
Re: [Question] Space in Commands - by Lorrden - 04.06.2009, 18:50
Re: [Question] Space in Commands - by samgreen - 04.06.2009, 19:13
Re: [Question] Space in Commands - by Lorrden - 04.06.2009, 19:17
Re: [Question] Space in Commands - by samgreen - 04.06.2009, 19:55
Re: [Question] Space in Commands - by Lorrden - 04.06.2009, 20:20
Re: [Question] Space in Commands - by samgreen - 04.06.2009, 20:33

Forum Jump:


Users browsing this thread: 1 Guest(s)