Reseting money when I dont want It to! - Help
#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


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)