SA-MP Forums Archive
Custom Hud - 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: Custom Hud (/showthread.php?tid=663201)



Custom Hud - Volumen - 24.01.2019

I'm doing a custom "hud" for my server, which will hide the original of the game and show new images of the weapons (in version 0.3.DL). It will show the weapon that the player currently has in his hands. Where can I use this code to update it? Use the "OnPlayerUpdate" callback to update or use a "timer" in "OnPlayerConnect"?

What is more recommendable and efficient?


Re: Custom Hud - codExpert - 24.01.2019

well you only need to update players hud, when player switches to other weapon. So you create timer what compares players weapon at the moment and server side weapon, when they are different you update hud model.


Re: Custom Hud - Volumen - 24.01.2019

Yes, I know I have to update, that's why I ask the question. Should I use "OnPlayerUpdate" to update or should I use a "timer" in some callback? What is more advisable and efficient?

I explained everything in the publication!


Re: Custom Hud - codExpert - 24.01.2019

well i think i would go 1 sec timer, because onplayerupdate check rate is too high, but onplayerupdate could also use gettickcount to make it update in every 1 sec and other benefit is that it wont be called when player is afk.
you can try both methods and check what fits best for this system.


Re: Custom Hud - Volumen - 24.01.2019

Thank you!

Someone to give me a concrete answer of what I am asking, thank you very much.


Re: Custom Hud - Pottus - 24.01.2019

Quote:
Originally Posted by codExpert
View Post
well i think i would go 1 sec timer, because onplayerupdate check rate is too high, but onplayerupdate could also use gettickcount to make it update in every 1 sec and other benefit is that it wont be called when player is afk.
you can try both methods and check what fits best for this system.
What would be the point of that? You still have to call functions!

Code:
// Don't even worry about resetting this variable when a player connects
// Just make sure you update your TD'd when they spawn
static g_LastPlayerWeapon[MAX_PLAYERS] = 0;

public OnPlayerUpdate(playerid)
{
	// Just do the check to see if changed chances are it has not so it should
	// Generally be more efficient to call GetPlayerWeapon() twice than call it
	// Once and have to make an extra assignment operation everytime OPU is called
	if(GetPlayerWeapon(playerid) != g_LastPlayerWeapon[playerid])
	{
	    g_LastPlayerWeapon[playerid] = GetPlayerWeapon(playerid);
	    // Perform any actions here
	}
	return 1;
}
That is how it is done quick and easy and don't worry about that lagging the server it will be next to nothing. You need this system to update as fast as possible otherwise it is going to look stupid having excessive update delays.


Re: Custom Hud - Volumen - 24.01.2019

Oh thanks. This is the answer I was looking for. By the way, is not it necessary to use a timer instead of 'OnPlayerUpdate'?


Re: Custom Hud - Pottus - 24.01.2019

You want to update this when the player updates, this kind of feature needs to update as fast as possible yes a timer would work but OPU has a variable update rate depending on what the player is doing.


Re: Custom Hud - Volumen - 24.01.2019

Ok, I will use 'OnPlayerUpdate'. If I had used a timer, would it go to OnPlayerConnect?


Re: Custom Hud - Pottus - 24.01.2019

Quote:
Originally Posted by Volumen
View Post
Ok, I will use 'OnPlayerUpdate'. If I had used a timer, would it go to OnPlayerConnect?
Nope, in that case you would create one timer in OnGameModeInit() or OnFilterScriptInit() depending on your script. Then loop through all the players and perform any actions.