Help please
#1

Hey guys

I've got a problem
When I type /setstat without filling out an ID or value it automaticly sets ID 0 is first stat to 0

Please help

pawn Код:
COMMAND:setstat(playerid,params[])
{
new stat[20],id,value,string[286];
if(adminlevel[playerid] <2) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
if(sscanf(params,"us[20]d",id,stat,value)) SendClientMessage(playerid, COLOR_RED, "HINT: /setstat [playerid] [stat] [amount]");
if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
else

if(!strcmp(stat,"money",true))
{
money[id] = value;
format(string,sizeof(string),"Your money has been setted to %d by Admin %s",value,playername[playerid]);
SendClientMessage(id,COLOR_YELLOW,string);
format(string,sizeof(string),"You've setted %s's money to %d",playername[id],value);
SendClientMessage(id,COLOR_YELLOW,string);
}
else
if(!strcmp(stat,"age",true))
{
age[id] = value;
format(string,sizeof(string),"Your age has been setted to %d by Admin %s",value,playername[playerid]);
SendClientMessage(id,COLOR_YELLOW,string);
format(string,sizeof(string),"You've setted %s's age to %d",playername[id],value);
SendClientMessage(id,COLOR_YELLOW,string);
}
else
if(!strcmp(stat,"fishes",true))
{
fishes[id] = value;
format(string,sizeof(string),"Your fishes has been setted to %d by Admin %s",value,playername[playerid]);
SendClientMessage(id,COLOR_YELLOW,string);
format(string,sizeof(string),"You've setted %s's fishes to %d",playername[id],value);
SendClientMessage(id,COLOR_YELLOW,string);
}

else
SendClientMessage(playerid,COLOR_RED,"Invalid choice");
SendClientMessage(playerid,COLOR_RED,"money,age,fishes");
return 1;
}
Reply
#2

Well you have a few general coding errors here...please read the comments in my fixed syntax version of your code.

pawn Код:
COMMAND:setstat(playerid,params[])
{
    new stat[20],id,value,string[286];
    if(adminlevel[playerid] <2) return SendClientMessage(playerid,COLOR_RED,"You're not allowed to do this");
    if(sscanf(params,"us[20]d",id,stat,value)) return SendClientMessage(playerid, COLOR_RED, "HINT: /setstat [playerid] [stat] [amount]"); // We use return here to make sure that if the parameters aren't set, the code doesn't continue!
    if(!IsPlayerConnected(id)) return SendClientMessage(playerid,COLOR_RED,"Player not connected");
    else // This will work in this case without wrapping the following code without brackets because it's followed by an if statement which will continue the chain, BUT it's much neater and more readable to wrap the following in brackets
    {
        if(!strcmp(stat,"money",true))
        {
            money[id] = value;
            format(string,sizeof(string),"Your money has been setted to %d by Admin %s",value,playername[playerid]);
            SendClientMessage(id,COLOR_YELLOW,string);
            format(string,sizeof(string),"You've setted %s's money to %d",playername[id],value);
            SendClientMessage(id,COLOR_YELLOW,string);
        }
        else if(!strcmp(stat,"age",true))
        {
            age[id] = value;
            format(string,sizeof(string),"Your age has been setted to %d by Admin %s",value,playername[playerid]);
            SendClientMessage(id,COLOR_YELLOW,string);
            format(string,sizeof(string),"You've setted %s's age to %d",playername[id],value);
            SendClientMessage(id,COLOR_YELLOW,string);
        }
        else if(!strcmp(stat,"fishes",true))
        {
            fishes[id] = value;
            format(string,sizeof(string),"Your fishes has been setted to %d by Admin %s",value,playername[playerid]);
            SendClientMessage(id,COLOR_YELLOW,string);
            format(string,sizeof(string),"You've setted %s's fishes to %d",playername[id],value);
            SendClientMessage(id,COLOR_YELLOW,string);
        }
        else // You need to wrap the following code in brackets here, as you have multiple functions you want to run should the else statement be true.
        {
            SendClientMessage(playerid,COLOR_RED,"Invalid choice");
            SendClientMessage(playerid,COLOR_RED,"money,age,fishes");
        }
    }
    return 1;
}
Reply
#3

Thankyou very much. It works perfectly now.
I understand the problems.

BTW:
Is your name dutch ? :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)