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


Messages In This Thread
Saving Vehicle Distance - by maximthepain - 28.06.2015, 23:26
Re: Saving Vehicle Distance - by Neos07 - 28.06.2015, 23:34
Re: Saving Vehicle Distance - by maximthepain - 28.06.2015, 23:37
Re: Saving Vehicle Distance - by maximthepain - 29.06.2015, 08:40

Forum Jump:


Users browsing this thread: 2 Guest(s)