3dtext update lag
#1

so i decided not to use sa-mp's player nametags and make my own ones using 3dtexts.
i've made a stock called UpdatePlayerLabel which updates players health & armour and puts them on the 3dtext.
now, the problem is, the 3dtext isn't updating correctly. for example if i shot my friend (he had 100 health pts) one time, with weapon that makes 10 dmg, he still had 100 hp on 3dtext even he really had 90 hp, and when i did it again, his 3dtext shows he now has 90hp when real amount is 80. how do i get rid of this update lag?
Код:
stock UpdatePlayerLabel(playerid)
{
	new Float:pHealth;
	new Float:pArmour;
	GetPlayerHealth(playerid, pHealth);
	GetPlayerArmour(playerid, pArmour);
	new naem[MAX_PLAYER_NAME];
	GetPlayerName(playerid, naem, sizeof(naem));
	format(stc,sizeof(stc),"\n\n\n{FFFFFF}%s\n{FF4040}%.0f/{9698FE}%.0f", naem, pHealth, pArmour);
	Update3DTextLabelText(PlayerLabel[playerid], 0xFFFFFFFF, stc);
	return 1;
}
Reply
#2

Call this every 10 ms?
Reply
#3

Use a low interval timer or use OnPlayerUpdate.
I think you should use something like this.
PHP код:
// In filterscript init or gamemodeinit
SetTimer("UpdatePlayerNametag"50true);
forward UpdatePlayersNametag();
public 
UpdatePlayersNametag()
{
    for(new 
GetPlayerPoolSize(); > -1i--)
    {
        if(
IsPlayerConnected(playerid))
        {
            
UpdatePlayerLabel(playerid);
        }
    }
    return 
1;
}
stock UpdatePlayerLabel(playerid)
{
    new 
Float:pHealth;
    new 
Float:pArmour;
    
GetPlayerHealth(playeridpHealth);
    
GetPlayerArmour(playeridpArmour);
    new 
naem[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnaemsizeof(naem));
    
format(stc,sizeof(stc),"\n\n\n{FFFFFF}%s\n{FF4040}%.0f/{9698FE}%.0f"naempHealthpArmour);
    
Update3DTextLabelText(PlayerLabel[playerid], 0xFFFFFFFFstc);
    return 
1;

Reply
#4

Quote:
Originally Posted by PawnHunter
Посмотреть сообщение
Use a low interval timer or use OnPlayerUpdate.
I think you should use something like this.
PHP код:
// In filterscript init or gamemodeinit
SetTimer("UpdatePlayerNametag"50true);
forward UpdatePlayersNametag();
public 
UpdatePlayersNametag()
{
    for(new 
GetPlayerPoolSize(); > -1i--)
    {
        if(
IsPlayerConnected(playerid))
        {
            
UpdatePlayerLabel(playerid);
        }
    }
    return 
1;
}
stock UpdatePlayerLabel(playerid)
{
    new 
Float:pHealth;
    new 
Float:pArmour;
    
GetPlayerHealth(playeridpHealth);
    
GetPlayerArmour(playeridpArmour);
    new 
naem[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnaemsizeof(naem));
    
format(stc,sizeof(stc),"\n\n\n{FFFFFF}%s\n{FF4040}%.0f/{9698FE}%.0f"naempHealthpArmour);
    
Update3DTextLabelText(PlayerLabel[playerid], 0xFFFFFFFFstc);
    return 
1;

Should've used SetTimerEx.
Reply
#5

There's no need to update the label every certain time when you got a callback that can initialize the process.

https://sampwiki.blast.hk/wiki/OnPlayerTakeDamage
Reply
#6

Quote:

There's no need to update the label every certain time when you got a callback that can initialize the process.

i'm already using this in OnPlayerTakeDamage, and that 'lag' is still happening.
Reply
#7

Use SetTimerEx dude. OnPlayerTakeDamage will be called e everytime a player is injured and therefore it will update everytime he is damaged. Call it under OnPlayerUpdate. Or maybe a settimerex.
Reply
#8

Quote:
Originally Posted by [ND]xXZeusXx.
Посмотреть сообщение
Use SetTimerEx dude. OnPlayerTakeDamage will be called e everytime a player is injured and therefore it will update everytime he is damaged. Call it under OnPlayerUpdate. Or maybe a settimerex.
OnPlayerUpdate & SetTimer will call it even when it doesn't need updated though. Dropping an if inside of OnPlayerTakeDamage will most likely see more benefits than dropping it into OnPlayerUpdate. OnPlayerUpdate can be called 25 times per second (usually is, unless they aren't moving). That's 25 extra checks that are happening even when it doesn't need updated. SetTimer will increase the delay of the label along with be called even if it doesn't need to be.
Reply
#9

Under OnPlayerTakeDamage it will be called only if a
Player gets damaged. And hence it will result in 3dtext update lag. Like it already is.
Reply
#10

nah, i already took care of update if player gains health etc. i just want to fix that update lag. is there anything wrong in my code?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)