[Tutorial] Creating A Basic Speedometer
#1

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;

Reply
#2

Nice tutorial very useful
Reply
#3

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

That is why is said ' Basic Speedometer '
Reply
#5

**Removed**
Reply
#6

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

Nice and simple.

PS: next time use [ pawn] [ /pawn]
Reply
#8

Yes

Very nice tutorial.
Reply
#9

Nice, Good for begginers.
Reply
#10

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!
Reply
#11

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

Next time, embed PAWN code in stead of PHP.
Reply
#13

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.
Reply
#14

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
Reply
#15

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
Reply
#16

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

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

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

Please photo
Reply
#20

TextDrawDestroy?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)