fuel crashing me..
#1

hey i made this fuel system awhile ago and after i made the fuel decrease after the faster you go it started crashing

pawn Код:
--------------------------

SA-MP Server: 0.3a R8



Exception At Address: 0x00482DA4



Registers:

EAX: 0x00000000 EBX: 0x00000400 ECX: 0x00000100 EDX: 0x7EFEFEFF

ESI: 0x00000000 EDI: 0x00F50E20 EBP: 0x0000006C ESP: 0x0012FD78

EFLAGS: 0x00010206



Stack:

+0000: 0x01480020   0x00EDBAA8   0x00F50E20   0x004743BB

+0010: 0x00F50E20   0x00000000   0x00000400   0x00C9C4F0

+0020: 0x00000000   0x0012FDD0   0x00F35A80   0x0000006C

+0030: 0x0046596E   0x438E8000   0x43D78000   0x00000000

+0040: 0x00C9C4F0   0x00F2DBDC   0x00003230   0x01480020

+0050: 0x00000000   0x00F35AA4   0x00F2CAAC   0x00402C20

+0060: 0x00C9C4F0   0x00F35A80   0x00F04B60   0x00000000

+0070: 0x00000000   0x00C9C4F0   0x00003230   0x00003220

+0080: 0x00007EA4   0x000080DC   0x000040E0   0x000080D0

+0090: 0x000040E0   0x00F2AE74   0x00F2DBDC   0x004493F2

+00A0: 0x00F2A938   0x00002D68   0x0046DE4A   0x00C9C4F0

+00B0: 0x0012FE50   0x00000000   0x00AB7900   0x7C802442

+00C0: 0x3C436CB5   0x00AB6F68   0x00F04B60   0x00000000

+00D0: 0x00AB6F68   0x00F491C8   0x00AB7900   0x0047C944

+00E0: 0x0000000B   0x7C802520   0x7C80A027   0x00000000

+00F0: 0x3C436CB5   0x0047931C   0x00000000   0x00000A28

+0100: 0x0012FFC0   0x7FFDD000   0x000193C2   0x00010101

+0110: 0x00000034   0x00001E61   0x00000070   0x000004C0

+0120: 0x00AB7900   0x656D6167   0x65646F6D   0x00003531

+0130: 0x004A8014   0x004A8010   0x7FFDD000   0x00493660
http://pastebin.com/dpMGTdBv
Reply
#2

It might be that line:

format(String,sizeof(String),"~r~Fuel~g~:~p~%d ~r~MPH~g~:~p~%i",CarFuel[vehicle], floatround(floatdiv(Speed, 1.609344), floatround_floor), floatround(Speed, floatround_floor));

You have 3 parameters, but only two replacers. So format does not know where to put the last one and crashes the server.
Reply
#3

how can i fix this

it had 3 when it was using mph only
Reply
#4

You could just remove the the last one:

format(String,sizeof(String),"~r~Fuel~g~:~p~%d ~r~MPH~g~:~p~%i",CarFuel[vehicle], floatround(floatdiv(Speed, 1.609344), floatround_floor));

But if Im right, you want to show both MPH and KMH, then you need to add the KMH to the string like this:

format(String,sizeof(String),"~r~Fuel~g~:~p~%d ~r~MPH~g~:~p~%i ~r~KMH~g~:~p~%i",CarFuel[vehicle], floatround(floatdiv(Speed, 1.609344), floatround_floor), floatround(Speed, floatround_floor));
Reply
#5

crashing still>>< could it be the getplayeraspeed? cus after i made it decrease the faster u go thats when it starts crashing

]edit] it crashed after 5 seconds in vehicle thats when fueldecrease is called
Reply
#6

Hmm, maybe GetPlayerSpeed has to be public, because its called within a timerfunction, but Im not sure about this. Would be the only thing I see atm.
Reply
#7

ah ha i found the problem! its diff now if i go to fast i crash

could it be that it cannot decrease fuel by points? as in 1.3 maybe that part is crashing it i dont want to use a float in the fuel i dont want it to show point decimals(40.3) e.g

pawn Код:
#include <a_samp>
#include <zcmd>
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define RED 0xFF0000FF
#define     LIME 0x00FF00FF
forward CheckStatus();
forward Fueldecrease();
forward IsAtFuelStation(playerid);
forward ReFill(playerid);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Booleans
new bool:TextDrawsShown[MAX_PLAYERS];
new bool:VHSCreated[MAX_PLAYERS];
new CarFuel[MAX_VEHICLES] = 0;
//Timer
new CheckStatusTimer;
new FuelDecrease;
new ReFuelTimer;

