3dtext update lag -
lucamsx - 09.11.2015
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;
}
Re: 3dtext update lag -
Ritzy2K - 10.11.2015
Call this every 10 ms?
Re: 3dtext update lag -
iKarim - 10.11.2015
Use a low interval timer or use OnPlayerUpdate.
I think you should use something like this.
PHP код:
// In filterscript init or gamemodeinit
SetTimer("UpdatePlayerNametag", 50, true);
forward UpdatePlayersNametag();
public UpdatePlayersNametag()
{
for(new i = GetPlayerPoolSize(); i > -1; i--)
{
if(IsPlayerConnected(playerid))
{
UpdatePlayerLabel(playerid);
}
}
return 1;
}
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;
}
Re: 3dtext update lag -
Ritzy2K - 10.11.2015
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", 50, true);
forward UpdatePlayersNametag();
public UpdatePlayersNametag()
{
for(new i = GetPlayerPoolSize(); i > -1; i--)
{
if(IsPlayerConnected(playerid))
{
UpdatePlayerLabel(playerid);
}
}
return 1;
}
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;
}
|
Should've used SetTimerEx.
Re: 3dtext update lag -
Kevln - 10.11.2015
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
Re: 3dtext update lag -
lucamsx - 10.11.2015
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.
Re: 3dtext update lag -
Ritzy2K - 10.11.2015
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.
Re: 3dtext update lag -
[ABK]Antonio - 10.11.2015
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.
Re: 3dtext update lag -
Ritzy2K - 10.11.2015
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.
Re: 3dtext update lag -
lucamsx - 10.11.2015
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?