SA-MP Forums Archive
[Tutorial] Creating A Basic Speedometer - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Creating A Basic Speedometer (/showthread.php?tid=187284)

Pages: 1 2


Creating A Basic Speedometer - Tim_Ethen - 02.11.2010

My comments explain it pretty good. Please read this and do not just copy and paste it.
PHP Code:
#include <a_samp>
new Float:svx[MAX_PLAYERS]; // Holds Velocity X
new Float:svy[MAX_PLAYERS]; // Holds Velocity Y
new Float:svz[MAX_PLAYERS]; // Holds Velocity Z
new Float:s1[MAX_PLAYERS]; // This Is What Our Forumula Outputs
new s2[MAX_PLAYERS]; // This Is The Output When The Forumula's Ouput Is Round
new s3[MAX_PLAYERS][256]; // This Is The Text That Is Displayed To The User
new Text:sdisplay[MAX_PLAYERS]; // This Holds The Textdraw's ID
new stimer[MAX_PLAYERS]; // This Holds The Timer's ID (Used To Refresh Speed)
forward speedometer(playerid); // This Forwards The Timer To Our Function
public OnFilterScriptInit() { // This Is What Is Excuted When The FilterScript Starts
    
print("                                       ");
    print(
"  -----------------------------------  ");
    print(
"                                       ");
    print(
"  Speedometer Filterscript Has Loaded  ");
    print(
"                                       ");
    print(
"  -----------------------------------  ");
    print(
"                                       ");
    return 
1;
}
public 
OnFilterScriptExit() { // This Is What Is Excuted When The FilterScript Ends
    
print("                                         ");
    print(
"  -------------------------------------  ");
    print(
"                                         ");
    print(
"  Speedometer Filterscript Has Unloaded  ");
    print(
"                                         ");
    print(
"  -------------------------------------  ");
    print(
"                                         ");
    return 
1;
}
public 
OnPlayerConnect(playerid) {
    
sdisplay[playerid] = TextDrawCreate(10.0,200.0," "); // This Creates Our Textdraw And Stores The Id In The Varible In Front
    
TextDrawSetShadow(sdisplay[playerid],0); // This Removes Our Textdraw's Shadow ( Makes Easier To Read )
    
TextDrawSetOutline(sdisplay[playerid],1); // This Adds A Black Outline To Our Textdraw ( Makes Easier To Read )
    
TextDrawFont(sdisplay[playerid], 2); // This Changes Our Textdraw's Font ( I Think This Ones Makes It Easier To Read )
    
TextDrawShowForPlayer(playerid,sdisplay[playerid]); // This Shows The User The Textdraw
    
return 1;
}
public 
speedometer(playerid) {
    
GetVehicleVelocity(GetPlayerVehicleID(playerid), svx[playerid], svy[playerid], svz[playerid]); // This Saves Our Velocitys To Our Varibles
    
s1[playerid] = floatsqroot(((svx[playerid]*svx[playerid])+(svy[playerid]*svy[playerid]))+(svz[playerid]*svz[playerid]))*100// This Is Our Forumula ( I Don't Know How It Works )
    
s2[playerid] = floatround(s1[playerid],floatround_round); // This Rounds Our Output To The Nearest Whole Number
    
format(s3[playerid],256,"%i MPH"s2[playerid]); // This Format Our Text Into What We See
    
TextDrawSetString(sdisplay[playerid], s3[playerid]); // This Changes The Value Of Our Textdraw To What We Formatted
    
return 1;
}
public 
OnPlayerStateChange(playeridnewstateoldstate) { // This Is The Callback That Is Called When A Person Changes State ( ex States In_Vehicle, Dead, Passenger, Speculating... )
    
KillTimer(stimer[playerid]); // This Stops Our Timer For When You Get Out Of Your Vehicle Your Speed Doesn't Keep Going
    
TextDrawSetString(sdisplay[playerid], " "); // This Sets Our Textdraw To Blank And Freezes Because We Stop The Timer ^
    
if(newstate == 2stimer[playerid] = SetTimerEx("speedometer"255true"i"playerid); // This Starts The Timer When The Player Changes His/Her State To Being The Driver
    
else if(newstate == 3stimer[playerid] = SetTimerEx("speedometer"250true"i"playerid); // This Start The Timer When The Player Changes His/Her Start To Being The Passenger
    
return 1;




Re: Creating A Basic Speedometer - Lorenc_ - 02.11.2010

Nice tutorial very useful


Re: Creating A Basic Speedometer - Steven82 - 02.11.2010

It is nice, but i think it's very plain no offense


Re: Creating A Basic Speedometer - Tim_Ethen - 02.11.2010

That is why is said ' Basic Speedometer '


Re: Creating A Basic Speedometer - Steven82 - 02.11.2010

**Removed**


Re: Creating A Basic Speedometer - pmk1 - 03.11.2010

nice! but by the way there is already two speedo tutorials.... didn't you see them? :P


Re: Creating A Basic Speedometer - [L3th4l] - 04.11.2010

Nice and simple.

PS: next time use [ pawn] [ /pawn]


Re: Creating A Basic Speedometer - Dime - 04.11.2010

Yes

Very nice tutorial.


Re: Creating A Basic Speedometer - Fresh9884 - 06.11.2010

Nice, Good for begginers.


Re: Creating A Basic Speedometer - Hiddos - 06.11.2010

Good job, at every section you explain what that line of code does. Even though it's one bump of code in a single tag and the variables aren't fully optimized, this is brilliant. Good job!


Re: Creating A Basic Speedometer - [WSF]ThA_Devil - 08.11.2010

can u make tuturial with KM/H too because others need km/h too


Re: Creating A Basic Speedometer - sim_sima - 13.06.2011

Next time, embed PAWN code in stead of PHP.


Re: Creating A Basic Speedometer - alpha500delta - 14.06.2011

Quote:
Originally Posted by sim_sima
View Post
Next time, embed PAWN code in stead of PHP.
Next time, check last post before posting :>

Nice tutorial though.


Re: Creating A Basic Speedometer - Jack_Rocker - 14.06.2011

I like this because it has been explained well, however there are already speedo tutorials! Try and make your tutorials a bit more unique! anyways.... 8/10


Re: Creating A Basic Speedometer - Namaco - 14.06.2011

Well knowing beginners they will copy and paste but indeed nice tutorial I wonder if it is a accurate one that shows the real speed not like going from 10 to 25


Re: Creating A Basic Speedometer - JamesMarcello - 04.07.2011

Well I'M super NEW to Scripting, Where exactly would i add this?


Re: Creating A Basic Speedometer - =WoR=Varth - 04.07.2011

Save it in your filterscript folder.
Don't forget to add it in your server.cfg


Re: Creating A Basic Speedometer - X3nZ - 11.07.2011

Well this isn't a tutorial because of the fact it doesn't explain nothing AT ALL.


Re: Creating A Basic Speedometer - Huiz - 13.07.2011

Please photo


Re: Creating A Basic Speedometer - Daren_Jacobson - 13.07.2011

TextDrawDestroy?