help, speedometer function
#1

hello people, speedometer function pleasee
Quote:

Textdraw7 = TextDrawCreate(230.799987, 403.953308, "usebox");
TextDrawLetterSize(Textdraw7, 0.000000, 1.591485);
TextDrawTextSize(Textdraw7, 129.199996, 0.000000);
TextDrawAlignment(Textdraw7, 1);
TextDrawColor(Textdraw7, 0);
TextDrawUseBox(Textdraw7, true);
TextDrawBoxColor(Textdraw7, 102);
TextDrawSetShadow(Textdraw7, 0);
TextDrawSetOutline(Textdraw7, 0);
TextDrawFont(Textdraw7, 0);

Textdraw8 = TextDrawCreate(139.199981, 403.946777, "1000 ~w~Km/h");
TextDrawLetterSize(Textdraw8, 0.415599, 1.473066);
TextDrawAlignment(Textdraw8, 1);
TextDrawColor(Textdraw8, -16776961);
TextDrawSetShadow(Textdraw8, 0);
TextDrawSetOutline(Textdraw8, 1);
TextDrawBackgroundColor(Textdraw8, 51);
TextDrawFont(Textdraw8, 1);
TextDrawSetProportional(Textdraw8, 1);

Reply
#2

What do u want us to do make it for you?
Reply
#3

PHP код:
for(new 0GetMaxPlayers(); i++)
{
    
//more textdraws before
    
    
Textdraw7 TextDrawCreate(230.799987403.953308"usebox"); //box
    
TextDrawLetterSize(Textdraw70.0000001.591485);
    
TextDrawTextSize(Textdraw7129.1999960.000000);
    
TextDrawAlignment(Textdraw71);
    
TextDrawColor(Textdraw70);
    
TextDrawUseBox(Textdraw7true);
    
TextDrawBoxColor(Textdraw7102);
    
TextDrawSetShadow(Textdraw70);
    
TextDrawSetOutline(Textdraw70);
    
TextDrawFont(Textdraw70);
    for(new 
0GetMaxPlayers(); i++)
    {
        
Textdraw8[i] = TextDrawCreate(139.199981403.946777""); //speed
        
TextDrawLetterSize(Textdraw8[i], 0.4155991.473066);
        
TextDrawAlignment(Textdraw8[i], 1);
        
TextDrawColor(Textdraw8[i], -16776961);
        
TextDrawSetShadow(Textdraw8[i], 0);
        
TextDrawSetOutline(Textdraw8[i], 1);
        
TextDrawBackgroundColor(Textdraw8[i], 51);
        
TextDrawFont(Textdraw8[i], 1);
        
TextDrawSetProportional(Textdraw8[i], 1);
        
        
//more textdraws, such as fuel, health and etc.
    
}

PHP код:
public OnPlayerStateChange(playeridnewstateoldstate)
{
    if(
newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) {
        
TextDrawShowForPlayer(playeridTextdraw7); //show box
        
for(new 0MAX_PLAYERSi++)
        {
            
TextDrawShowForPlayer(playeridTextdraw8[playerid]); //show speed
        
}
    }
    else if(
oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER) {
        
TextDrawHideForPlayer(playerid,  Textdraw7); //show box
        
for(new 0MAX_PLAYERSi++)
        {
            
TextDrawHideForPlayer(playerid,  Textdraw8[playerid]); //show speed
        
}
    }

PHP код:
//after public OnGameModeInit()
SetTimer("speedoUpdate"10true); //the bigger number is, the slower speedometer will be (this is time in milliseconds). 
PHP код:
//somewhere at the bottom of your script
forward speedoUpdate(playerid);
public 
speedoUpdate(playerid)
{
    for(new 
0MAX_PLAYERSi++)
    {
        if(
IsPlayerConnected(i) && IsPlayerInAnyVehicle(i))
        {
            new 
string  32 ],
            
format(stringsizeof(string), "%d"GetPlayerSpeed(i0)); //set string for Texdraw8
            
TextDrawSetString(Texdraw8[i], string);
        }
    }
    return 
1;

PHP код:
stock GetPlayerSpeed(playeridget3d//get player speed
{
    new
        
Float:x,
        
Float:y,
        
Float:z;
    if(
IsPlayerInAnyVehicle(playerid))
        
GetVehicleVelocity(GetPlayerVehicleID(playerid), xyz);
    else
        
GetPlayerVelocity(playeridxyz);
    return 
SpeedCheck(xyz100.0get3d);

Reply
#4

Quote:
Originally Posted by luke49
Посмотреть сообщение
[PHP]
PHP код:
//after public OnGameModeInit()
SetTimer("speedoUpdate"10true); //the bigger number is, the slower speedometer will be (this is time in milliseconds). 
Put this under OnPlayerUpdate

PHP код:
speedoUpdate(playerid); 
Reply
#5

i think that you only need around 100-300ms, no need to go 10ms. Dont use global textdraws, when dealing with different values, every single player, so use CreatePlayerTextDraw.

PHP код:
new Text:spbox;
new 
PlayerText:speedometer[MAX_PLAYERS];
public 
OnPlayerConnect(playerid){
     
speedometer[playerid]=CreatePlayerTextDraw(playerid,139.19403.94""); //speed 
     
PlayerTextDrawLetterSize(playerid,speedometer[playerid], 0.4155991.473066); 
     
PlayerTextDrawAlignment(playerid,speedometer[playerid], 1); 
     
PlayerTextDrawColor(playerid,speedometer[playerid], -16776961); 
     
PlayerTextDrawSetShadow(playerid,speedometer[playerid], 0); 
     
PlayerTextDrawSetOutline(playerid,speedometer[playerid], 1); 
     
PlayerTextDrawBackgroundColor(playerid,speedometer[playerid], 51); 
     
PlayerTextDrawFont(playerid,speedometer[playerid], 1); 
     
PlayerTextDrawSetProportional(playerid,speedometer[playerid], 1); 
     return 
1;
}
public 
OnGameModeInit(){
     
SetTimer("Update02sec",200,true);     
     
spbox TextDrawCreate(230.79403.95"_"); //box 
     
TextDrawLetterSize(spbox0.01.591485); 
     
TextDrawTextSize(spbox129.1999960.0); 
     
TextDrawAlignment(spbox1); 
     
TextDrawColor(spbox0); 
     
TextDrawUseBox(spboxtrue); 
     
TextDrawBoxColor(spbox102); 
     
TextDrawSetShadow(spbox0); 
     
TextDrawSetOutline(spbox0); 
     
TextDrawFont(spbox0); 
     return 
1;
}
public 
OnPlayerStateChange(playerid){
     if(
newstate==PLAYER_STATE_DRIVER || newstate==PLAYER_STATE_PASSENGER){
          
PlayerTextDrawShow(playerid,speedometer[playerid]);        
      
TextDrawShowForPlayer(playerid,spbox);
     }
     if(
newstate==PLAYER_STATE_ONFOOT){
          
PlayerTextDrawHide(playerid,speedometer[playerid]);        
      
TextDrawHideForPlayer(playerid,spbox);
     }
     return 
1;
}
forward Update02sec();
public 
Update02sec(){
     new 
str[20];
     for(new 
i;i<MAX_PLAYERS;i++){
          if(!
IsPlayerConnected(i) || !IsPlayerInAnyVehicle(i))continue;
          
format(str,sizeof(str),"speed: %d",GetVehSpeed(GetPlayerVehicleID(i));
          
PlayerTextDrawSetString(i,speedometer[i],str);
     }
     return 
1;
}
GetVehSpeed(vid){
    new 
Float:pos[3];
    
GetVehicleVelocity(vid,pos[0],pos[1],pos[2]);
    return 
floatround(floatsqroot(pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]) * 180.0);

Reply
#6

Quote:
Originally Posted by CodeStyle175
Посмотреть сообщение
i think that you only need around 100-300ms, no need to go 10ms. Dont use global textdraws, when dealing with different values, every single player, so use CreatePlayerTextDraw.

PHP код:
new Text:spbox;
new 
PlayerText:speedometer[MAX_PLAYERS];
public 
OnPlayerConnect(playerid){
     
speedometer[playerid]=CreatePlayerTextDraw(playerid,139.19403.94""); //speed 
     
PlayerTextDrawLetterSize(playerid,speedometer[playerid], 0.4155991.473066); 
     
PlayerTextDrawAlignment(playerid,speedometer[playerid], 1); 
     
PlayerTextDrawColor(playerid,speedometer[playerid], -16776961); 
     
PlayerTextDrawSetShadow(playerid,speedometer[playerid], 0); 
     
PlayerTextDrawSetOutline(playerid,speedometer[playerid], 1); 
     
PlayerTextDrawBackgroundColor(playerid,speedometer[playerid], 51); 
     
PlayerTextDrawFont(playerid,speedometer[playerid], 1); 
     
PlayerTextDrawSetProportional(playerid,speedometer[playerid], 1); 
     return 
1;
}
public 
OnGameModeInit(){
     
SetTimer("Update02sec",200,true);     
     
spbox TextDrawCreate(230.79403.95"_"); //box 
     
TextDrawLetterSize(spbox0.01.591485); 
     
TextDrawTextSize(spbox129.1999960.0); 
     
TextDrawAlignment(spbox1); 
     
TextDrawColor(spbox0); 
     
TextDrawUseBox(spboxtrue); 
     
TextDrawBoxColor(spbox102); 
     
TextDrawSetShadow(spbox0); 
     
TextDrawSetOutline(spbox0); 
     
TextDrawFont(spbox0); 
     return 
1;
}
public 
OnPlayerStateChange(playerid){
     if(
newstate==PLAYER_STATE_DRIVER || newstate==PLAYER_STATE_PASSENGER){
          
PlayerTextDrawShow(playerid,speedometer[playerid]);        
      
TextDrawShowForPlayer(playerid,spbox);
     }
     if(
newstate==PLAYER_STATE_ONFOOT){
          
PlayerTextDrawHide(playerid,speedometer[playerid]);        
      
TextDrawHideForPlayer(playerid,spbox);
     }
     return 
1;
}
forward Update02sec();
public 
Update02sec(){
     new 
str[20];
     for(new 
i;i<MAX_PLAYERS;i++){
          if(!
IsPlayerConnected(i) || !IsPlayerInAnyVehicle(i))continue;
          
format(str,sizeof(str),"speed: %d",GetVehSpeed(GetPlayerVehicleID(i));
          
PlayerTextDrawSetString(i,speedometer[i],str);
     }
     return 
1;
}
GetVehSpeed(vid){
    new 
Float:pos[3];
    
GetVehicleVelocity(vid,pos[0],pos[1],pos[2]);
    return 
floatround(floatsqroot(pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]) * 180.0);

Well, it is true that we have to use CreatePlayerTextDraw function when we deal with different values, but setting update speed to 100-300 ms will cause a bit slowly speedometer (as I know from my experience) - "0 kph - 6 kph - 15 kph - ..." - that is why I recommend 10-100 ms - speedometer will be perfectly running without any lagg.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)