//4all
new Text:Black0;
new Text:Black1;
new Text:Black2;
new Text:Black3;
new Text:LightBlack;
//4player
new Text:VHS[MAX_PLAYERS];
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public OnFilterScriptInit()
{
    CheckStatusTimer = SetTimer("CheckStatus", 900, 1);
    FuelDecrease = SetTimer("Fueldecrease", 5000, 1);
    for(new v = 0; v < MAX_VEHICLES; v++)
    {
            new randfuel = minrand(25,100);
            CarFuel[v] = randfuel; // This sets the fuel
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public OnFilterScriptExit()
{
    KillTimer(CheckStatusTimer);
    KillTimer(FuelDecrease);
    TextDrawDestroy(Text:Black0);
    TextDrawDestroy(Text:Black1);
    TextDrawDestroy(Text:Black2);
    TextDrawDestroy(Text:Black3);
    TextDrawDestroy(Text:LightBlack);
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        TextDrawDestroy(Text:VHS[i]);
    }
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

public OnVehicleSpawn(vehicleid)
{
        CarFuel[vehicleid] = minrand(25,100);
        return 1;
}

public OnPlayerConnect(playerid)
{
    TextDrawsShown[playerid] = false;
    VHSCreated[playerid] = false;
}
stock minrand(min, max) //By Alex "******" Cole
{
    return random(max-min)+min;
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
CMD:refuel(playerid,params[])
{
    if(IsPlayerConnected(playerid) && IsPlayerInAnyVehicle(playerid))
    {
        if(IsAtFuelStation(playerid) && GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
        {
            new vehicle = GetPlayerVehicleID(playerid);
            if(CarFuel[vehicle] >= 100)
            {
                SendClientMessage(playerid,RED,".::Error:Your Gas Tank Is Already Full");
            }
            else
            {
                SendClientMessage(playerid,LIME,"Your Gas Is Being ReFueled Right Now! Please Wait");
                ReFuelTimer = SetTimerEx("ReFill", 800, true, "i", playerid);
            }
        }
        else
        {
        SendClientMessage(playerid,RED,".::Error: You Must Be At A Gas Station To Refuel Your Vehicle");
        }
    }
    else
    {
        SendClientMessage(playerid,RED,".::Error: You must Be In A Vehicle To Refuel It Idiot");
    }
    return true;
}

public ReFill(playerid)
{
    new Float:x, Float:y, Float:z;
    new vehicle = GetPlayerVehicleID(playerid);
    if(GetPlayerPos(playerid, x, y, z) != IsAtFuelStation(playerid) || CarFuel[vehicle] >= 100)
    {
        StopRefueling(playerid);
    }
    else
    {
        CarFuel[vehicle] ++;
    }
    return true;
}

stock StopRefueling(playerid)
{
    GivePlayerMoney(playerid, -300);
    SendClientMessage(playerid, LIME,".::FUEL:Your Gas Tank Has Been Filled Up For $300");
    KillTimer(ReFuelTimer);
    return true;
}

public Fueldecrease()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInAnyVehicle(i))
            {
                new vehicle = GetPlayerVehicleID(i);
                new Float:speed;
                speed = GetPlayerSpeed(i, false);
                if(CarFuel[vehicle] >= 1 && CarFuel[vehicle] <= 100)
                {
                    if(speed >= 1 && speed <= 70)
                    {
                        CarFuel[vehicle] -= 1;
                    }
                    if(speed >= 71 && speed <= 130)
                    {
                        CarFuel[vehicle] -= 1.5;
                    }
                    if(speed >= 131 && speed <= 170)
                    {
                        CarFuel[vehicle] -= 1.8;
                    }
                    if(speed >= 171)
                    {
                        CarFuel[vehicle] -= 2.0;
                    }
                }
            }
        }
    }
    return 1;
}


public CheckStatus()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
        if(IsPlayerConnected(i))
        {
            if(IsPlayerInAnyVehicle(i))
            {

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                if(TextDrawsShown[i] == false)
                {
                    TextDrawsShown[i] = true;
                }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                new vehicle = GetPlayerVehicleID(i);
                new String[128];
                new Float:X, Float:Y, Float:Z, Float:Speed;
                GetVehicleVelocity(GetPlayerVehicleID(i), X, Y, Z);
                Speed = floatmul(floatsqroot(floatadd(floatadd(floatpower(X, 2), floatpower(Y, 2)),  floatpower(Z, 2))), 200.0); //100.0
                if(CarFuel[vehicle] >= 1 && CarFuel[vehicle] <= 100)
                {
                    format(String,sizeof(String),"~r~Fuel~g~:~p~%d ~r~MPH~g~:~p~%i ~r~KMH~g~:~p~%i",CarFuel[vehicle], floatround(floatdiv(Speed, 1.609344), floatround_floor), floatround(Speed, floatround_floor));
                }
                if(CarFuel[vehicle] == 0)
                {
                    CarFuel[vehicle] = 0;
                    CarFuel[vehicle] --;
                    RemovePlayerFromVehicle(i);
                    GameTextForPlayer(i,"~r~No Fuel In Vehicle",4000,3);
                }
                if(CarFuel[vehicle] == 25)
                {
                    GameTextForPlayer(i,"~r~Warning Low Fuel",4000,3);
                }
                if(CarFuel[vehicle] == 20)
                {
                    GameTextForPlayer(i,"~r~Warning Low Fuel",4000,3);
                }
                if(CarFuel[vehicle] == 15)
                {
                    GameTextForPlayer(i,"~r~Warning Low Fuel",4000,3);
                }
                if(CarFuel[vehicle] == 10)
                {
                    GameTextForPlayer(i,"~r~Warning Low Fuel",4000,3);
                }
                if(CarFuel[vehicle] == 5)
                {
                    GameTextForPlayer(i,"~r~Warning Low Fuel",4000,3);
                }
                if(VHSCreated[i] == true)
                {
                    TextDrawDestroy(VHS[i]);
                }
               
                VHS[i] = TextDrawCreate(285.000000, 431.000000, String);
                TextDrawAlignment(VHS[i], 2);
                TextDrawBackgroundColor(VHS[i], 255);
                TextDrawFont(VHS[i], 2);
                TextDrawLetterSize(VHS[i], 0.360000, 1.000000);
                TextDrawColor(VHS[i], -1);
                TextDrawSetOutline(VHS[i], 1);
                TextDrawSetProportional(VHS[i], 1);
                TextDrawShowForPlayer(i, VHS[i]);
               
                VHSCreated[i] = true;

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            }
            else
            {
                if(TextDrawsShown[i] == true)
                {
                    TextDrawHideForPlayer(i, Text:Black0);
                    TextDrawHideForPlayer(i, Text:Black1);
                    TextDrawHideForPlayer(i, Text:Black2);
                    TextDrawHideForPlayer(i, Text:Black3);
                    TextDrawHideForPlayer(i, Text:LightBlack);
                    TextDrawsShown[i] = false;
                }
                TextDrawHideForPlayer(i, Text:VHS[i]);
            }
        }
    }
}

