Help Scripting Give Money
#1

what should be changed script from Give Money Player to Give Money All Player

This is the code Give Money to Player
Код:
CMD:givemoney(playerid, params[])
{
    new id, money, string[128], string2[128];
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR:You're not an admin.");
    {
        if(sscanf(params,"ii",id,money)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /givemoney [ID] [amount]");
        else
            GivePlayerMoney(id,money);
        format(string, sizeof(string),"You have give player %s %d$!", GetName(id), money);
        SendClientMessage(playerid, COLOR_GREY, string);
        format(string2 ,sizeof(string2),"Administrator %s has given you %d$!", GetName(id), money);
        SendClientMessage(id, COLOR_GREY, string2);
    }
    return 1;
}
What should be changed in order to Give Money to All Player?
Reply
#2

You would need to loop through all the players. https://sampwiki.blast.hk/wiki/Loops
Better yet, just use foreach, it's much faster looping through players.
Reply
#3

pawn Код:
CMD:givemoneytoall(playerid, params[])
{
    new money, string[128], string2[128];
    if(!IsPlayerAdmin(playerid)) return SendClientMessage(playerid, 0xFF0000AA, "ERROR:You're not an admin.");
    {
        if(sscanf(params,"i",money)) return SendClientMessage(playerid,COLOR_WHITE,"USAGE: /givemoneytoall [amount]");
        else
        for(new i=0; i < MAX_PLAYERS; i++)
        {
            GivePlayerMoney(i,money);
            format(string2 ,sizeof(string2),"Administrator %s has given you %d$!", GetName(id), money);
            SendClientMessage(i, COLOR_GREY, string2);
        }
        format(string, sizeof(string),"You have given everyone %d$!", money);
        SendClientMessage(playerid, COLOR_GREY, string);
       
    }
    return 1;
}
All you have to do is adding a loop that loops trough all players, then apply GivePlayerMoney for 'i', inside the loop. DBan's suggestion above me is also a good one, czech out foreach if you're learning anyway, it's not much new
Reply
#4

I've tried it and compile the results of this
Код:
C:\Users\Home\Downloads\Compressed\MODE SAMP\CBF FreeRoam\gamemodes\CBF.pwn(3208) : error 017: undefined symbol "id"
C:\Users\Home\Downloads\Compressed\MODE SAMP\CBF FreeRoam\gamemodes\CBF.pwn(3213) : error 017: undefined symbol "id"
how do I fix it
Reply
#5

Replace this :
Код:
format(string2 ,sizeof(string2),"Administrator %s has given you %d$!", GetName(id), money);
By this :
Код:
format(string2 ,sizeof(string2),"Administrator %s has given you %d$!", GetName(playerid), money);
Reply
#6

ok thanks all xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)