Reseting money when I dont want It to! - Help
#6

sure I would give you an example of how to use it
I guess you have player enum something like PlayerInfo[playerid][variablehere]

here you can do this on commands, explanation is given in the code
and I am assuming you know how to use sscanf

pawn Код:
COMMAND:givemoney(playerid, params[])
{
    new amount;
    new receiverid;
    new Float:x, Float:y, Float:z;
    GetPlayerPos(playerid, x, y, z);
    if(sscanf(params, "ui", receiverid, amount)) return SendClientMessage(playerid, -1, "Usage: /givemoney [id] [amount]");
    if(!IsPlayerConnected(receiverid)) return SendClientMessage(playerid, -1, "Player is Not Connected");
    if(!IsPlayerInRangeOfPoint(receiverid, 5, x, y, z)) return SendClientMessage(playerid, -1, "You are not near that player");
    if(PlayerInfo[playerid][pMoney] < amount)/*If money in player variable is less than the amount he entered */ return SendClientMessage(playerid, -1, "You don't have that much money");
    // now if all the above requirements are met
    new string1[128];
    new string2[128];
    PlayerInfo[playerid][pMoney] = PlayerInfo[playerid][pMoney] - amount; // it deducts the amount from the variable
    PlayerInfo[receiverid][pMoney] = PlayerInfo[receiverid][pMoney] + amount // it adds the amount to the one who received the money
    ResetPlayerMoney(playerid);
    ResetPlayerMoney(receiverid); // Reset the money of both guys
    GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney);
    GivePlayerMoney(receiverid, PlayerInfo[receiverid][pMoney]); //this sets the money of both guys according to their variable
    return 1;
}

public OnPlayerUpdate(playerid) // now on player update
{
    if(GetPlayerMoney(playerid) > PlayerInfo[playerid][pMoney]) // if the money is greater than the variable, which is most likely to happen if someone hacks
    {
        ResetPlayerMoney(playerid);
        GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]); // This sets back the money according to their variable
        // now the upcoming thing is if you want to inform admins
        for(new i = 0; i < MAX_PLAYERS; i++) //this is loop, hope you know about it
        {
            if(PlayerInfo[i][pAdmin] > 0) // if Player Admin level is greater than 0
            {
                new string[128];
                new name[24];
                GetPlayerName(playerid, name, 24);
                format(string, sizeof(string), "%s is Money Hacking..!! ID: %i", name, playerid);
                SendClientMessage(playerid, -1, string); // sends the message to admins , so they can handle it
                return 1;
            }
        }
    }


    return 1;
}
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)