SA-MP Forums Archive
The way to make this speedo? - 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)
+--- Thread: The way to make this speedo? (/showthread.php?tid=630925)



The way to make this speedo? - DuyDang2412 - 20.03.2017

Yeah, I'm trying to make this speedometer because it looks very nice.
I just know that to do that, I have to get vehicle speed and vehicle max speed, so I already done. About the Textdraw, I don't know how to make it update, can someone tell me? Because I'm not really good at this.
https://*********/OFLX74vmGtc


Re: The way to make this speedo? - Mic_H - 20.03.2017

1. Make 20 PlayerTextDrawBoxes in color black. Similar to the one made like that, You shouldn't make GlobalTextDraws because its being updated per-player and 20 * MAX_PLAYERS will be too much and you might exceed the textdraw limit

2. Use OnPlayerUpdate or Timer to update the PlayerTextDrawColor (You must use PlayerTextDrawShow to update changes)

Outline of Script
PHP код:
How the code would look:>
#define SMALL_BOXES_MADE 20
#define COLOR_EMPTY 0x00000077 //77 is the transperancy
#define COLOR_GOOD 0x0066ccFF //Can do this for the first 5 boxes
#define COLOR_AVG 0x00ff00FF //Can do this for the next 10 boxes
#define COLOR_MAX 0xcc3300FF //Can do this for the last 5 boxes
new PlayerText:SpeedoMeter[MAX_PLAYERS][SMALL_BOXES_MADE];
//Here 0 will be the smallest box
//19 will be the biggest
new Timer:x[MAX_PLAYERS];
OnPlayerConnect(playerid)
    
Create20SmallBoxes(playerid);
    
OnPlayerEnterVehicle(playerid ...)
    
ShowSmallBoxes(playerid);
    
x[playerid] = repeat Speedo(playerid);
    
OnPlayerExitVehicle(playerid ...)
{
    
HideSmallBoxes(playerid);
    
stop x[playerid];
}
//You can either use a Timer or onPlayerUpdate.. But timer is better for this case..
timer Speedo[500](playerid)
{
    if(
IsPlayerInAnyVehicle(playerid)) //Incase he was jacked or exited in ways that wouldnt trigger OnPlayerExitVehicle
    
{
        new 
vehicleid GetPlayerVehicleID(playerid);
        new 
modelid GetVehicleModel(vehicleid);
        new 
Float:maxspeed max_speed[modelid 400]; //However u store it
        
new speedtokens maxspeed SMALL_BOXES_MADE;
        
//Speedtokens decide at what speed ONE box's color has to be changed.
        
new Float:Currspeed GetPlayerSpeed(playerid); //However you get it
        
new BoxesToUpdate floatround(CurrSpeed speedtokensfloatround_round);
        for(new 
0SMALL_BOXES_MADEi++)
        {
            if(
<= BoxesToUpdate)
            {
                if(
5PlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_GOOD);
                else if(
15PlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_AVG);
                else if(
SMALL_BOXES_MADEPlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_MAX);
            }
            else
            {
                  
PlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_EMPTY);
            }
            
PlayerTextDrawShow(playeridSpeedoMeter[playerid][i]);
        }
    }
    else
    {
        
HideSmallBoxes(playerid);
        
stop x[playerid];
    }

This is the not the code.. This is to educate you on how its done.


Re: The way to make this speedo? - DuyDang2412 - 20.03.2017

Quote:
Originally Posted by Mic_H
Посмотреть сообщение
1. Make 20 PlayerTextDrawBoxes in color black. Similar to the one made like that, You shouldn't make GlobalTextDraws because its being updated per-player and 20 * MAX_PLAYERS will be too much and you might exceed the textdraw limit

2. Use OnPlayerUpdate or Timer to update the PlayerTextDrawColor (You must use PlayerTextDrawShow to update changes)

Outline of Script
PHP код:
How the code would look:>
#define SMALL_BOXES_MADE 20
#define COLOR_EMPTY 0x00000077 //77 is the transperancy
#define COLOR_GOOD 0x0066ccFF //Can do this for the first 5 boxes
#define COLOR_AVG 0x00ff00FF //Can do this for the next 10 boxes
#define COLOR_MAX 0xcc3300FF //Can do this for the last 5 boxes
new PlayerText:SpeedoMeter[MAX_PLAYERS][SMALL_BOXES_MADE];
//Here 0 will be the smallest box
//19 will be the biggest
new Timer:x[MAX_PLAYERS];
OnPlayerConnect(playerid)
    
Create20SmallBoxes(playerid);
    
OnPlayerEnterVehicle(playerid ...)
    
ShowSmallBoxes(playerid);
    
x[playerid] = repeat Speedo(playerid);
    
