Speedometer not working. (Screenshots)
#1

I've debugged for days and days and now I can't figure out why it won't display.

What the speedometer should look like.



What it looks like now.


CODE:
Creation of the text.
pawn Код:
forward SpeedoUpdate(playerid);
forward FuelUpdate(playerid);
new Text:speed[MAX_PLAYERS],Text:fuel[MAX_PLAYERS];
Creation of the textdraw. (When the player logs in, it is created.)
pawn Код:
speed[playerid] = TextDrawCreate(478,389,"_");
                TextDrawLetterSize(speed[playerid],0.37,2.0);
                TextDrawSetOutline(speed[playerid],1);
                TextDrawFont(speed[playerid], 2);
                fuel[playerid] = TextDrawCreate(478,413,"_");
                TextDrawLetterSize(fuel[playerid],0.37,2.0);
                TextDrawSetOutline(fuel[playerid],1);
                TextDrawFont(fuel[playerid], 2);
Engine on command.
pawn Код:
CMD:eon(playerid, params[])
{
    if(LoggedIn[playerid] == 0)return SendClientMessage(playerid, COLOUR_GREY, "You must be logged in to use this command.");
    if(IsRefuelling[playerid] == 1)return SendClientMessage(playerid, COLOUR_GREY, "You may not turn your engine on as you are refuelling.");
    printf("checks if refueling");
    new string[128];
    new vehicleid = GetPlayerVehicleID(playerid);
    new name = GetVehicleModel(vehicleid) - 400;
    if(GetPlayerState(playerid) != PLAYER_STATE_DRIVER)return SendClientMessage(playerid, COLOUR_GREY, "You are not the driver.");
    printf("checks player state");
    if(EngineStartStatus[vehicleid] == 1)return SendClientMessage(playerid, COLOUR_GREY, "The engine is already on.");
    printf("checks engine");
    if(!IsPlayerInAnyVehicle(playerid))return SendClientMessage(playerid, COLOUR_GREY, "You are not in a vehicle.");
    printf("checks if in vehicle.");

    //KillTimer(SpeedoSysTimer[playerid]);
    printf("kills speedo");
    //KillTimer(FuelSysTimer[playerid]);

   

    printf("shows fuel");
    TextDrawDestroy(enginestring);

    SpeedoSysTimer[playerid] = SetTimerEx("SpeedoUpdate", 300, true, "i", playerid);
    printf("speedotimer");
    FuelSysTimer[playerid] = SetTimerEx("FuelUpdate", 30000, true, "i", playerid);
    SetTimer("FuelSave", 4000, 1);
    TextDrawShowForPlayer(playerid,speed[playerid]);
    TextDrawShowForPlayer(playerid,fuel[playerid]);
   
    if(VehFuel[vehicleid] > 0)
    {
        EngineStartStatus[vehicleid] = 1;
        GameTextForPlayer(playerid, "~g~Engine starting...", 2500, 5);
        SetTimerEx("EngineOn", 3000, false, "i", playerid);
        format(string, sizeof(string), "* %s turns the %s's ignition key...", GetNameEx(playerid), VehicleNames[name]);
        ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
    }
    else if(VehFuel[vehicleid] == 0)
    {
        EngineStartStatus[vehicleid] = 0;
        SendClientMessage(playerid, COLOUR_REALRED, "Your vehicle is out of fuel..");
        format(string, sizeof(string), "* The %s has run out of fuel and failed to start.", VehicleNames[name]);
        ProxDetector(30.0, playerid, string, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE, COLOUR_PURPLE);
    }
    return 1;
}
The SpeedoUpdate (formats the string for the textdraw).
pawn Код:
public SpeedoUpdate(playerid)
{
        if(IsPlayerInAnyVehicle(playerid))
        {
            new Float:x,Float:y,Float:z,string[24],vehicleid = GetPlayerVehicleID(playerid);
            GetVehicleVelocity(vehicleid,x,y,z);
            format(string,sizeof(string),"~g~Speed: ~w~%d mph",floatround(floatsqroot(((x*x)+(y*y))+(z*z))*156.666667*0.641371192));
            TextDrawSetString(speed[playerid],string);
            format(string,sizeof(string),"~g~Fuel: ~w~%d%%",VehFuel[vehicleid]);
            TextDrawSetString(fuel[playerid],string);
            TextDrawShowForPlayer(playerid,fuel[playerid]);
            TextDrawShowForPlayer(playerid,speed[playerid]);
    }
}
If someone can assist in any way possible, I'd appreciate it.
Reply
#2

Bump.
Reply
#3

Try debugging it in public SpeedoUpdate(playerid) (assuming that Fuel TD is updated succesfully here):
pawn Код:
// ...
            format(string,sizeof(string),"~g~Speed: ~w~%d mph",floatround(floatsqroot(((x*x)+(y*y))+(z*z))*156.666667*0.641371192));
            printf("[-Debug-] New Speed string for TextDraw ID # %d: [%d]'%s'", speed[playerid], strlen(string), string);
            TextDrawSetString(speed[playerid],string)
            format(string,sizeof(string),"~g~Fuel: ~w~%d%%",VehFuel[vehicleid]);
            TextDrawSetString(fuel[playerid],string);
            TextDrawShowForPlayer(playerid,fuel[playerid]);
            TextDrawShowForPlayer(playerid,speed[playerid]);
    }
}
Check if the TextDraw ID is valid and if not please check what can compromise your speed variable and if you think you are getting over the Global TextDraw Limit, have a look at Player TextDraws.

If you can not determine the problem with these instructions, and you think the debug message contains correct informations about the TextDraw ID and the string, please post here your whole FuelUpdate function.

Edit: public functions like SpeedoUpdate must return a value, altough this cannot be associated with the problem.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)