Speedometer
#1

Hello, im trying to make a speedometer, but i have 1 problem with textdraws. So now there are this codes in filterscript:
At the filterscript start:
Код:
new Text:greitis;
forward Matuoja(playerid);
OnPlayerEnterVehicle:
Код:
SetTimerEx("Matuoja",500,true,"i",playerid);
OnPlayerExitVehicle:
Код:
TextDrawDestroy(greitis);
And in script down there are Matuoja timer and stock GetPlayerSpeed:
Код:
public Matuoja(playerid)
{
	new kmh[128];
	format(kmh, 128, "Greitis: %i", GetPlayerSpeed(playerid));
	greitis = TextDrawCreate(160, 349, kmh);
	TextDrawFont(greitis , 2);
	TextDrawLetterSize(greitis , 0.4, 1);
	TextDrawColor(greitis , 0xC6D134FF);
	TextDrawSetOutline(greitis , 0);
	TextDrawSetProportional(greitis , 1);
	TextDrawSetShadow(greitis , 0);
	TextDrawShowForPlayer(playerid, greitis);
}

stock GetPlayerSpeed(playerid)
{
	new Float:ST[4];
	if(IsPlayerInAnyVehicle(playerid))
	GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
	else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
	ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 180.3;
	return floatround(ST[3]);
}
So now the problem is, when i driving a car, it will makes much of speed texts, like this one: here
But why?
Reply
#2

Do not recreate the textdraw every half a second in a timer ! Do it somewhere in another function, preferably under OnGameModeInit, and then update the textdraw in a timer with TextDrawSetString.
Reply
#3

Quote:
Originally Posted by Virtual1ty
Посмотреть сообщение
Do not recreate the textdraw every half a second in a timer ! Do it somewhere in another function, preferably under OnGameModeInit, and then update the textdraw in a timer with TextDrawSetString.
So it should look like this:
Код:
#include <a_samp>

new Text:greitis;
forward Matuoja(playerid);

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    greitis = TextDrawCreate(160, 349, "");
	TextDrawFont(greitis , 2);
	TextDrawLetterSize(greitis , 0.4, 1);
	TextDrawColor(greitis , 0xC6D134FF);
	TextDrawSetOutline(greitis , 0);
	TextDrawSetProportional(greitis , 1);
	TextDrawSetShadow(greitis , 0);
	return 1;
}

public OnFilterScriptExit()
{
	return 1;
}

#else

main()
{
	print("\n----------------------------------");
	print(" ...");
	print("----------------------------------\n");
}

#endif

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
	SetTimerEx("Matuoja",500,true,"i",playerid);
	return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
	TextDrawDestroy(greitis);
	return 1;
}

public Matuoja(playerid)
{
    new kmh[128];
	format(kmh, 128, "Greitis: %i", GetPlayerSpeed(playerid));
	TextDrawSetString(greitis, kmh);
	TextDrawShowForPlayer(playerid, greitis);
}

stock GetPlayerSpeed(playerid)
{
	new Float:ST[4];
	if(IsPlayerInAnyVehicle(playerid))
	GetVehicleVelocity(GetPlayerVehicleID(playerid),ST[0],ST[1],ST[2]);
	else GetPlayerVelocity(playerid,ST[0],ST[1],ST[2]);
	ST[3] = floatsqroot(floatpower(floatabs(ST[0]), 2.0) + floatpower(floatabs(ST[1]), 2.0) + floatpower(floatabs(ST[2]), 2.0)) * 180.3;
	return floatround(ST[3]);
}
?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)