Simple speed indicator / Speedometer Circle
Hello!
Just checked out Correlli's Dynamic Circles. I felt like making something, since no one else posted anything related yet. So here is a Textdraw that converts the Velocity over to a visible green (or any defined color) line on the circle.
The source below requires:
- Foreach
- Textdraw Circles Include by Correlli (Check Requirements..) .
I would appreciate being corrected if my code contain unhappy mistakes.
I am not sure if i could make it even more efficient but did my best. It only updates the code if the speed is different from last update, and it only updates the text-draws that are affected.
Media:
https://www.youtube.com/watch?v=sQeT...ature=youtu.be
Check Attachment for picture
Requirements:
Correlli's Dynamic Circle System: http://forum.sa-mp.com/showthread.php?t=601855
Y_iterate: Click for GitHub (Or simply just foreach standalone.. People tend to not use YSI library). The include Requires it anyway
Mirror for the textdraw circle Include: https://1drv.ms/u/s!Ao9STFEV7-HjgtMIUwcINW43VyTp-w
If you have any further improvements to make, let me know.
Hello!
Just checked out Correlli's Dynamic Circles. I felt like making something, since no one else posted anything related yet. So here is a Textdraw that converts the Velocity over to a visible green (or any defined color) line on the circle.
The source below requires:
- Foreach
- Textdraw Circles Include by Correlli (Check Requirements..) .
I would appreciate being corrected if my code contain unhappy mistakes.
I am not sure if i could make it even more efficient but did my best. It only updates the code if the speed is different from last update, and it only updates the text-draws that are affected.
Media:
https://www.youtube.com/watch?v=sQeT...ature=youtu.be
Check Attachment for picture
Requirements:
Correlli's Dynamic Circle System: http://forum.sa-mp.com/showthread.php?t=601855
Y_iterate: Click for GitHub (Or simply just foreach standalone.. People tend to not use YSI library). The include Requires it anyway
Mirror for the textdraw circle Include: https://1drv.ms/u/s!Ao9STFEV7-HjgtMIUwcINW43VyTp-w
PHP Code:
#include <a_samp>
#include <foreach>
#include <c_textdraw>
main ()
{
return 1;
}
// __ _______ __ __ _
// _/_//_/ ___/___ / /_/ /_(_)___ ____ ______
// _/_//_/ \__ \/ _ \/ __/ __/ / __ \/ __ `/ ___/
// _/_//_/ ___/ / __/ /_/ /_/ / / / / /_/ (__ )
///_//_/ /____/\___/\__/\__/_/_/ /_/\__, /____/
// /____/
new TD_L_Value[MAX_PLAYERS];
new SpeedoTimer[MAX_PLAYERS];
#define UPDATE_INTERVAL 200 //How often do you want to update the spedometer textdraw? In milliseconds
#define COLOR_EMPTY 0x00000055 //when no speed, which color? (The base color)
#define COLOR_FILLED 0x33FF3377 //when speed detected, which color whould it be?
#define SPEED_MULTIPLIER 43 //needs to be increased a bit if you lower the value of "DIFF" below.
#define POSX 560.0 //Center Position X
#define POSY 400.0 //Center Position Y
#define DIAMETER 40.0 //Diameter of the circle
#define TD_LETTER ")" //This is the letter the Circle is made of. ".", "," and ")" are the best ones in my opinion.
#define DIFF 4.0 // 1.40 is lowest, as 360/1.41 ~ 256. do 360/DIFF in order to see how many TXD's you get. The higher number = less textdraws, read about "DIFF" here:
//http://forum.sa-mp.com/showthread.php?p=3663973#post3663973
public OnFilterScriptInit()
{
print("Circle Textdraw speedo v1.0 by denNorske has been loaded successfully");
return 1;
}
public OnPlayerStateChange(playerid, newstate, oldstate)
{
if(newstate == PLAYER_STATE_ONFOOT && oldstate == PLAYER_STATE_DRIVER && TD_IsCircleCreated(playerid)) //The player was a driver, and now he's on foot.
{
TD_DestroyCircle(playerid);
KillTimer(SpeedoTimer[playerid]);
}
if(newstate == PLAYER_STATE_DRIVER && !TD_IsCircleCreated(playerid)) //Player became a driver in a car, and no textdraws has been created yet
{
TD_CreateCircle(playerid,TD_LETTER, COLOR_EMPTY, POSX, POSY, DIAMETER, DIFF);
SpeedoTimer[playerid] = SetTimerEx("UpdateSpeed", UPDATE_INTERVAL, 1, "i", playerid);
}
return 1;
}
forward UpdateSpeed(playerid);
public UpdateSpeed(playerid)
{
if(GetPlayerState(playerid) == PLAYER_STATE_DRIVER && TD_IsCircleCreated(playerid))
{
new Float:VelX, Float:VelTotal, Float:VelY, Float:VelZ, value;
GetVehicleVelocity(GetPlayerVehicleID(playerid), VelX, VelY, VelZ);
VelTotal = floatsqroot(floatpower(VelX, 2) + floatpower(VelY, 2) + floatpower(VelZ, 2)); //
value = floatround(VelTotal*SPEED_MULTIPLIER); //the calc'ed velocity, added with 43 to make it work correctly. can be adjusted--
if(TD_L_Value[playerid] == value) //no need to update anything. Very efficient if car is standing still, or the speed is constant
return 1;
else if(TD_L_Value[playerid] < value) //higher speed, aka only new green to add
{
if(value > floatround(360/DIFF, floatround_floor))
value = floatround(360/DIFF, floatround_floor); //to avoid crashes. the speed may go higher than amount of textdraws, that's why
for(new i = TD_L_Value[playerid]; i< value; i++) //TD_L_Value[playerid] is used here to avoid updating already colored part, and just extend the area..
{
TD_L_Value[playerid] = value;
TD_SetCircleSlotColor(playerid, i, COLOR_FILLED);
}
}
else if(TD_L_Value[playerid] > value)
{
for(new i = value; i<TD_L_Value[playerid]; i++)
{
TD_SetCircleSlotColor(playerid, i, COLOR_EMPTY);
}
TD_L_Value[playerid] = value;
}
}
return 1;
}
public OnFilterScriptExit()
{
foreach(new i : Player)
TD_DestroyCircle(i);
print("Circles Unloaded");
return 1;
}
public OnPlayerDisconnect(playerid, reason)
{
TD_DestroyCircle(playerid);
return 1;
}
If you have any further improvements to make, let me know.