Speedometer only displays to 1st person joining server.
#1

Title says all..When I connect, no matter who the first person is to join the server, the speedometer only displays for them. The fuel meter displays for ALL players. Can anyone see the issue?

CREATING TIMERS:
pawn Code:
new SpeedoSysTimer[MAX_PLAYERS];
new FuelSysTimer[MAX_PLAYERS];
forward SpeedoUpdate(playerid);
forward FuelUpdate(playerid);
CREATING TEXTS:
pawn Code:
new Text:speed[MAX_PLAYERS],Text:fuel[MAX_PLAYERS];
ENGINE ON.
pawn Code:
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("kills fuel");
   
    TextDrawShowForPlayer(playerid,speed[playerid]);
    printf("shows speedo");
    TextDrawShowForPlayer(playerid,fuel[playerid]);
    printf("shows fuel");
    TextDrawDestroy(enginestring);

    SpeedoSysTimer[playerid] = SetTimerEx("SpeedoUpdate", 300, true, "i", playerid);
    printf("speedotimer");
    FuelSysTimer[playerid] = SetTimerEx("FuelUpdate", 30000, true, "i", playerid);
    printf("fueltimer");
    SetTimer("FuelSave", 4000, 1);
   
   
    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;
}
SPEEDO TIMER
pawn Code:
public SpeedoUpdate()
{
    foreach(Player, i)
    {
        if(IsPlayerInAnyVehicle(i))
        {
            new Float:x,Float:y,Float:z,string[24],vehicleid = GetPlayerVehicleID(i);
            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[i],string);
            format(string,sizeof(string),"~g~Fuel: ~w~%d%%",VehFuel[vehicleid]);
            TextDrawSetString(fuel[i],string);
        }
    }
}
Can someone assist? As you can see, I've tried to DEBUG multiple times. If someone could give me some pointers. + REP.
Reply
#2

Someone Please tell me why?
Reply
#3

well...

you have this
pawn Code:
SpeedoSysTimer[playerid] = SetTimerEx("SpeedoUpdate", 800, true, "i", playerid);
which you farward the playerid so why not use it ? instead your making more lag !

pawn Code:
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);
        }

}
Explained

as you have a cmd to turn on the speedo , etc..
just forward the playerid so you don't have to loop through all players creating more lag because the timers is running at 300 every millisecond for nearly every player on the server and if you add the loop that will eat a lot of CPU mem. will cause lag!
Reply
#4

Quote:
Originally Posted by park4bmx
View Post
well...

you have this
pawn Code:
SpeedoSysTimer[playerid] = SetTimerEx("SpeedoUpdate", 800, true, "i", playerid);
which you farward the playerid so why not use it ? instead your making more lag !

pawn Code:
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);
        }

}
Explained

as you have a cmd to turn on the speedo , etc..
just forward the player id so you dont have to loop through all players creating more lag becouse the timers is running at 300 every milisecond and if you add the [b]loop[/u] that will eat alot of cpu mem. will cause lagg!
Yes, I done that for testing purposes, I originally had what you showed me. The issue is not resolved, the first player that logs in and goes to a vehicle and types /eon gets this display:

SPEED: 0MPH (Not moving yet).
Fuel: 17%(or whatever the fuel is).

Second person logs in, goes to a vehicle and gets this.

FUEL: 17%.

No SPEED:

It's the same for any vehicle and any other player except the first one to hit the command.
Reply
#5

Bump again, Urgently need help.
Reply
#6

what i would say is.

[1] if there is a background BOX behind the speedometer, for the secodns player the Speed text might be created behind the BOX

[2try creat a normal cmd with just
pawn Code:
TextDrawShowForPlayer(playerid,fuel[playerid]);
see if it comes up
Reply
#7

Doing that now!
Reply
#8

That didn't work, the command.
Reply
#9

None of that worked, at all. Can someone else help?
Reply
#10

if the dialog didnt show then the Textdraw must have being Destroyed in previous code !
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)