Thanks.
My final code is this :
Код:
#include <a_samp>
#include <colors>
enum td
{
Text:TDSpeedClock[13]
}
new TextDraws[td];
new Text:TextDrawsd[MAX_PLAYERS];
public OnFilterScriptInit()
{
TextDraws[TDSpeedClock][0] = TextDrawCreate(496.000000,400.000000,"~g~20");
TextDraws[TDSpeedClock][1] = TextDrawCreate(487.000000,388.000000,"~g~40");
TextDraws[TDSpeedClock][2] = TextDrawCreate(483.000000,375.000000,"~g~60");
TextDraws[TDSpeedClock][3] = TextDrawCreate(488.000000,362.000000,"~g~80");
TextDraws[TDSpeedClock][4] = TextDrawCreate(491.000000,349.000000,"~g~100");
TextDraws[TDSpeedClock][5] = TextDrawCreate(508.000000,336.500000,"~y~120");
TextDraws[TDSpeedClock][6] = TextDrawCreate(536.000000,332.000000,"~y~140");
TextDraws[TDSpeedClock][7] = TextDrawCreate(567.000000,337.000000,"~y~160");
TextDraws[TDSpeedClock][8] = TextDrawCreate(584.000000,348.000000,"~r~180");
TextDraws[TDSpeedClock][9] = TextDrawCreate(595.000000,360.000000,"~r~200");
TextDraws[TDSpeedClock][10] = TextDrawCreate(603.000000,374.000000,"~r~220");
TextDraws[TDSpeedClock][11] = TextDrawCreate(594.000000,386.000000,"~r~240");
TextDraws[TDSpeedClock][12] = TextDrawCreate(585.000000,399.000000,"~r~260");
for(new i = 0; i < 13; i++)
TextDrawSetShadow(TextDraws[TDSpeedClock][i], 1);
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_DRIVER)
{
for(new i; i < 13; i++)
TextDrawShowForPlayer(playerid, TextDraws[TDSpeedClock][i]);
TextDrawsd[playerid] = TextDrawCreate(555.0, 402.0, "~b~.");
}
else
{
TextDrawHideForPlayer(playerid, TextDrawsd[playerid]);
for(new i; i < 13; i++)
TextDrawHideForPlayer(playerid, TextDraws[TDSpeedClock][i]);
}
return 1;
}
public OnPlayerUpdate(playerid)
{
new
Float:fPos[3],
Float:Pos[2],
Float:fSpeed;
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER)
{
GetVehicleVelocity(GetPlayerVehicleID(playerid), fPos[0], fPos[1], fPos[2]);
fSpeed = floatsqroot(floatpower(fPos[0], 2) + floatpower(fPos[1], 2) +
floatpower(fPos[2], 2)) * 100;
new Float:alpha = 640 - fSpeed;
TextDrawHideForPlayer(playerid, TextDrawsd[playerid]);
TextDrawDestroy(TextDrawsd[playerid]);
GetDotXY(548, 401, Pos[0], Pos[1], alpha, 32);
TextDrawsd[playerid] = TextDrawCreate(Pos[0], Pos[1], "~w~.");
TextDrawLetterSize(TextDrawsd[playerid], 0.73, -2.60);
TextDrawSetOutline(TextDrawsd[playerid], 0);
TextDrawSetShadow(TextDrawsd[playerid], 1);
TextDrawShowForPlayer(playerid, TextDrawsd[playerid]);
new string[400];
format(string, 400, "fSpeed : %f - alpha : %f - Pos[0] : %f - Pos[1] : %f", fSpeed, alpha, Pos[0], Pos[1]);
SendClientMessageToAll(ORANGE, string);
}
return 1;
}
stock GetDotXY(Float:StartPosX, Float:StartPosY, &Float:NewX, &Float:NewY, Float:alpha, Float:dist)
{
NewX = StartPosX + (dist * floatsin(alpha, degrees));
NewY = StartPosY + (dist * floatcos(alpha, degrees));
}
I'm particularly interested in this part:
Код:
GetVehicleVelocity(GetPlayerVehicleID(playerid), fPos[0], fPos[1], fPos[2]);
fSpeed = floatsqroot(floatpower(fPos[0], 2) + floatpower(fPos[1], 2) +
floatpower(fPos[2], 2)) * 100;
new Float:alpha = 640 - fSpeed;
TextDrawHideForPlayer(playerid, TextDrawsd[playerid]);
TextDrawDestroy(TextDrawsd[playerid]);
GetDotXY(548, 401, Pos[0], Pos[1], alpha, 32);
and
Код:
stock GetDotXY(Float:StartPosX, Float:StartPosY, &Float:NewX, &Float:NewY, Float:alpha, Float:dist)
{
NewX = StartPosX + (dist * floatsin(alpha, degrees));
NewY = StartPosY + (dist * floatcos(alpha, degrees));
}
The problem is that I find the speed a little faster ... With a bike, I get to 100km / h (again, the bikes, no matter).
Except that if such because, I remain at 50km / h, the speed is really slow ... So I try to reduce some of the counter.
If I chance '* 200' to '* 100', the counter is not going further than 140/160 km / h.
If I spend 320 to 640, the meter starts at 40 ...
In short, I do not know how to get a more realistic speed: /
Thank you in advance!