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

Hi guys,

I'm building a server using Vortex Role play as my base. Most things are saved onto my MYSQL Server on localhost. It doesn't include a fuel system. So im using a filter script for a fuel system I found on the forums. It's a good fuel system but when It's supposed to charge the player money, It does it, then resets back to what it was.

Im not 100% sure why this is happening but If I had to make a guess I'd say it was something to do with the Anti-Money hack code that is in the game mode.

Vortex Roleplay Gamemode - https://sampforum.blast.hk/showthread.php?tid=252612&page=1

A snippet of code from the filter script fuel system im using, where it charges the money:

Код:
command(refuel, playerid, params[])
{
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_YELLOW, "You to be inside an vehicle to refuel it.");
    	if(GetPlayerMoney(playerid) < 250) return SendClientMessage(playerid, COLOR_YELLOW, "You do not have enough money to refuel your vehicle.");
        Carinfo[GetPlayerVehicleID(playerid)][Fuel] = MAX_FUEL;
        KillTimer(FuelTimer[playerid]);
        ToggleVehicleEngine(GetPlayerVehicleID(playerid), true);
        FuelTimer[playerid] = SetTimerEx("FuelDown", 1000, true, "i", playerid); // Fueldown timer
        GivePlayerMoney(playerid, -250);
        SendClientMessage(playerid, COLOR_YELLOW, "You refueled your vehicle.");
        return 1;
}
If you need the full fuel system script please just ask and ill put it on paste bin.

Thanks for your help.
Reply
#2

Vortex uses a server-side money system. You have to update playerVariables[playerid][pMoney] when you change a player's money.
Reply
#3

Right I see, I did try that but I got a huge amount of errors, I probably did it wrong as Im new to this.

Any suggestions on how you'd go about updating playerVariables[playerid][pMoney] ?

Thanks for your help.
Reply
#4

What I do is

On each command, or system which gives player money, I ResetPlayerMoney, update the Player Variable, and then use GivePlayerMoney(playerid, PlayerVariable[playerid][pMoney]); so they get money according to their variable

and, OnPlayerUpdate, I check that the money is not greater than the variable , if its greater than the variable, then ResetPlayerMoney and GivePlayerMoney(just as above) and Send a message to admin about Player trying to hack
Reply
#5

That sounds like a good suggestion, thanks for your help.

I am pretty new to all this though and that sounds a bit complex for the level im at right now.

Do you think you could show me how to do it? On the command in question ^^^^.
Reply
#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
#7

Sorry but im totally confused now! :P

I'm really new to this stuff and I just need to know what to do to make the command I stuck in the first post not reset my cash. Could you explain step by step what I need to do? I have very little knowledge on this.

Sorry to be a pain in the ar*e!

Much appreciate your help
Reply
#8

Код:
//********************* [ Credits ] ******************************************//
/*

                                Car Fuel Script by Cameltoe
                                        Version 1.3

                I do not demand to keep the credits but it is appreciated.

*/
//******************** [ Includes ] ******************************************//
#include <a_samp>
#include <zcmd>

//******************** [ Forwards ] ******************************************//
forward FuelDown(playerid);

//******************** [ Defines ] ******************************************//

// Vehicles

#undef MAX_VEHICLES
#define MAX_VEHICLES 	250

// Fuel

#define MAX_FUEL 		100
#define FUEL_DECREASE 	1

// Colors
#define COLOR_RED		0xFF000000
#define COLOR_YELLOW	0xFFFF0000
#define COLOR_BLUE		0x0000FF00
#define COLOR_GREEN		0x00FF0000

//******************** [ Enums ] *********************************************//
enum Car
{
        Float:Fuel,
}
//******************** [ Symbols ] *******************************************//
new Carinfo[MAX_VEHICLES][Car];
new Text:FuelText[MAX_PLAYERS];
new FuelTimer[MAX_PLAYERS];

//******************** [ Callbakcs ] *****************************************//

public OnFilterScriptInit()
{
        printf("________Fuel System Loaded___________");


        for(new vehicleid; vehicleid < MAX_VEHICLES; vehicleid++)
        {
                Carinfo[vehicleid][Fuel] = MAX_FUEL;
        }
        return 1;
}


public OnPlayerConnect(playerid)
{
        FuelText[playerid] = TextDrawCreate(450.0, 405.0,"         ");
        TextDrawHideForPlayer(playerid,FuelText[playerid]);
        TextDrawAlignment(FuelText[playerid],0);
        TextDrawSetProportional(FuelText[playerid],1);
        TextDrawSetShadow(FuelText[playerid], 1);
        TextDrawSetOutline(FuelText[playerid], 2);
        TextDrawLetterSize(FuelText[playerid],0.60,2.0);
        TextDrawFont(FuelText[playerid], 3);
        return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    TextDrawDestroy(FuelText[playerid]);
        return 1;
}


