SA-MP Forums Archive
Help with this command REP++ - 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)
+--- Thread: Help with this command REP++ (/showthread.php?tid=380457)



Help with this command REP++ - Biess - 25.09.2012

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?


Re: Help with this command REP++ - Glint - 25.09.2012

Why are you returning 0 ?


Re: Help with this command REP++ - Biess - 25.09.2012

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


Re: Help with this command REP++ - Vince - 25.09.2012

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;
}



Re: Help with this command REP++ - .v - 25.09.2012

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;


Re: Help with this command REP++ - Biess - 25.09.2012

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


Re: Help with this command REP++ - Vince - 25.09.2012

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


Re: Help with this command REP++ - Biess - 25.09.2012

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;
}



Re: Help with this command REP++ - Glint - 25.09.2012

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.


Re: Help with this command REP++ - Biess - 25.09.2012

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...