Problem with Speedometer !
#1

Hello everyone, I have a speedometer I don't remember where I have found it.
This is it:

This on top of GM:
pawn Код:
new Text:SPEEDOX;
new Speedox[MAX_PLAYERS];

pawn Код:
public OnGameModeExit()
{
    TextDrawDestroy(Text:SPEEDOX);
    return 1;
}

pawn Код:
public OnPlayerConnect(playerid)
{
    Speedox[playerid]=1;
    UpdateSpeed();
    return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(Speedox[playerid]==1)
    {
    Speedox[playerid]=0;
    TextDrawHideForPlayer(playerid, Text:SPEEDOX);
    }
return 1;
}
This is a Command:
pawn Код:
if(strcmp(cmdtext,"/dash",true) == 0)
{
if(IsPlayerInAnyVehicle(playerid))
{
    if(Speedox[playerid] == 1){SendClientMessage(playerid, YELLOW, "SpeedoMeter desabled."); Speedox[playerid] = 0;}
    else{SendClientMessage(playerid, YELLOW, "~ MSS: SpeedoMeter enabled."); Speedox[playerid] = 1;}
}else{
    SendClientMessage(playerid, RED, "You're not in a car.");
}

    return 1;
}
pawn Код:
public OnPlayerUpdate(playerid)
{  
if(Speedox[playerid] == 1)
{
        if(IsPlayerInAnyVehicle(playerid))
        {
            TextDrawShowForPlayer (playerid, Text:SPEEDOX);
        }
        else
        {
            TextDrawHideForPlayer(playerid, Text:SPEEDOX);
        }
}
else
{
        if(IsPlayerInAnyVehicle(playerid))
        {
            TextDrawHideForPlayer(playerid, Text:SPEEDOX);
        }
        else
        {
            TextDrawHideForPlayer(playerid, Text:SPEEDOX);
        }
}
    return 1;
}
This is under the GM:
pawn Код:
forward UpdateSpeed();
public UpdateSpeed()
{
    for(new i=0; i<MAX_PLAYERS; i++)
    {
            new Float:Sp_x, Float:Sp_y, Float:Sp_z, Float:f_speed, f_speed_int;
            new S_string[256];
            new Float:vh;
            new vehicleid;
            vehicleid = GetPlayerVehicleID(i);
            GetVehicleHealth(vehicleid, vh);
            GetVehicleVelocity(vehicleid,Sp_x,Sp_y,Sp_z);
            f_speed = floatsqroot(((Sp_x*Sp_x)+(Sp_y*Sp_y))+(Sp_z*Sp_z))*136.666667; // & MPH = 85.4166672
            f_speed_int = floatround(f_speed,floatround_round);
            format(S_string,256,"~g~Vehicule : ~w~%s ~n~~g~~h~~h~Ping : ~w~%d / ~b~KM/H : ~w~%d ~n~~r~Vehicle Health:~w~ %.2f",Vehiclex[GetVehicleModel(vehicleid)-400],GetPlayerPing(i),f_speed_int,vh);
            SPEEDOX = TextDrawCreate(320.00, 380.00, S_string);
            TextDrawSetOutline(SPEEDOX, 0);
            TextDrawFont(SPEEDOX, 3);
            TextDrawSetProportional(SPEEDOX, 2);
            TextDrawAlignment(SPEEDOX, 2);
    }
    return 1;
}
Now, if I join the server I take a car and no dashboard
and if there is a mistake, I hope you correct it for me!
So I hope some experts help me
Please

~ Yassine
Reply
#2

and also I have this one:
pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_ONFOOT && Speedox[playerid] == 1)
{
TextDrawHideForPlayer(playerid, Text:SPEEDOX);
}

   return 1;
}
Reply
#3

Add:


TextDrawShowForPlayer(playerid, Text:SPEEDOX);

To your command
Reply
#4

Thanks for your answer

But, it should show the text when I take a car without taping /dash
When someone is join the server and spawn and take a car it show him the dash
Reply
#5

on player update you need to do something like if(!IsPlayerInVehicle(playerid))

and insert the stuff..
Reply
#6

and don't know what can I do, please help !
Reply
#7

I think the TextDrawCreate should be in OnGameModeInit, but if I do
The whole vehicles / skins not appears if I play
Something wrong with me !
Reply
#8

OnPlayerEnterVehicle?....
Reply
#9

This one ?
pawn Код:
public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    if(Speedox[playerid] == 1){TextDrawShowForPlayer (playerid, Text:SPEEDOX);}
    else{TextDrawHideForPlayer(playerid, Text:SPEEDOX);}
    return 1;
}

And should also this ?
pawn Код:
public OnPlayerExitVehicle(playerid,vehicleid)
{
if(Speedox[playerid] == 1)
{
TextDrawHideForPlayer(playerid, Text:SPEEDOX);
}
else {}
return 1;
}
But there is OnPlayerUpdate it show the text if player Speedox=1 & incar !!
Reply
#10

Well I should use onplayerentervehicle. Or just a timer that repeats.
Onplayerupdate will let your server lag like hell.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)