Speedometer only works for 1st person joining server.
#1

As the title says, the speedometer ONLY displays to the FIRST person that joins the server. The fuel gauge however, displays for everyone!

So it's like this:
for the first person.

SPEED : 0 MPH
FUEL: 100%

If someone else joins and enters a vehicle it's like this:


FUEL: 100%

It's been killing me for ages trying to figure it out. Could someone help me or make any suggestions? Or advise a better way to code it?

CODE:
(Forwards)

pawn Код:
forward SpeedoUpdate(playerid);
forward FuelUpdate(playerid);

new Text:speed[MAX_PLAYERS],Text:fuel[MAX_PLAYERS];
Publics.
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);
        }
}
public FuelUpdate(playerid)
{
    if(IsPlayerInAnyVehicle(playerid))
    {
    new pvehicle = GetPlayerVehicleID(playerid);
    for(new i = 1;i<MAX_VEHICLES;i++)
    {
        if(GetVehicleModel(i))
        {
            GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
            if(engine == 1)
            {
                if(VehFuel[i] > 0)
                {
                    VehFuel[i]--;
                    Fuel = VehFuel[i];
                }
                else if(VehFuel[pvehicle] == 0)
                {
                    KillTimer(FuelSysTimer[playerid]);
                    EngineStartStatus[i] = 0;
                    SetVehicleParamsEx(i,0,lights,alarm,doors,bonnet,boot,objective);
                    GameTextForPlayer(playerid, "~r~out of fuel", 3000, 5);
                    SendClientMessage(playerid, COLOUR_REALRED, "Your vehicle has run out of fuel.");

                    }
                }
            }
        }
    }
}
Fuel Save
pawn Код:
public FuelSave()
{
    for(new i = 1;i<MAX_VEHICLES;i++)
    {
        if(GetVehicleModel(i))
        {
            GetVehicleParamsEx(i,engine,lights,alarm,doors,bonnet,boot,objective);
            if(engine == 1)
            {
                    Fuel = VehFuel[i];
                    new vehicleid = MySQL_GetValue(i, "id", "vehicles");
                    MySQL_SetInteger(vehicleid, "VehFuel", Fuel, "vehicles");
                   
            }

        }
    }
}

OnPlayerStateChange
pawn Код:
if(newstate == PLAYER_STATE_DRIVER && oldstate == PLAYER_STATE_ONFOOT)
    {
        TextDrawShowForPlayer(playerid,speed[playerid]);
        TextDrawShowForPlayer(playerid,fuel[playerid]);
        if(VehOwned[vehicleid] == 1)
        {
        if(strcmp(VehOwner[VehID], GetName(playerid), true))
        {
            RemovePlayerFromVehicle(playerid);
            SendClientMessage(playerid, COLOUR_YELLOW, "This vehicle is owned by someone else.");
            TextDrawDestroy(enginestring);
            }
        }
    }
    if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER && EngineStartStatus[vehicleid] == 1)
    {
        KillTimer(SpeedoSysTimer[playerid]);
        KillTimer(FuelSysTimer[playerid]);
        SpeedoSysTimer[playerid] = SetTimerEx("SpeedoUpdate", 300, true, "i", playerid);
        FuelSysTimer[playerid] = SetTimerEx("FuelUpdate", 30000, true, "i", playerid);
        TextDrawShowForPlayer(playerid,speed[playerid]);
        TextDrawShowForPlayer(playerid,fuel[playerid]);

    }
Timers
pawn Код:
SpeedoSysTimer[playerid] = SetTimerEx("SpeedoUpdate", 300, true, "i", playerid);
    printf("speedotimer");
    FuelSysTimer[playerid] = SetTimerEx("FuelUpdate", 30000, true, "i", playerid);

If you feel any piece of code will assist that isn't here, I will post it!
Reply
#2

Where you load the textdraw codes?
Reply
#3

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);
Under Dialog_Login
Reply
#4

lol load it under onplayerconnect
Reply
#5

I already have tried that.
Reply
#6

Yeah, It still doesn't work.
Reply
#7

Create a loop which creates the textdraws needed at OnGameModeInit.
Reply
#8

Quote:
Originally Posted by CmZxC
Посмотреть сообщение
Create a loop which creates the textdraws needed at OnGameModeInit.
What do you mean?
Reply
#9

pawn Код:
public OnGameModeInit()
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        // your "TextDrawCreate" and "TextDrawSet..." things come here.
        // replace playerid with i
    }
    return 1;
}
results.

pawn Код:
public OnGameModeInit()
{
    for(new i=0;i<MAX_PLAYERS;i++)
    {
        speed[i] = TextDrawCreate(478,389,"_");
        TextDrawLetterSize(speed[i],0.37,2.0);
        TextDrawSetOutline(speed[i],1);
        TextDrawFont(speed[i], 2);
        fuel[i] = TextDrawCreate(478,413,"_");
        TextDrawLetterSize(fuel[i],0.37,2.0);
        TextDrawSetOutline(fuel[i],1);
        TextDrawFont(fuel[i], 2);
    }
    return 1;
}
Reply
#10

Going to try it! If you fix this, I'll probably love you.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)