SA-MP Forums Archive
Money bug ( GTA ) - 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: Money bug ( GTA ) (/showthread.php?tid=448957)



Money bug ( GTA ) - morocco - 06.07.2013

Hi guys

i make this CMD

pawn Код:
CMD:givemoney(playerid, params[])
{
    new playerb, amount, string[128];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
    if(sscanf(params, "ui", playerb, amount)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /givemoney [playerid] [amount]");
    if(!IsPlayerLoggedIn(playerb)) return SendClientMessage(playerid, COLOR_GREY, "Invalid player id.");
    PlayerInfo[playerb][pMoney] = PlayerInfo[playerb][pMoney]+amount;
    GiveZaiatMoney(playerb, amount);
    format(string, sizeof(string), " Administrator %s has given you $%d", RPN(playerid), amount);
    SendClientMessage(playerb, COLOR_WHITE, string);
    format(string, sizeof(string), "AdmWarn: %s has given %s $%d.", RPN(playerid), RPN(playerb), amount);
    SendAdminMessage(COLOR_DARKRED, 1, string);
    Log("logs/givemoney.log", string);
    OnPlayerSave(playerb);
    return 1;
}

CMD:setmoney(playerid, params[])
{
    new playerb, amount, string[128];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(PlayerInfo[playerid][pAdmin] < 4) return SendClientMessage(playerid, COLOR_GREY, "You are not authorized to use this command.");
    if(sscanf(params, "ui", playerb, amount)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /setmoney [playerid] [amount]");
    if(!IsPlayerLoggedIn(playerb)) return SendClientMessage(playerid, COLOR_GREY, "Invalid player id.");
    PlayerInfo[playerb][pMoney] = amount;
    SetZaiatMoney(playerb, amount);
    format(string, sizeof(string), " Administrator %s has set your money to $%d", RPN(playerid), amount);
    SendClientMessage(playerb, COLOR_WHITE, string);
    format(string, sizeof(string), "AdmWarn: %s has set %s's money to $%d.", RPN(playerid), RPN(playerb), amount);
    SendAdminMessage(COLOR_DARKRED, 1, string);
    Log("logs/setmoney.log", string);
    OnPlayerSave(playerb);
    return 1;
}







Re: Money bug ( GTA ) - Konstantinos - 06.07.2013

Can you explain what is wrong with it? Also make sure that GiveZaiatMoney adds the money to the variable, I assume it's server-side money.


Re : Money bug ( GTA ) - morocco - 06.07.2013

Fix !

Old
pawn Код:
stock GiveZaiatMoney(playerid, amount)
{
    new string[128];
    if(amount < 0) format(string, sizeof(string), "~r~-$%d", amount*-1);
    else if(amount > 0) format(string, sizeof(string), "~g~+$%d", amount);
    GameTextForPlayer(playerid, string, 3000, 1);
    PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
    return 1;
}
New
pawn Код:
stock GiveZaiatMoney(playerid, amount)
{
    new string[128];
    if(amount < 0) format(string, sizeof(string), "~r~-$%d", amount*-1);
    else if(amount > 0) format(string, sizeof(string), "~g~+$%d", amount);
    GameTextForPlayer(playerid, string, 3000, 1);
    PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
    PlayerInfo[playerid][pMoney] = PlayerInfo[playerid][pMoney]+amount;
    GivePlayerMoney(playerid,amount);
    return 1;
}



Re: Money bug ( GTA ) - Konstantinos - 06.07.2013

Nice! Make sure that SetZaiatMoney function sets the value to the PlayerInfo[playerid][pMoney] too.

Off-topic: you can also use
pawn Код:
PlayerInfo[playerid][pMoney] += amount;
// instead of
PlayerInfo[playerid][pMoney] = PlayerInfo[playerid][pMoney]+amount;