Xeirh
Veteran
- Messages
- 8
- Reaction score
- 4
- Points
- 793
C:
/*
*
* (unsigned)(hud - g_hudelems) < (unsigned)((18 * (31 + 31) + 192))
*
* this is the vm limit, let us break this down some. hopefully someone
* will find some of this useful, most of this will apply to other titles.
*
* 18: players
* 31: archive pool
* 31: non-archive pool
* 192: additional asset - only god knows
*
* by default ... if undefined, hudelems will default and use the archive pool.
* the archive pool is the most consistent in titles, nothing hardly messes with
* this pool. by default one hudelem from both pools is always reserved so you can
* hang up having the full pool. further, another one is gone as the cross hair is also
* one less hudelem in that pool. so the free archive pool is twenty-nine and always will
* be unless you mess with the pool or playing on zm_prison zclassic as another archived
* hudelem will be introduced know as self.client_hint so twenty-eight, so lets talk auto
* archive systems to switch between the pools.
*
*/
hudelem_count()
{
if( !isdefined( self.hudelem_count ) || self.hudelem_count < 0 )
self.hudelem_count = 0;
// easy right? but I want all the hudelems
return self.hudelem_count < 29;
}
hudelem_count()
{
if( !isdefined( self.hudelem_count ) || self.hudelem_count < 0 )
self.hudelem_count = 0;
pool = 30;
// checking the start location: if prison, it's classic, cellblock is grief
if( getdvar( "ui_zm_mapstartlocation" ) == "prison" )
pool = 29;
return self.hudelem_count < pool;
}
/*
*
* you can also get more complex by reassigning archive states based on self.client_hint
* being defined but I personally don't think this is worth it.
*
* zm_transit:
* - archived 29, non-archived 23
* zm_nuked:
* - archived 29, non-archived 23
* zm_prison:
* - archived 28, non-archived 23, archived 29 if not classic
* zm_buried:
* - archived 29, non-archived 23
* zm_highrise:
* - archived 29, non-archived 23
* zm_tomb:
* - archived 29, non-archived 23
*
*/
setpoint( point, x, y )
{
switch( point )
{
case "top_right":
self.alignx = "right";
self.aligny = "top";
break;
default:
self.alignx = "left";
self.aligny = "top";
break;
}
self.horzalign = "user_center";
self.vertalign = "user_top";
self.x = x;
self.y = y;
}
setclient_text( text, font, fontscale, point, x, y, color, sort, alpha )
{
element = newclienthudelem( self );
element.archived = self hudelem_count();
element.font = font;
element.fontscale = fontscale;
element.width = 0;
element.height = int( level.fontheight * fontscale );
element.color = color;
element.sort = sort;
element.alpha = alpha;
element.hidewheninmenu = true;
element.hidewheninscope = true;
element settext( text );
element setpoint( point, x, y );
self.hudelem_count++;
return element;
}
setclient_icon( shader, width, height, point, x, y, color, sort, alpha )
{
element = newclienthudelem( self );
element.archived = self hudelem_count();
element.width = width;
element.height = height;
element.color = color;
element.sort = sort;
element.alpha = alpha;
element.hidewheninmenu = true;
element.hidewheninscope = true;
element setshader( shader, width, height );
element setpoint( point, x, y );
self.hudelem_count++;
return element;
}
destroyelement( element )
{
element destroy();
self.hudelem_count--;
}
/*
*
* keep in mind: you do not need a fancy archive system, 28 elements is more
* than enough for anyone on earth. staying inside the archive pool also means
* full stealth.
*
*/
C:
index = self.cursor;
if( self attackbuttonpressed() != && self adsbuttonpressed() )
{
delta = 1;
if( self.structure.size > 1 )
{
if( self adsbuttonpressed() )
delta = -1;
self.cursor = ( index + self.structure.size + delta ) % self.structure.size;
}
wait 0.08;
}
/*
*
* wrapping with modulo:
*
* 0 % 5 = 0
* 1 % 5 = 1
* 2 % 5 = 2
* 3 % 5 = 3
* 4 % 5 = 4
* 5 % 5 = 0
* 6 % 5 = 1
* 7 % 5 = 2
* 8 % 5 = 3
* 9 % 5 = 4
*
* Keep in mind that this is slower than using statements, but the performance
* impact is negligible and nothing to worry about. modulo can also be somewhat
* fragile, but this usage should be perfectly safe.
*
*/
C:
/*
*
* was first fixed in vanguard, so any game below this title. when creating
* a element using parent and children via setparent will leak variables. this
* happens because the children array doesn't have a destructor, so the array
* will infinitely grow until you hit to 32 bit memory limit.
*
* another eazy fix is to just not contribute to parent and children, it's
* not like anyone used them for the correct reason anyways, this will save
* a lot of variables and you won't contribute to the leak.
*
* keep in mind that most of the _hud_utils depend on getparent(), using
* any of the functions will crash the game. check out hudelem allspark for
* my hud utils.
*
* self.parent = removechild( self ); should also work.
*
*/
addchild( element )
{
element.index = self.children.size;
self.children[ self.children.size ] = element;
self remove_destroyed_children();
}
removedestroyedchildren()
{
if( isdefined( self.childchecktime ) && self.childchecktime == gettime() )
return;
self.childchecktime = gettime();
tempchildren = [];
foreach( i, element in self.children )
{
if( !isdefined( element ) )
continue;
element.index = tempchildren.size;
tempchildren[ tempchildren.size ] = element;
}
self.children = tempchildren;
}
// here is the utils I personally use, these have reduced variable usage.
setpoint( point, x, y )
{
switch( point )
{
case "top_right":
self.alignx = "right";
self.aligny = "top";
break;
default:
self.alignx = "left";
self.aligny = "top";
break;
}
self.horzalign = "user_center";
self.vertalign = "user_top";
self.x = x;
self.y = y;
}
setclient_text( text, font, fontscale, point, x, y, color, sort, alpha )
{
element = newclienthudelem( self );
element.font = font;
element.fontscale = fontscale;
element.width = 0;
element.height = int( level.fontheight * fontscale );
element.color = color;
element.sort = sort;
element.alpha = alpha;
element.hidewheninmenu = true;
element.hidewheninscope = true;
element settext( text );
element setpoint( point, x, y );
return element;
}
setclient_icon( shader, width, height, point, x, y, color, sort, alpha )
{
element = newclienthudelem( self );
element.width = width;
element.height = height;
element.color = color;
element.sort = sort;
element.alpha = alpha;
element.hidewheninmenu = true;
element.hidewheninscope = true;
element setshader( shader, width, height );
element setpoint( point, x, y );
return element;
}
Attachments
Last edited: