GivePlayerCash - On Mod garages.
#1

Hello I'm using the stock Giveplayercash as server side money to prevent hacking, well trouble is :

When players mod the cars in the mod garages, it will still be using the standard giveplayermoney and the money is taken and given back to the player... well any ideas on how to get the mod garages using the Callback - GivePlayerCash ? i been trying for a while and no luck so far help is very appreciated and thanks in advance.

Best regards,

Charlie Sanchez.
Reply
#2

I would use OnEnterExitModShop callback so I can toggle to a variable whether the player is in the mod shop or not.

Then in a global timer (5 seconds for example), I'd loop through the players (using foreach - since it loops through connected players only) and reset their money, then give the registered money back. Before doing so, a simple check about if the player's money (from GetPlayerMoney) are lesser than the registered one and if the variable is 1 (that the player is in the mod shop) so then you set the registered money as the money GetPlayerMoney returned.

An example:
pawn Код:
static
    bool: Player_ModShop[MAX_PLAYERS char],
    Player_Money[MAX_PLAYERS],
       
    Timer_Money = -1;

// On(GameMode/FilterScript)Init:
Timer_Money = SetTimer("OnMoneyUpdate", 5000, true);

// On(GameMode/FilterScript)Exit:
KillTimer(Timer_Money);

// OnPlayerConnect:
Player_ModShop{playerid} = false;
Player_Money[playerid] = 0;

// on logging, set the registered money to "Player_Money[playerid]"

// OnEnterExitModShop:
Player_ModShop{playerid} = !!enterexit;

forward OnMoneyUpdate();
public OnMoneyUpdate()
{
    new
        money;
       
    foreach(new i : Player)
    {
        if ((money = GetPlayerMoney(i)) < Player_Money[i] && Player_ModShop{i}) Player_Money[i] = money;
        ResetPlayerMoney(i);
        GivePlayerMoney(i, Player_Money[i]);
    }
}
EDIT: It seems that everything works fine except one thing. If you have for example $150 and you try to buy a colour which costs $150, then it doesn't remove the money and it gives you that money back. But if you have more than that, then it works fine. If you have less than that, it returns the error message.
Reply
#3

Ok, i getting the idea indeed but i am a bit confused cause i already have timers set for the money update let me post the code bellow:
Код:
#define ResetMoneyBar ResetPlayerMoney
#define UpdateMoneyBar GivePlayerMoney

new Cash[MAX_PLAYERS];

forward MoneyTimer(playerid); // For Server Side money protection

//ongamemodeinit...
SetTimer("MoneyTimer", 1000, 1);


public MoneyTimer()
{
    new username[MAX_PLAYER_NAME];
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(GetPlayerCash(i) != GetPlayerMoney(i))
            {
                ResetMoneyBar(i);//Resets the money in the original moneybar, Do not remove!
                UpdateMoneyBar(i,GetPlayerCash(i));//Sets the money in the moneybar to the serverside cash, Do not remove!
                new hack = GetPlayerMoney(i) - GetPlayerCash(i);
                GetPlayerName(i,username,sizeof(username));
                printf("%s has picked up/attempted to spawn $%d.", username,hack);
            }
        }
    }
}



//------ Server Side money Protection Stock -----//
//---------------------------------------------------------------------------------------------------------//
stock GivePlayerCash(playerid, money)
{
    Cash[playerid] += money;
    ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
    UpdateMoneyBar(playerid,Cash[playerid]);//Sets the money in the moneybar to the serverside cash, Do not remove!
    return Cash[playerid];
}
stock SetPlayerCash(playerid, money)
{
    Cash[playerid] = money;
    ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
    UpdateMoneyBar(playerid,Cash[playerid]);//Sets the money in the moneybar to the serverside cash, Do not remove!
    return Cash[playerid];
}
stock ResetPlayerCash(playerid)
{
    Cash[playerid] = 0;
    ResetMoneyBar(playerid);//Resets the money in the original moneybar, Do not remove!
    UpdateMoneyBar(playerid,Cash[playerid]);//Sets the money in the moneybar to the serverside cash, Do not remove!
    return Cash[playerid];
}
stock GetPlayerCash(playerid)
{
    return Cash[playerid];
}
However i just read your EDIT: and going to try your code bud im happy with that color money thing lets hope the rest works hehe and thanks ill post the result..
Reply
#4

Only use the array for the mod shop, the rest was just an example. I'll suggest you to use foreach so it loops through the connected players only.

pawn Код:
public MoneyTimer()
{
    new username[MAX_PLAYER_NAME], money;
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            money = GetPlayerMoney(i);
            if(GetPlayerCash(i) != money)
            {
                if (money < Cash[i] && Player_ModShop{i}) Cash[i] = money;
                ResetMoneyBar(i);//Resets the money in the original moneybar, Do not remove!
                UpdateMoneyBar(i,GetPlayerCash(i));//Sets the money in the moneybar to the serverside cash, Do not remove!
                new hack = money - GetPlayerCash(i);
                GetPlayerName(i,username,sizeof(username));
                printf("%s has picked up/attempted to spawn $%d.", username,hack);
            }
        }
    }
}
Reply
#5

Alright going to try it and yes using foreach, crossing fingers here hehe ill post the results and thanks for responding so fast buddy cheers !

PS - Don't know if matters or not but gave you some rep for helping me ! Thank you.
Reply
#6

Right Success !! works perfect spot on bud thanks,
I still get the printf warning lol but it's ok.
and here is the code i implemented:

Код:
new Player_ModShop[MAX_PLAYERS];
public MoneyTimer()
{
    new username[MAX_PLAYER_NAME], money;
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            money = GetPlayerMoney(i);
            if(GetPlayerCash(i) != money)
            {
                if (money < Cash[i] && Player_ModShop{i}) Cash[i] = money;
                ResetMoneyBar(i);//Resets the money in the original moneybar, Do not remove!
                UpdateMoneyBar(i,GetPlayerCash(i));//Sets the money in the moneybar to the serverside cash, Do not remove!
                new hack = money - GetPlayerCash(i);
                GetPlayerName(i,username,sizeof(username));
                printf("%s has picked up/attempted to spawn $%d.", username,hack);
            }
        }
    }
}


public OnEnterExitModShop(playerid, enterexit, interiorid)
{
    Player_ModShop{playerid} = !!enterexit;
    return 1;
}
Reply
#7

You get the message in the console/server log because you check if the registered money are not the same as the amount GetPlayerMoney returns. So check if the money is more than the registered money and then print the message:
pawn Код:
if (money > GetPlayerCash(i))
{
    GetPlayerName(i,username,sizeof(username));
    printf("%s has picked up/attempted to spawn $%d.", username, money - GetPlayerCash(i));
}
Reply
#8

Got it Working 100% perfect ! Thank you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)