/givescoreall and /givemoneyall
#1

Basically, when i (Or any other admin) type /givescoreall [Score-Amount], the message sends twice.
For an example - If there are 2 admins online, the message will be sent 2 times, but If I'm the only admin online, it will be sent only once.
The same happens with /givemoneyall
Here's an picture.

http://i.imgur.com/DA7dLN3.jpg?1

Codes:

pawn Код:
CMD:givescoreall(playerid, params[]) {
    new score;
    if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_RED, "[ADMIN] - You're not a high enough level to use this command!");
    if(sscanf(params, "d", score)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] - /givescoreall [AMMOUNT]");
    if( score < 1 ) return SendClientMessage(playerid, COLOR_RED, "[ERROR] - You need to give more than 0 score.");
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            new string[74];
            new name[MAX_PLAYER_NAME];
            GetPlayerName(i, name, sizeof(name));
            SetPlayerScore(playerid,GetPlayerScore(playerid)+score);
            format(string, sizeof(string), "[ADMIN] - %s[%d] has used GIVESCOREALL - %d -", name, i, score);
            SendMessageToAdmins(string);
            format(string, sizeof(string), "* Admin %s[%d] has given %d score to everyone!", name, i, score);
            SendClientMessageToAll(COLOR_YELLOW, string);
        }
    }
    return 1;
}
CMD:givemoneyall(playerid, params[]) {
    new money;
    if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_RED, "[ADMIN] - You're not a high enough level to use this command!");
    if(sscanf(params, "d", money)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] - /givemoneyall [AMMOUNT]");
    if( money < 1 ) return SendClientMessage(playerid, COLOR_RED, "[ERROR] - You need to give more than 0$");
    for(new i = 0; i < MAX_PLAYERS; i ++)
    {
        if(IsPlayerConnected(i))
        {
            new string[74];
            new name[MAX_PLAYER_NAME];
            GetPlayerName(i, name, sizeof(name));
            GivePlayerMoney(i, money);
            format(string, sizeof(string), "[ADMIN] - %s[%d] has used GIVEMONEYALL - %d -", name, i, money);
            SendMessageToAdmins(string);
            format(string, sizeof(string), "* Admin %s[%d] has given %d$ to everyone!", name, i, money);
            SendClientMessageToAll(COLOR_YELLOW, string);
        }
    }
    return 1;
}
Reply
#2

You used SendClientMessageToAll inside a loop, that's why.

I recommend you to use foreach for players-looping since it loops ONLY through connected players and it's MUCH faster!

pawn Код:
CMD:givescoreall(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_RED, "[ADMIN] - You're not a high enough level to use this command!");
    new
        score;
    if (sscanf(params, "d", score)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] - /givescoreall [AMMOUNT]");
    if (score < 1) return SendClientMessage(playerid, COLOR_RED, "[ERROR] - You need to give more than 0 score.");
    new
        string[74],
        name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(string, sizeof(string), "[ADMIN] - %s[%d] has used GIVESCOREALL - %d -", name, playerid, score);
    SendMessageToAdmins(string);
    format(string, sizeof(string), "* Admin %s[%d] has given %d score to everyone!", name, playerid, score);
    SendClientMessageToAll(COLOR_YELLOW, string);

    for (new i; i != MAX_PLAYERS; ++i)
    {
        if (!IsPlayerConnected(i)) continue;
        SetPlayerScore(i, GetPlayerScore(i) + score);
    }
    return 1;
}

CMD:givemoneyall(playerid, params[])
{
    if(PlayerInfo[playerid][pAdmin] < 3) return SendClientMessage(playerid, COLOR_RED, "[ADMIN] - You're not a high enough level to use this command!");
    new
        money;
    if(sscanf(params, "d", money)) return SendClientMessage(playerid, COLOR_RED, "[USAGE] - /givemoneyall [AMMOUNT]");
    if( money < 1 ) return SendClientMessage(playerid, COLOR_RED, "[ERROR] - You need to give more than 0$");
    new
        string[74],
        name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, MAX_PLAYER_NAME);
    format(string, sizeof(string), "[ADMIN] - %s[%d] has used GIVEMONEYALL - %d -", name, playerid, money);
    SendMessageToAdmins(string);
    format(string, sizeof(string), "* Admin %s[%d] has given %d$ to everyone!", name, playerid, money);
    SendClientMessageToAll(COLOR_YELLOW, string);
   
    for (new i; i != MAX_PLAYERS; ++i)
    {
        if (!IsPlayerConnected(i)) continue;
        GivePlayerMoney(i, money);
    }
    return 1;
}
Reply
#3

//EDIT: too slow >.<

SendClientMessageToAll ... in a loop :S
it will be send to everyone every time until the condition in your loop (i < MAX_PLAYERS) equals false

so if there are 30 players online (jep players, cuz youre not checking if that playerid looping trough is an admin or not.), you get 30 messages. Simple as that.
Reply
#4

Edit: Too late, my net is slowass..
Reply
#5

Alright, thanks to everyone who helped
(Sadly can't give any reputation to Konstantinos, cause i need to "Spread out some reputation" before +repping him)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)