SA-MP Forums Archive
Problem with Speedometer ! - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Problem with Speedometer ! (/showthread.php?tid=215180)



Problem with Speedometer ! - Yaszine - 22.01.2011

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


Re : Problem with Speedometer ! - Yaszine - 22.01.2011

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;
}



Re: Problem with Speedometer ! - Lorenc_ - 22.01.2011

Add:


TextDrawShowForPlayer(playerid, Text:SPEEDOX);

To your command


Re : Problem with Speedometer ! - Yaszine - 22.01.2011

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


Re: Problem with Speedometer ! - Lorenc_ - 23.01.2011

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

and insert the stuff..


Re : Problem with Speedometer ! - Yaszine - 23.01.2011

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


Re : Problem with Speedometer ! - Yaszine - 23.01.2011

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 !


Re: Problem with Speedometer ! - bartje01 - 23.01.2011

OnPlayerEnterVehicle?....


Re : Problem with Speedometer ! - Yaszine - 23.01.2011

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 !!


Re: Problem with Speedometer ! - bartje01 - 23.01.2011

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