Custom Hud
#1

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?
Reply
#2

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.
Reply
#3

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!
Reply
#4

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.
Reply
#5

Thank you!

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

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.
Reply
#7

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

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.
Reply
#9

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

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)