public OnPlayerStateChange(playerid,newstate,oldstate)
{
        new string[128];
        if(newstate == PLAYER_STATE_DRIVER)
        {
            if(floatround(Carinfo[GetPlayerVehicleID(playerid)][Fuel]) <= 0)
                {
                        format(string,sizeof(string),"~g~ Fuel: ~w~ 0");
                        SendClientMessage(playerid, COLOR_RED, "This vehicle has ran out of fuel");
                        KillTimer(FuelTimer[playerid]);
                        ToggleVehicleEngine(GetPlayerVehicleID(playerid), false);
                        TextDrawSetString(FuelText[playerid], string);
                }
                else
                {
                        FuelTimer[playerid] = SetTimerEx("FuelDown", 1000, true, "i", playerid); // Fueldown timer
                        TextDrawShowForPlayer(playerid, FuelText[playerid]);
                }
        }
        else
        {
                TextDrawHideForPlayer(playerid,FuelText[playerid]);
                TextDrawSetString(FuelText[playerid], "         ");
        }
        return 1;
}

public OnPlayerCommandText(playerid, cmdtext[])
{
        return 0;
}

//******************** [ Functions ] ********************************************//
public FuelDown(playerid)
{
        new string[128];
        new vehicleid = GetPlayerVehicleID(playerid);
        if(IsPlayerInAnyVehicle(playerid))
        {
                if(floatround(Carinfo[vehicleid][Fuel]) <= 0 || Carinfo[vehicleid][Fuel] - GetPlayerSpeed(playerid) * FUEL_DECREASE / 100 < 0)
                {
                        format(string,sizeof(string),"~g~ Fuel: ~w~ 0");
                        SendClientMessage(playerid, COLOR_RED, "This vehicle has ran out of fuel");
                        KillTimer(FuelTimer[playerid]);
                        ToggleVehicleEngine(vehicleid, false);
                        TextDrawSetString(FuelText[playerid], string);
                }
                else
                {
                        Carinfo[vehicleid][Fuel] = Carinfo[vehicleid][Fuel] - GetPlayerSpeed(playerid) * FUEL_DECREASE / 100;
                        format(string,sizeof(string),"~g~ Fuel: ~w~ %d", floatround(Carinfo[vehicleid][Fuel]));
                        TextDrawSetString(FuelText[playerid], string);
                }
        }
        else
        {
                format(string,sizeof(string),"~g~ Fuel: ~w~ ");
                KillTimer(FuelTimer[playerid]);
        }
}

//******************** [ Stocks ] ********************************************//

stock ToggleVehicleEngine(vehicleid, bool: Mode)
{
    new engine,lights,alarm,doors,bonnet,boot,objective;
    GetVehicleParamsEx(vehicleid,engine,lights,alarm,doors,bonnet,boot,objective);
    if(Mode == false) SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_OFF, lights, alarm, doors, bonnet, boot, objective);
    else SetVehicleParamsEx(vehicleid, VEHICLE_PARAMS_ON, lights, alarm, doors, bonnet, boot, objective);
}

stock GetPlayerSpeed(playerid)
{
        new Float:ST[4];
        if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]); else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
        ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 180;
        return floatround(ST[3]);
}

//******************** [ Commands ] ******************************************//



command(refuel, playerid, params[])
{
        if(!IsPlayerInAnyVehicle(playerid)) return SendClientMessage(playerid, COLOR_YELLOW, "You to be inside an vehicle to refuel it.");
    	if(GetPlayerMoney(playerid) < 250) return SendClientMessage(playerid, COLOR_YELLOW, "You do not have enough money to refuel your vehicle.");
        Carinfo[GetPlayerVehicleID(playerid)][Fuel] = MAX_FUEL;
        KillTimer(FuelTimer[playerid]);
        ToggleVehicleEngine(GetPlayerVehicleID(playerid), true);
        FuelTimer[playerid] = SetTimerEx("FuelDown", 1000, true, "i", playerid); // Fueldown timer
        GivePlayerMoney(playerid, -250);
        SendClientMessage(playerid, COLOR_YELLOW, "You refueled your vehicle.");
        return 1;
}
Thats my entire fuel filter script if it helps!

Reply
#9

Re-reading over your reply, I found this in the actual game mode:

Код:
			playerVariables[playerid][pMoney] -= 500;
I tried using that in the command but It gave me errors.
Reply
#10

I am too tired currently, its 1 AM here,,,,
I will post the step by step explanation tomorrow in this comment
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)