help, speedometer function
#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


Messages In This Thread
help, speedometer function - by Coma - 20.05.2016, 23:32
Re: help, speedometer function - by WhiteGhost - 21.05.2016, 01:18
Re: help, speedometer function - by luke49 - 21.05.2016, 04:09
Re: help, speedometer function - by oMa37 - 21.05.2016, 07:06
Re: help, speedometer function - by CodeStyle175 - 21.05.2016, 07:30
Re: help, speedometer function - by luke49 - 21.05.2016, 07:50

Forum Jump:


Users browsing this thread: 2 Guest(s)