OnPlayerExitVehicle(playerid ...)
{
    
HideSmallBoxes(playerid);
    
stop x[playerid];
}
//You can either use a Timer or onPlayerUpdate.. But timer is better for this case..
timer Speedo[500](playerid)
{
    if(
IsPlayerInAnyVehicle(playerid)) //Incase he was jacked or exited in ways that wouldnt trigger OnPlayerExitVehicle
    
{
        new 
vehicleid GetPlayerVehicleID(playerid);
        new 
modelid GetVehicleModel(vehicleid);
        new 
Float:maxspeed max_speed[modelid 400]; //However u store it
        
new speedtokens maxspeed SMALL_BOXES_MADE;
        
//Speedtokens decide at what speed ONE box's color has to be changed.
        
new Float:Currspeed GetPlayerSpeed(playerid); //However you get it
        
new BoxesToUpdate floatround(CurrSpeed speedtokensfloatround_round);
        for(new 
0SMALL_BOXES_MADEi++)
        {
            if(
<= BoxesToUpdate)
            {
                if(
5PlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_GOOD);
                else if(
15PlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_AVG);
                else if(
SMALL_BOXES_MADEPlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_MAX);
            }
            else
            {
                  
PlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_EMPTY);
            }
            
PlayerTextDrawShow(playeridSpeedoMeter[playerid][i]);
        }
    }
    else
    {
        
HideSmallBoxes(playerid);
        
stop x[playerid];
    }

This is the not the code.. This is to educate you on how its done.
Thanks a lot ! You helped me, that's very kind of you. I will show you my result after I've done.


Re: The way to make this speedo? - DuyDang2412 - 20.03.2017

Quote:
Originally Posted by Mic_H
Посмотреть сообщение
1. Make 20 PlayerTextDrawBoxes in color black. Similar to the one made like that, You shouldn't make GlobalTextDraws because its being updated per-player and 20 * MAX_PLAYERS will be too much and you might exceed the textdraw limit

2. Use OnPlayerUpdate or Timer to update the PlayerTextDrawColor (You must use PlayerTextDrawShow to update changes)

Outline of Script
PHP код:
How the code would look:>
#define SMALL_BOXES_MADE 20
#define COLOR_EMPTY 0x00000077 //77 is the transperancy
#define COLOR_GOOD 0x0066ccFF //Can do this for the first 5 boxes
#define COLOR_AVG 0x00ff00FF //Can do this for the next 10 boxes
#define COLOR_MAX 0xcc3300FF //Can do this for the last 5 boxes
new PlayerText:SpeedoMeter[MAX_PLAYERS][SMALL_BOXES_MADE];
//Here 0 will be the smallest box
//19 will be the biggest
new Timer:x[MAX_PLAYERS];
OnPlayerConnect(playerid)
    
Create20SmallBoxes(playerid);
    
OnPlayerEnterVehicle(playerid ...)
    
ShowSmallBoxes(playerid);
    
x[playerid] = repeat Speedo(playerid);
    
OnPlayerExitVehicle(playerid ...)
{
    
HideSmallBoxes(playerid);
    
stop x[playerid];
}
//You can either use a Timer or onPlayerUpdate.. But timer is better for this case..
timer Speedo[500](playerid)
{
    if(
IsPlayerInAnyVehicle(playerid)) //Incase he was jacked or exited in ways that wouldnt trigger OnPlayerExitVehicle
    
{
        new 
vehicleid GetPlayerVehicleID(playerid);
        new 
modelid GetVehicleModel(vehicleid);
        new 
Float:maxspeed max_speed[modelid 400]; //However u store it
        
new speedtokens maxspeed SMALL_BOXES_MADE;
        
//Speedtokens decide at what speed ONE box's color has to be changed.
        
new Float:Currspeed GetPlayerSpeed(playerid); //However you get it
        
new BoxesToUpdate floatround(CurrSpeed speedtokensfloatround_round);
        for(new 
0SMALL_BOXES_MADEi++)
        {
            if(
<= BoxesToUpdate)
            {
                if(
5PlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_GOOD);
                else if(
15PlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_AVG);
                else if(
SMALL_BOXES_MADEPlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_MAX);
            }
            else
            {
                  
PlayerTextDrawBoxColor(playeridSpeedoMeter[playerid][i], COLOR_EMPTY);
            }
            
PlayerTextDrawShow(playeridSpeedoMeter[playerid][i]);
        }
    }
    else
    {
        
HideSmallBoxes(playerid);
        
stop x[playerid];
    }

This is the not the code.. This is to educate you on how its done.
It worked very well.



Re: The way to make this speedo? - Sithis - 20.03.2017

Good job! You clearly read the instructions and made this by yourself. This is what the scripting help section is about. +REP for following instructions and creating something by yourself


Re: The way to make this speedo? - DuyDang2412 - 21.03.2017

Quote:
Originally Posted by Sithis
Посмотреть сообщение
Good job! You clearly read the instructions and made this by yourself. This is what the scripting help section is about. +REP for following instructions and creating something by yourself
Thank you, buddy. If he hadn't help me, I wouldn't know how to do this.