Saving Vehicle Distance
#1

Hello, having a problem with the textdraw showing how far the vehicle traveled. I'll show some codes then explain:

Код:
#define   GetKilometers(%0)         (VehicleInfo[%0][vKilometraj] * 0.001)

enum vInfo
{
	vKilometraj,
}
new VehicleInfo[MAX_VEHICLES][vInfo];

public loadvehicles_data(idx, name[], value[])
{
	INI_Int("Kilometraj",VehicleInfo[idx][vKilometraj]);
	return 1;
}
Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
   	if(newstate == PLAYER_STATE_DRIVER)
	{
	    GetVehiclePos(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]);
		E@_Timer[playerid] = SetTimerEx("CountKilo", 1000, true, "i", playerid);
	}
	if(oldstate == PLAYER_STATE_DRIVER && newstate == PLAYER_STATE_ONFOOT)
	{
		KillTimer(E@_Timer[playerid]);
	}
        return 1;
}
Код:
public CountKilo(playerid)
{
	if(GetVehicleDistanceFromPoint(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]) <= 100)
	{
		VehicleInfo[GetPlayerVehicleID(playerid)][vKilometraj] += floatround(GetVehicleDistanceFromPoint(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]));
	}
	GetVehiclePos(GetPlayerVehicleID(playerid), v@_P[0], v@_P[1], v@_P[2]);
}
And this function is in timer for player:
Код:
vehicleid = GetPlayerVehicleID(playerid);
strcat(string, "~n~~w~~h~", sizeof(string));
format(fstring,sizeof(fstring),"Kilometraj: ~w~%0.2f KM", GetKilometers(vehicleid));
strcat(string, fstring, sizeof(string));
TextDrawSetString(SpeedoText[i], string);
The problem is that when im driving around it stays 0.0KM its not updating to the actual travling distance.
Can somebody explain whats wrong? thank you.
Reply
#2

You must set that string to the textdraw:
TextDrawSetString(Textdraw, string);
Reply
#3

Quote:
Originally Posted by Neos07
Посмотреть сообщение
You must set that string to the textdraw:
TextDrawSetString(Textdraw, string);
Ehm, sorry forgot to add the line to code but its already there
Код:
 TextDrawSetString(SpeedoText[i], string);
I have updated the codes, you can check it again and tell me whats wrong, to this moment the TextDrawSetString is there and its not the problem. (Health+Speed updates works, the distance tracker doesn't)
Reply
#4

Bump, i still need help here.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)