SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 02/11/2010, 03:48 AM   #1
Tim_Ethen
Little Clucker
 
Join Date: Sep 2010
Posts: 21
Reputation: 3
Default Creating A Basic Speedometer

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;

Tim_Ethen is offline   Reply With Quote
Old 02/11/2010, 03:51 AM   #2
Lorenc_
High-roller
 
Lorenc_'s Avatar
 
Join Date: Jan 2010
Location: Australia
Posts: 3,804
Reputation: 1160
Default Re: Creating A Basic Speedometer

Nice tutorial very useful
__________________
Join the best Cops And Robbers in SA-MP, today. svr.sfcnr.com:7777

Lorenc_ is offline   Reply With Quote
Old 02/11/2010, 04:06 AM   #3
Steven82
High-roller
 
Join Date: Nov 2009
Posts: 2,432
Reputation: 173
Default Re: Creating A Basic Speedometer

It is nice, but i think it's very plain no offense
__________________
If you read my old posts; I apologize in advance.
Steven82 is offline   Reply With Quote
Old 02/11/2010, 04:17 AM   #4
Tim_Ethen
Little Clucker
 
Join Date: Sep 2010
Posts: 21
Reputation: 3
Default Re: Creating A Basic Speedometer

That is why is said ' Basic Speedometer '
Tim_Ethen is offline   Reply With Quote
Old 02/11/2010, 04:27 AM   #5
Steven82
High-roller
 
Join Date: Nov 2009
Posts: 2,432
Reputation: 173
Default Re: Creating A Basic Speedometer

**Removed**
__________________
If you read my old posts; I apologize in advance.
Steven82 is offline   Reply With Quote
Old 03/11/2010, 10:44 PM   #6
pmk1
Huge Clucker
 
pmk1's Avatar
 
Join Date: Jan 2010
Posts: 351
Reputation: 1
Default Re: Creating A Basic Speedometer

nice! but by the way there is already two speedo tutorials.... didn't you see them? :P
__________________
Tutorials***
[TUT]Speedometer & Healthometer with A Timer
จจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจจ

Currently In-Developpement ~60% done
...
pmk1 is offline   Reply With Quote
Old 04/11/2010, 02:51 AM   #7
[L3th4l]
Guest
 
Posts: n/a
Default Re: Creating A Basic Speedometer

Nice and simple.

PS: next time use [ pawn] [ /pawn]
  Reply With Quote
Old 04/11/2010, 03:04 AM   #8
Dime
Huge Clucker
 
Join Date: Jul 2010
Posts: 257
Reputation: 1
Default Re: Creating A Basic Speedometer

Yes

Very nice tutorial.
Dime is offline   Reply With Quote
Old 06/11/2010, 02:39 PM   #9
Fresh9884
Huge Clucker
 
Fresh9884's Avatar
 
Join Date: Apr 2009
Posts: 303
Reputation: 6
Default Re: Creating A Basic Speedometer

Nice, Good for begginers.
Fresh9884 is offline   Reply With Quote
Old 06/11/2010, 02:49 PM   #10
Hiddos
High-roller
 
Hiddos's Avatar
 
Join Date: Sep 2008
Posts: 3,308
Reputation: 2183
Default Re: Creating A Basic Speedometer

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!
__________________
Quote:
Originally Posted by DeWolf View Post
For fuck's sake people, this whole thread is fucked up now.
Hiddos is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] [TUT]Creating a basic Account system_ -Rebel Son- Tutorials 34 18/10/2011 01:29 PM
Need help with Speedometer! Cameltoe Help Archive 2 02/11/2010 03:55 AM
speedometer [Lsrcr]Rafa Help Archive 7 14/09/2010 08:51 PM
|ฐ Speedometer HELP ฐ| DarkPower Help Archive 3 12/05/2010 08:12 PM
Speedometer and Name car icebox10 Help Archive 0 30/07/2009 02:05 PM


All times are GMT. The time now is 06:53 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.