SA-MP Forums Archive
[Question] Space in Commands - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: [Question] Space in Commands (/showthread.php?tid=80410)



[Question] Space in Commands - Lorrden - 04.06.2009

Hi there!
Could someone be kind enough to tell me;
if the player only types "/hi" there will come a message like : "There's something missing..."
and if he types /hi there he gets teleported to someplace ...

(I use DCMD, dutils, dini and SSCANF if that could be to any helt )

I just know how to make with numbers and not with text, please help me out


Re: [Question] Space in Commands - Lorrden - 04.06.2009

bump.. sorry, need help with this one, can't fin anything other than /command [nr]
searched in Pen script and other too..


Re: [Question] Space in Commands - samgreen - 04.06.2009

I'm not sure I fully understand the question. Are you asking how to parse parameters that are strings instead of numbers?

Why don't you post the code that you have for /command [number], and I can help you to adapt it to parse text instead.


Re: [Question] Space in Commands - Lorrden - 04.06.2009

okay, here's a really simple /money <amount> command wich will give the player as much as he enters after "money"
instead I'd like it to be if he types /money dm he will recieve 100$
Just so you perhaps can make me understand how to do :P

[pawn]
dcmd_money(playerid, params[])
{
new amount;
{
if(sscanf(params, "d", amount)) return SendClientMessage(playerid, RED,"[ERROR]: You forgot to enter an Amount");
GivePlayerMoney(playerid, amount);
}
return 1;
}
[pawn]


Re: [Question] Space in Commands - samgreen - 04.06.2009

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.


Re: [Question] Space in Commands - Lorrden - 04.06.2009

No errors but IG it says "You need to enter a string" even if i type /money dm


Re: [Question] Space in Commands - samgreen - 04.06.2009

Put an ! before the sscanf in the if statement. I'm not sure what sscanf returns.