Help with this command REP++
#1

pawn Код:
CMD:giveallscore(playerid, params[])
{
    if(PInfo[playerid][Level] < 4) return SendClientMessage(playerid,0xFF0000AA,"ERROR: You are not allowed to use this command!");//Checking if the player has admin level 3, if not it sends him a message.
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        new ammount;
        if(sscanf(params,"i", ammount))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /giveallscore [score]");
        else
        {
            new score = GetPlayerScore(i);
            SetPlayerScore(i, score + ammount);
            new pname[24],dstring[124];
            GetPlayerName(playerid,pname,sizeof(pname));
            format(dstring, sizeof(dstring), "Administrator %s has given everybody %d score.", pname, ammount);
            SendClientMessageToAll(blue, dstring);
         }
        return 0;
    }
    return 1;
}
Okay so when i type /giveallscore it says
pawn Код:
Administrator Max has given everybody (amount) score
witch is good.
But it also returns this message
pawn Код:
SERVER: That command does not exist, use /cmds for all our commands
what did i do wrong?
Reply
#2

Why are you returning 0 ?
Reply
#3

Quote:
Originally Posted by [Lexi]
Посмотреть сообщение
Why are you returning 0 ?
Else it was saying the same message hundres of times
Reply
#4

NEVER return inside a loop unless you explicitly want to break out of it. But actually your whole command is flawed. Removing the return will just spam the server with SendClientMessageToAll, which is probably the reason why you put it there in the first place.

pawn Код:
CMD:giveallscore(playerid, params[])
{
    if(PInfo[playerid][Level] < 4) return SendClientMessage(playerid,0xFF0000AA,"ERROR: You are not allowed to use this command!");//Checking if the player has admin level 3, if not it sends him a message.

    new ammount;
    if(sscanf(params,"i", ammount))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /giveallscore [score]");

    for(new i=0; i<MAX_PLAYERS; i++)
        SetPlayerScore(i, GetPlayerScore(i) + ammount);
   
    new pname[24],dstring[124];
    GetPlayerName(playerid,pname,sizeof(pname));
    format(dstring, sizeof(dstring), "Administrator %s has given everybody %d score.", pname, ammount);
    SendClientMessageToAll(blue, dstring);
    return 1;
}
Reply
#5

Hmm. I don't see any code that will send a message to the player "SERVER: That command does not exist, use /cmds for all our commands"

Lexi was right I think It's because it was returning to 0;
Reply
#6

Quote:
Originally Posted by Vince
Посмотреть сообщение
NEVER return inside a loop unless you explicitly want to break out of it. But actually your whole command is flawed. Removing the return will just spam the server with SendClientMessageToAll, which is probably the reason why you put it there in the first place.

pawn Код:
CMD:giveallscore(playerid, params[])
{
    if(PInfo[playerid][Level] < 4) return SendClientMessage(playerid,0xFF0000AA,"ERROR: You are not allowed to use this command!");//Checking if the player has admin level 3, if not it sends him a message.

    new ammount;
    if(sscanf(params,"i", ammount))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /giveallscore [score]");

    for(new i=0; i<MAX_PLAYERS; i++)
        SetPlayerScore(i, GetPlayerScore(i) + ammount);
   
    new pname[24],dstring[124];
    GetPlayerName(playerid,pname,sizeof(pname));
    format(dstring, sizeof(dstring), "Administrator %s has given everybody %d score.", pname, ammount);
    SendClientMessageToAll(blue, dstring);
    return 1;
}
Thanks, can you text me what you did actualy?
Because i need the same with this command:
pawn Код:
CMD:giveallmoney(playerid, params[])
{
    if(PInfo[playerid][Level] < 4) return SendClientMessage(playerid,0xFF0000AA,"ERROR: You are not allowed to use this command!");//Checking if the player has admin level 3, if not it sends him a message.
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        new ammount;
        if(sscanf(params,"i", ammount))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /giveallmoney [ammount]");
        else
        {
        new pname[24],dstring[124];
        GetPlayerName(playerid,pname,sizeof(pname));
        PlayerPlaySound(i,1057,0.0,0.0,0.0);
        format(dstring,sizeof(dstring),"Administrator %s has given everybody %d money!",pname, ammount );
        SendClientMessageToAll(blue,dstring);
        }
       return 0;
    }
    return 1;
}
NOTICE: CAN YOU ALSO FIX THE GIVEALLMONEY ITS NOT WORKING PROPERLY EITHER
Reply
#7

Only use functions in the loop for which you need the loop variable (in this case i). Move all the rest outside the loop.
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
Only use functions in the loop for which you need the loop variable (in this case i). Move all the rest outside the loop.
So can you fix my other command to? and show with // what you changed ?

@Ronaldo_raul™ my giveallscore is already working and fixed ((It was already working only thing was the string))
I only need the giveallmoney to be fixed and i dont use those errors messages i use my own


pawn Код:
public OnPlayerCommandPerformed(playerid, cmdtext[], success)
{
if(success == 0)
SendClientMessage(playerid, red, "SERVER: That command does not exist, use /cmds for all our commands!");
return 1;
}
Reply
#9

Quote:
Originally Posted by Biess
Посмотреть сообщение
So can you fix my other command to? and show with // what you changed ?
He told you what you need to do, then do it yourself he is not going to fix all of your commands.
Reply
#10

Quote:
Originally Posted by [Lexi]
Посмотреть сообщение
He told you what you need to do, then do it yourself he is not going to fix all of your commands.
But i dont get it...
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)