Different kind of speed - 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)
+--- Thread: Different kind of speed (
/showthread.php?tid=426150)
Different kind of speed -
alleboss - 28.03.2013
Hi, I'm alessandro and i'm italian, I add in my gamemode the gCamera script. gCamera script to show the speed when you was shot use this:
Код:
stock Float:GetVehicleSpeed(vehicleid,UseMPH = 0)
{
new Float:speed_x,Float:speed_y,Float:speed_z,Float:temp_speed;
GetVehicleVelocity(vehicleid,speed_x,speed_y,speed_z);
if(UseMPH == 0)
{
temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*136.666667; //dov'и quello delle text?
} else {
temp_speed = floatsqroot(((speed_x*speed_x)+(speed_y*speed_y))+(speed_z*speed_z))*86.4166672;
}
floatround(temp_speed,floatround_round);return temp_speed;
}
and for example show you're driving at 100 when the max speed is 70.
The problem is: My gamemode use a textdraw to show the speed but the speed on the textdraw is different.
Код:
stock GetPlayerSpeed(playerid,bool:kmh)
{
new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz); else GetPlayerVelocity(playerid,Vx,Vy,Vz);
rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
return kmh ? floatround(((rtn * 100 * 1.61) / 1.609)) : floatround(rtn * 100);
}
Код:
stock GetPlayerSpeed(playerid,bool:kmh)
{
new Float:Vx,Float:Vy,Float:Vz,Float:rtn;
if(IsPlayerInAnyVehicle(playerid)) GetVehicleVelocity(GetPlayerVehicleID(playerid),Vx,Vy,Vz);
else GetPlayerVelocity(playerid,Vx,Vy,Vz);
rtn = floatsqroot(floatabs(floatpower(Vx + Vy + Vz,2)));
return kmh?floatround(rtn * 100 * 3.61):floatround(rtn * 120);
}
and here the speedometer
Код:
public Speedometer(playerid)
{
new State = GetPlayerState(playerid);
if(State == PLAYER_STATE_DRIVER && IsPlayerInAnyVehicle(playerid))
{
if(Contachilometri[playerid][ShowSpeed] == 1)
{
new string[256], Float:health;
new vehicleid = GetPlayerVehicleID(playerid);
GetVehicleHealth(vehicleid, health);
new Float:svx[MAX_PLAYERS];
new Float:svy[MAX_PLAYERS];
new Float:svz[MAX_PLAYERS];
new Float:s1[MAX_PLAYERS];
new s2[MAX_PLAYERS];
GetVehicleVelocity(GetPlayerVehicleID(playerid), svx[playerid], svy[playerid], svz[playerid]);
s1[playerid] = floatsqroot(((svx[playerid]*svx[playerid])+(svy[playerid]*svy[playerid]))+(svz[playerid]*svz[playerid]))*100;
s2[playerid] = floatround(s1[playerid],floatround_round);
new Sspeed[15];
if( s2[playerid] == 0) {
format(Sspeed,sizeof(Sspeed),"~w~%d Km/h", s2[playerid]);
} else if( s2[playerid] >= 1 && s2[playerid] < 100 ){
format(Sspeed,sizeof(Sspeed),"~g~%d Km/h", s2[playerid]);
} else if( s2[playerid] >= 100 && s2[playerid] < 140 ){
format(Sspeed,sizeof(Sspeed),"~Y~%d Km/h", s2[playerid]);
} else {
format(Sspeed,sizeof(Sspeed),"~R~%d Km/h",s2[playerid]);
}
format(string,sizeof(string),"~p~Auto:~n~~w~%s~n~~p~Velocita: %s~n~~p~Benzina: ~w~%d~n~~p~Vita: ~W~%.1f~n~~p~Localita:~n~~w~%s" ,VehiclesName[GetVehicleModel(vehicleid)-400], Sspeed, Fuel[vehicleid], health/10, ReturnPlayerZone(playerid));
TextDrawSetString(Contachilometri[playerid][Speedom], string);
TextDrawShowForPlayer(playerid, Contachilometri[playerid][Speedom]);
} else { TextDrawHideForPlayer(playerid, Contachilometri[playerid][Speedom]); Contachilometri[playerid][ShowSpeed] = 0; }
}
return true;
}
Finally, what i do to show in a textdraw the speed like a gCam's speed calculations?