Quantcast
Channel: SA-MP Forums - Filterscripts
Viewing all articles
Browse latest Browse all 595

[FilterScript] v1.0 Speed indicator / Speedometer with Correlli's Dynamic Circles

$
0
0
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

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(playeridnewstateoldstate

    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_LETTERCOLOR_EMPTYPOSXPOSYDIAMETERDIFF);  
        
SpeedoTimer[playerid] = SetTimerEx("UpdateSpeed"UPDATE_INTERVAL1"i"playerid); 
    } 
    return 
1



forward UpdateSpeed(playerid); 
public 
UpdateSpeed(playerid

    if(
GetPlayerState(playerid) == PLAYER_STATE_DRIVER && TD_IsCircleCreated(playerid)) 
    { 
        new 
Float:VelXFloat:VelTotalFloat:VelYFloat:VelZvalue
        
GetVehicleVelocity(GetPlayerVehicleID(playerid), VelXVelYVelZ); 
        
VelTotal floatsqroot(floatpower(VelX2) + floatpower(VelY2) + floatpower(VelZ2)); // 
        
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/DIFFfloatround_floor)) 
                
value floatround(360/DIFFfloatround_floor); //to avoid crashes. the speed may go higher than amount of textdraws, that's why 
            
for(new TD_L_Value[playerid]; ivaluei++) //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(playeridiCOLOR_FILLED); 
            } 

        } 
        else if(
TD_L_Value[playerid] > value
        { 
            for(new 
valuei<TD_L_Value[playerid]; i++) 
            { 
                
TD_SetCircleSlotColor(playeridiCOLOR_EMPTY); 
            } 
            
TD_L_Value[playerid] = value
        } 
    } 
    return 
1


public 
OnFilterScriptExit() 

    foreach(new 
Player
        
TD_DestroyCircle(i);  
    print(
"Circles Unloaded"); 
    return 
1

public 
OnPlayerDisconnect(playeridreason

    
TD_DestroyCircle(playerid); 
    return 
1




If you have any further improvements to make, let me know.

Attached Images
File Type: jpg Uten navn.jpg (199.8 KB)

Viewing all articles
Browse latest Browse all 595

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>