Shortcuts on input
#1

So I'm trying to create a command
PHP код:
CMD:createeffect(playeridparams[])
{
    new 
ideffect[15];
    if(
sscanf(params"r,s[15]"ideffect))
    {
        
SendClientMessage(playeridCOLOR_GREY"USAGE: /createeffect [PON/id] [fire/lightning]");
        return 
1;
    }
    if(
strcmp(effect"fire"true) == 0)
    {
        
CreateEffect(id1);
    }
    return 
1;

Is there any way a player can just write "f", "fi", or "fir" instead of the whole word "fire"?
Reply
#2

Код:
CMD:createeffect(playerid, params[])
{
    new id, effect[15];
    if(sscanf(params, "r,s[15]", id, effect))
    {
        SendClientMessage(playerid, COLOR_GREY, "USAGE: /createeffect [PON/id] [fire/lightning]");
        return 1;
    }
    if(strcmp(effect, "fire", true) == 0 || strcmp(effect,"f",true) == 0)
    {
        CreateEffect(id, 1);
    }
    return 1;
}
This should work
Reply
#3

Awesome, thanks!
Reply
#4

The answer above will compare if you entered either "fire" or "f" but no "fi" or "fir"
use strfind instead
Код:
if(strfind("fire", effect, true) == 0)
Reply
#5

Quote:
Originally Posted by NealPeteros
Посмотреть сообщение
PHP код:
    if(sscanf(params"r,s[15]"ideffect)) 
You shouldn't use a comma there. It should be
PHP код:
if(sscanf(params"rs[15]"ideffect)) 
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)