PDA

View Full Version : [CoD4] Menu - Player Counter



DjTranceFire
8th March 2014, 18:31
Hey there.. :)
I'm trying to create a small counter in hud.menu to show the count of alive players.
I know there is:


(player(kills));

to track the kills of the player.
Is there something like that for menus to count the alive players?
Or did i have to use dvars to count it in codscript?

Tally
8th March 2014, 19:18
Hey there.. :)
I'm trying to create a small counter in hud.menu to show the count of alive players.
I know there is:


(player(kills));

to track the kills of the player.
Is there something like that for menus to count the alive players?
Or did i have to use dvars to count it in codscript?

You'd do better by using level hud elements to count the number of players alive. It can be done in a menu, but you would still need a loop function to constantly set the value of the menu item to show the correct number of players. And using menu items would necessitate running the function on all players. Using level hud elements, you run the function on the server, not the player. This is more cpu friendly.

level hud element to constantly show the number of players alive and dead on each team:


init()
{

thread UpdateTeamStatus();

}

UpdateTeamStatus()
{
level endon( "game_ended" );

icon_Y = 10;
deaths_icons_Y = 53;
player_Y = 33;
deaths_num_Y = 76;

for( ;; )
{
wait 1;

if( level.intermission )
{
level thread CleanUP();
break;
}

if( !isdefined( level.axisicon ) ) ////////////////////////////// team icon
{
level.axisicon = newHudElem();
level.axisicon.x = 629;
level.axisicon.y = icon_Y;
level.axisicon.alignX = "right";
level.axisicon.alignY = "top";
level.axisicon.horzAlign = "fullscreen";
level.axisicon.vertAlign = "fullscreen";
level.axisicon.hideWhenInMenu = true;
level.axisicon.alpha = 0.8;
level.axisicon setShader( game["icons"]["axis"], 20, 20 );
}

if( !isdefined( level.deadaxisicon ) ) //////////////////////////// deaths icon
{
level.deadaxisicon = newHudElem();
level.deadaxisicon.x = 629;
level.deadaxisicon.y = deaths_icons_Y;
level.deadaxisicon.alignX = "right";
level.deadaxisicon.alignY = "top";
level.deadaxisicon.horzAlign = "fullscreen";
level.deadaxisicon.vertAlign = "fullscreen";
level.deadaxisicon.alpha = 0.8;
level.deadaxisicon.hideWhenInMenu = true;
level.deadaxisicon.hidden = false;
level.deadaxisicon setShader( game["deathicon"], 20, 20 );
}

if( !isdefined( level.axisnumber ) ) ///////////////////////////// player number
{
level.axisnumber = newHudElem();
level.axisnumber.x = 622;
level.axisnumber.y = player_Y;
level.axisnumber.alignX = "right";
level.axisnumber.alignY = "top";
level.axisnumber.horzAlign = "fullscreen";
level.axisnumber.vertAlign = "fullscreen";
level.axisnumber.font = "default";
level.axisnumber.hideWhenInMenu = true;
level.axisnumber.fontscale = 1.4;
level.axisnumber setValue( 0 );
}

if( !isdefined( level.deadaxisnumber ) ) /////////////////////////// deaths number
{
level.deadaxisnumber = newHudElem();
level.deadaxisnumber.x = 622;
level.deadaxisnumber.y = deaths_num_Y;
level.deadaxisnumber.alignX = "right";
level.deadaxisnumber.alignY = "top";
level.deadaxisnumber.horzAlign = "fullscreen";
level.deadaxisnumber.vertAlign = "fullscreen";
level.deadaxisnumber.font = "default";
level.deadaxisnumber.hideWhenInMenu = true;
level.deadaxisnumber.fontscale = 1.4;
level.deadaxisnumber.color = ( 1, 1, 0 );
level.deadaxisnumber setValue( 0 );
}

//################################################## ###########################

if( !isdefined( level.alliedicon ) ) ////////////////////////////// team icon
{
level.alliedicon = newHudElem();
level.alliedicon.x = 605;
level.alliedicon.y = icon_Y;
level.alliedicon.alignX = "right";
level.alliedicon.alignY = "top";
level.alliedicon.horzAlign = "fullscreen";
level.alliedicon.vertAlign = "fullscreen";
level.alliedicon.hideWhenInMenu = true;
level.alliedicon.alpha = 0.8;
level.alliedicon setShader( game["icons"]["allies"], 20, 20 );
}

if( !isdefined( level.deadalliesicon ) ) //////////////////////////// deaths icon
{
level.deadalliesicon = newHudElem();
level.deadalliesicon.x = 605;
level.deadalliesicon.y = deaths_icons_Y;
level.deadalliesicon.alignX = "right";
level.deadalliesicon.alignY = "top";
level.deadalliesicon.horzAlign = "fullscreen";
level.deadalliesicon.vertAlign = "fullscreen";
level.deadalliesicon.hideWhenInMenu = true;
level.deadalliesicon.alpha = 0.8;
level.deadalliesicon setShader( game["deathicon"], 20, 20 );
}

if( !isdefined( level.alliednumber ) ) ///////////////////////////// player number
{
level.alliednumber = newHudElem();
level.alliednumber.x = 598;
level.alliednumber.y = player_Y;
level.alliednumber.alignX = "right";
level.alliednumber.alignY = "top";
level.alliednumber.horzAlign = "fullscreen";
level.alliednumber.vertAlign = "fullscreen";
level.alliednumber.font = "default";
level.alliednumber.hideWhenInMenu = true;
level.alliednumber.fontscale = 1.4;
level.alliednumber setValue( 0 );
}

if( !isdefined( level.deadalliednumber ) ) /////////////////////////// deaths number
{
level.deadalliednumber = newHudElem();
level.deadalliednumber.x = 598;
level.deadalliednumber.y = deaths_num_Y;
level.deadalliednumber.alignX = "right";
level.deadalliednumber.alignY = "top";
level.deadalliednumber.horzAlign = "fullscreen";
level.deadalliednumber.vertAlign = "fullscreen";
level.deadalliednumber.font = "default";
level.deadalliednumber.hideWhenInMenu = true;
level.deadalliednumber.fontscale = 1.4;
level.deadalliednumber.color = ( 1, 1, 0 );
level.deadalliednumber setValue( 0 );
}

allies = [];
axis = [];
deadallies = [];
deadaxis = [];

for(i = 0; i < level.players.size; i++)
{
if( level.players[i].sessionstate == "playing" && level.players[i].sessionteam == "allies" )
allies[ allies.size ] = level.players[i];
if( level.players[i].sessionstate != "playing" && level.players[i].sessionteam == "allies" )
deadallies[deadallies.size] = level.players[i];
if( level.players[i].sessionstate == "playing" && level.players[i].sessionteam == "axis" )
axis[ axis.size ] = level.players[i];
if( level.players[i].sessionstate != "playing" && level.players[i].sessionteam == "axis" )
deadaxis[ deadaxis.size ] = level.players[i];
}

level.axisnumber setValue( axis.size );
level.alliednumber setValue( allies.size );
level.deadaxisnumber setValue( deadaxis.size );
level.deadalliednumber setValue( deadallies.size );
}
}

CleanUP()
{
if( isdefined( level.axisicon ) ) level.axisicon destroy();
if( isdefined( level.axisnumber ) ) level.axisnumber destroy();
if( isdefined( level.deadaxisicon ) ) level.deadaxisicon destroy();
if( isdefined( level.deadaxisnumber ) ) level.deadaxisnumber destroy();
if( isdefined( level.alliedicon ) ) level.alliedicon destroy();
if( isdefined( level.alliednumber ) ) level.alliednumber destroy();
if( isdefined( level.deadalliesicon ) ) level.deadalliesicon destroy();
if( isdefined( level.deadalliednumber ) ) level.deadalliednumber destroy();
}

DjTranceFire
12th March 2014, 20:09
Thank you its working fine! :)
Is there something build in to get a health-indicator with numbers in it?