tincxd

handling hud elements

Recommended Posts

I cant really find any good reference to the hud elements and so i'v been struggling a lot with adding additional hud elements to the mod, my question is, what is he best way to write such scripts.

Example:

The goal of this script is to create a couple of elements, that are visible only at strattime and then destroyed.

player thread exampleInit();

exampleInit(){
	self endon ("disconnect");
	self endon ("death");
	self waittill("spawned_player");
	
	/*Should loadoutInfoHudElem be thread? also should they have "self" */
	loadoutInfoHudElem("Primary weapon", "m40a3", "weapon_remington700", "gun", -80, 120, "cutbox_bg_hud", 170, 140, 0.5, true);
	loadoutInfoHudElem("Primary weapon", "m40a3", "weapon_remington700", "gun", -80, 120, "cutbox_bg_hud", 170, 140, 0.5, true);
}

loadoutInfoHudElem(header, itemname, item, itemtype, x, y, shader, shaderw, shaderh, alpha, him){
	/*should elements have "self"? If they dont i get a error: "not an entity", is there a way around that?*/
	self.bck = newHudElem();
	/*elem code*/

	self.item = newHudElem();
	/*elem code*/

	self.itemName = newHudElem();
	/*elem code*/

	/*if i try to destroy them here i get an error saying "removed entity is not an entity"*/
}

If anyone has time to answer, thank you :)

 

Share this post


Link to post
Share on other sites

You don't have to thread the creation of a hud elem. Except you put a loop into it which monitors a value/text change then you should thread it to keep the main function running.

 

A hud elem does not require an entity (self in your case) when it's a global hud.

The Syntax ist then:

Whatever = NewHudElem()

In case you want to make it visible for a certain player only then you need an entity.

The syntax then is :

Whatever = newClientHudElem(Player)

 

You still don't need to do self.whatever, except you want to share the Information between functions.

 

 

I guess you get that error about the removed entity because self, propably a player you assigned the hud to, does not exist anymore.

 

 

 

Share this post


Link to post
Share on other sites
22 minutes ago, Viking said:

You don't have to thread the creation of a hud elem. Except you put a loop into it which monitors a value/text change then you should thread it to keep the main function running.

 

A hud elem does not require an entity (self in your case) when it's a global hud.

The Syntax ist then:

Whatever = NewHudElem()

In case you want to make it visible for a certain player only then you need an entity.

The syntax then is :

Whatever = newClientHudElem(Player)

 

You still don't need to do self.whatever, except you want to share the Information between functions.

 

 

I guess you get that error about the removed entity because self, propably a player you assigned the hud to, does not exist anymore.

 

 

 

Thank you, this helped :) Whatever = newClientHudElem(Player)

Another question tho, how does the number of added hud elements impact the mod/server? Can the max cap be increased?

Share this post


Link to post
Share on other sites
Posted (edited)

I am not sure but i have a Max of 16 in mind. However, i have seen a variable in a gsc (or was it the cod4x source) which sets the limit.

Maybe changing it will increase it.

 

I try to find it.

 

Edit: it's an engine limit of 32.

https://wiki.zeroy.com/index.php?title=Call_of_Duty_5:_Engine_Limitation

 

16 was the minimap icons then I guess.

Edited by Viking
  • Like 1

Share this post


Link to post
Share on other sites
1 hour ago, Viking said:

I am not sure but i have a Max of 16 in mind. However, i have seen a variable in a gsc (or was it the cod4x source) which sets the limit.

Maybe changing it will increase it.

 

I try to find it.

 

Edit: it's an engine limit of 32.

https://wiki.zeroy.com/index.php?title=Call_of_Duty_5:_Engine_Limitation

 

16 was the minimap icons then I guess.

Tanks for info :)

Share this post


Link to post
Share on other sites

Yes 16 compass icons per side in team games. In one of the gscs, I think game objects, it checks for the current number of icons in use and returns false if all are taken.

Whether or not that can be increased in cod4x, that would be useful indeed. 16 is a lot for a typical game but when you include games like freezetag an increased number of compass icons could come in handy.

Share this post


Link to post
Share on other sites
7 hours ago, Sheryl said:

Yes 16 compass icons per side in team games. In one of the gscs, I think game objects, it checks for the current number of icons in use and returns false if all are taken.

Whether or not that can be increased in cod4x, that would be useful indeed. 16 is a lot for a typical game but when you include games like freezetag an increased number of compass icons could come in handy.

So how many hud elements out of 32 are taken by default for a player?

Share this post


Link to post
Share on other sites
10 hours ago, tincxd said:

So how many hud elements out of 32 are taken by default for a player?

long time since i played around with that .. i believe it was ~20ish that were free mostly. you can easily create a loop that creates as many hudelements as possible, once the limit is reached hudelements just won't appear on the screen anymore. no script error is thrown if you exceed the limit, they just won't appear on the screen.

Share this post


Link to post
Share on other sites
2 hours ago, dpj said:

long time since i played around with that .. i believe it was ~20ish that were free mostly. you can easily create a loop that creates as many hudelements as possible, once the limit is reached hudelements just won't appear on the screen anymore. no script error is thrown if you exceed the limit, they just won't appear on the screen.

Yep they dissapear, but that is't really the desired effect :P. If you saw the strattime script i made, it takes around 10 elements, and in the first round 20...

Do you maybe know if adding too much elements badly effects the server or mod....performance?

Have you ever seen or heard of a way to increase the engine limits?

Share this post


Link to post
Share on other sites

Nah, there are predefined 32 positions that are synchronized each server frame so it doesn't matter if it contains something useful or just a placeholder. This one is not too easy to increment.

Edited by T-Max

Share this post


Link to post
Share on other sites

offtopic question...

Elements (shown in-game) like map, ammo counter, website text, weapon name... are hud elements?

Hypothetically, you could use a menu to create more elements for a player (in-game), since there's no limit to them? Would that be doable?

Share this post


Link to post
Share on other sites

Most of the ingame elements are menus (Hud.menu)

 

Yep doable, but you have to send the info to the client. Depending on your mod that might not be the best idea (overflow)

Share this post


Link to post
Share on other sites
16 minutes ago, Viking said:

Most of the ingame elements are menus (Hud.menu)

 

Yep doable, but you have to send the info to the client. Depending on your mod that might not be the best idea (overflow)

Well the thing in question here is this script i'v made

68747470733a2f2f692e696d6775722e636f6d2f

Which shows loadout to player at strattime, and it takes 4 hudelements per item which is too much.

Code: https://github.com/MartinKogovsek/promodUntitled/blob/master/raw-promodUntitled/misc_scripts/strat/loadoutInfo.gsc

 

If i were to convert this to a .menu, at which point would a overflow occur? What info do i have to send?

Share this post


Link to post
Share on other sites

You wont have an overflow with that, don't worry.

 

The background and the titles are constant, so you don't have to send them to the client.

For the weapon images and the weapon namens i would send two dvars to the client which contain the weapons.

You can then extract the remaining data from the game stringtables, just like the class selection menu does.

 

And for all of them you use a visArg that is set when strat begins (or the player joins during strat) and gets removed when strat ends.

 

 

Edit: the menu itself is not a problem, the overflow happens when you send a lot of info to the client in a short period of time.

Using a lot of Setclientdvar at once for example.

Edited by Viking

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.