stock GetPlayerSpeed(playerid,bool:kmh)
{
  new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
  if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
  rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
  return kmh?floatround(rtn * 100 * 1.61):floatround(rtn * 100);
}

public IsAtFuelStation(playerid)
{
    if(PlayerToPoint(10,playerid,1595.5406, 2198.0520, 10.3863) || PlayerToPoint(10,playerid,2202.0649, 2472.6697, 10.5677) ||
    PlayerToPoint(10,playerid,2115.1929, 919.9908, 10.5266) || PlayerToPoint(10,playerid,2640.7209, 1105.9565, 10.5274) ||
    PlayerToPoint(10,playerid,608.5971, 1699.6238, 6.9922) || PlayerToPoint(10,playerid,618.4878, 1684.5792, 6.9922) ||
    PlayerToPoint(10,playerid,2146.3467, 2748.2893, 10.5245) || PlayerToPoint(10,playerid,-1679.4595, 412.5129, 6.9973) ||
    PlayerToPoint(10,playerid,-1327.5607, 2677.4316, 49.8093) || PlayerToPoint(10,playerid,-1470.0050, 1863.2375, 32.3521) ||
    PlayerToPoint(10,playerid,-2409.2200, 976.2798, 45.2969) || PlayerToPoint(10,playerid,-2244.1396, -2560.5833, 31.9219) ||
    PlayerToPoint(10,playerid,-1606.0544, -2714.3083, 48.5335) || PlayerToPoint(10,playerid,1937.4293, -1773.1865, 13.3828) ||
    PlayerToPoint(10,playerid,-91.3854, -1169.9175, 2.4213) || PlayerToPoint(10,playerid,1383.4221, 462.5385, 20.1506) ||
    PlayerToPoint(10,playerid,660.4590, -565.0394, 16.3359) || PlayerToPoint(10,playerid,1381.7206, 459.1907, 20.3452) ||
    PlayerToPoint(10,playerid,-1605.7156, -2714.4573, 48.5335))
    { return true; }
    return false;
}

stock PlayerToPoint(Float:radi, playerid, Float:x, Float:y, Float:z)
{
    new Float:oldposx, Float:oldposy, Float:oldposz;
    new Float:tempposx, Float:tempposy, Float:tempposz;
    GetPlayerPos(playerid, oldposx, oldposy, oldposz);
    tempposx = (oldposx -x);
    tempposy = (oldposy -y);
    tempposz = (oldposz -z);
    if (((tempposx < radi) && (tempposx > -radi)) && ((tempposy < radi) && (tempposy > -radi)) && ((tempposz < radi) && (tempposz > -radi)))
    {
        return 1;
    }
    return 0;
}

//EOF/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Reply
#8

you can try it without the decimals... maybe it will work. OR (dunno for sure) try it with 1,5 instead of 1.5
Reply
#9

warning 215: expression has no effect
Pawn compiler 3.2.3664 Copyright © 1997-2006, ITB CompuPhase
Reply
#10

Код:
new CarFuel[MAX_VEHICLES]; // no need for initialising
Also, it should be a float.
Код:
new Float:CarFuel[MAX_VEHICLES];
because are not decreasing whole numbers but decimals in your "Fueldecrease" callback.

Either decrease whole numbers, or use float and while printing :
Код:
format(String,sizeof(String),"~r~Fuel~g~:~p~%0.2f ~r~MPH~g~:~p~%i ~r~KMH~g~:~p~%i",CarFuel[vehicle], floatround(floatdiv(Speed, 1.609344), floatround_floor), floatround(Speed, floatround_floor));
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)