deleted
deleted
Last edited by raphael; 27th February 2023 at 11:08.
Why are you storing client hud elems in level variables?
"Does not work" is an error report for a bug between keyboard and chair.
All hail Artie Effem
raphael (22nd March 2023)
I'm sorry I maybe shouldn't have deleted my message
Few minutes after posting, I found something and I thought maybe I should have think/search more before posting
This is the post I found and I think this is the way I should do to make my counter to work normally : https://www.ugx-mods.com/forum/scrip...7144#msg147144
Ftr, here is the insane code that I deleted in first post :
The issue is that values don't get updated properlyCode:main(phase, register) { codam\utils::_debug("NNNNNNNNNNNN Alive players counter/main"); switch(phase) { case "init": _init(register); break; } } _init(register) { codam\utils::_debug("NNNNNNNNNNNN Alive players counter/_init"); if (isdefined(level.showaliveplayerscount)) return; level.showaliveplayerscount = true; if (codam\utils::getVar("promod", "alivecounter", "bool", 1|2, false)) { if (getCvar("g_gametype") == "sd") { [[register]]("spawnPlayer", ::spawnPlayer, "thread"); [[register]]("gt_spawnSpectator", ::spawnSpectator, "thread"); } } } spawnPlayer(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9) { codam\utils::_debug("NNNNNNNNNNNN Alive players counter/spawnPlayer"); /*//Clean counter if (isdefined(level.promod_score)) { if (isdefined(level.promod_score["alivefriends"])) { level.promod_score["alivefriends"] destroy(); } if (isdefined(level.promod_score["aliveenemies"])) { level.promod_score["aliveenemies"] destroy(); } }*/ thread hudAlivePlayersCount(); } spawnSpectator(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9) { codam\utils::_debug("NNNNNNNNNNNN Alive players counter/spawnSpectator"); /*//Clean counter if (isdefined(level.promod_score)) { if (isdefined(level.promod_score["alivefriends"])) { level.promod_score["alivefriends"] destroy(); } if (isdefined(level.promod_score["aliveenemies"])) { level.promod_score["aliveenemies"] destroy(); } }*/ } hudAlivePlayersCount() { codam\utils::_debug("NNNNNNNNNNNN Alive players counter/hudAlivePlayersCount"); level endon("intermission"); wait(0.05); if (isdefined(level.gtd_call)) teams = [[level.gtd_call ]]("teamsPlaying"); if (!isdefined(teams) || (teams.size < 1)) { teams = []; teams[teams.size] = "allies"; teams[teams.size] = "axis"; } level.promod_score = []; iter = 0; for (;;) { displayAlivePlayersCount(teams, iter); iter = 1 - iter; wait(0.5); } } displayAlivePlayersCount(teams, iter) { numonteam = []; aliveonteam = []; players = getentarray("player", "classname"); for (i = 0; i < players.size; i++) { player = players[i]; team = player.sessionteam; if (!isdefined(team) || (team == "none")) { team = player.pers["team"]; if (!isdefined(team)) continue; } if (isdefined(numonteam[team])) numonteam[team ]++; else numonteam[team] = 1; if (player.sessionstate != "playing") continue; if (isdefined(aliveonteam[team])) aliveonteam[team]++; else aliveonteam[team] = 1; } for (i = 0; i < teams.size; i++) { _team = teams[i]; if (isPlayer(self) && isdefined(self.pers["team"])) { if (self.pers["team"] != "spectator") { if (self.pers["team"] == _team) { //FRIENDS if (!isdefined(level.promod_score["alivefriends"])) { //CREATE COUNTER _cf = newClientHudElem(self); _cf.x = 570; _cf.y = 75; _cf.fontScale = 1.5; _cf.color = (0.6, 1, 0); level.promod_score["alivefriends"] = _cf; } else { _cf = level.promod_score["alivefriends"]; } //SET COUNT if (isdefined(aliveonteam[_team])) { _cf setValue(aliveonteam[_team]); } else { _cf setValue(0); } } else { //ENEMIES if (!isdefined(level.promod_score["aliveenemies"])) { //CREATE COUNTER _ce = newClientHudElem(self); _ce.x = 610; _ce.y = 75; _ce.fontScale = 1.5; _ce.color = (1, 0.2, 0); level.promod_score["aliveenemies"] = _ce; } else { _ce = level.promod_score["aliveenemies"]; } //SET COUNT if (isdefined(aliveonteam[_team])) { _ce setValue(aliveonteam[_team]); } else { _ce setValue(0); } } } } } return; }
I will post the working code here if I manage to fix it
Thanks IzNoGoD, your question confirms that I should not store client hud elems in level variables (I'm new with gsc)
It is now sane
Here is the code:
Code://1. Put this file in the "codam" folder of the "main" server folder. //2. Add the below line to "modlist.gsc": //[[register]]("Alive players counter", codam\aliveplayers_counter::main); main(phase, register) { codam\utils::_debug("NNNNNNNNNNNN Alive players counter/main"); switch(phase) { case "init": _init(register); break; } } _init(register) { codam\utils::_debug("NNNNNNNNNNNN Alive players counter/_init"); if (isdefined(level.showaliveplayerscount)) return; level.showaliveplayerscount = true; if (getCvar("g_gametype") == "sd") { [[register]]("spawnPlayer", ::spawnPlayer, "thread"); [[register]]("gt_spawnSpectator", ::spawnSpectator, "thread"); } } spawnPlayer(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9) { codam\utils::_debug("NNNNNNNNNNNN Alive players counter/spawnPlayer"); thread hudAlivePlayersCount(); } spawnSpectator(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9) { codam\utils::_debug("NNNNNNNNNNNN Alive players counter/spawnSpectator"); //Clear counter if (isdefined(self.hud_counter_friends)) { self.hud_counter_friends destroy(); } if (isdefined(self.hud_counter_enemies)) { self.hud_counter_enemies destroy(); } } hudAlivePlayersCount() { codam\utils::_debug("NNNNNNNNNNNN Alive players counter/hudAlivePlayersCount"); level endon("death"); level endon("intermission"); wait(0.05); if (isdefined(level.gtd_call)) teams = [[level.gtd_call ]]("teamsPlaying"); if (!isdefined(teams) || (teams.size < 1)) { teams = []; teams[teams.size] = "allies"; teams[teams.size] = "axis"; } iter = 0; for (;;) { displayAlivePlayersCount(teams, iter); iter = 1 - iter; wait(0.5); } } displayAlivePlayersCount(teams, iter) { numonteam = []; aliveonteam = []; players = getentarray("player", "classname"); for (i = 0; i < players.size; i++) { player = players[i]; team = player.sessionteam; if (!isdefined(team) || (team == "none")) { team = player.pers["team"]; if (!isdefined(team)) continue; } if (isdefined(numonteam[team])) numonteam[team ]++; else numonteam[team] = 1; if (player.sessionstate != "playing") continue; if (isdefined(aliveonteam[team])) aliveonteam[team]++; else aliveonteam[team] = 1; } for (i = 0; i < teams.size; i++) { teamInLoop = teams[i]; if (teamInLoop != "spectator") { for (ii = 0; ii < players.size; ii++) { player = players[ii]; player_sTeam = player.sessionteam; if (player_sTeam != "spectator") { if (player_sTeam == teamInLoop) { //FRIENDS if (!isdefined(player.hud_counter_friends)) { //CREATE HUD hud[ii] = newClientHudElem(player); hud[ii].color = (0.6, 1, 0); hud[ii].x = 570; hud[ii].y = 75; hud[ii].fontScale = 1.5; player.hud_counter_friends = hud[ii]; } //SET VALUE if (isdefined(aliveonteam[teamInLoop])) { player.hud_counter_friends setValue(aliveonteam[teamInLoop]); } else { player.hud_counter_friends setValue(0); } } else { //ENEMIES if (!isdefined(player.hud_counter_enemies)) { //CREATE HUD hud[ii] = newClientHudElem(player); hud[ii].color = (1, 0.2, 0); hud[ii].x = 610; hud[ii].y = 75; hud[ii].fontScale = 1.5; player.hud_counter_enemies = hud[ii]; } //SET VALUE if (isdefined(aliveonteam[teamInLoop])) { player.hud_counter_enemies setValue(aliveonteam[teamInLoop]); } else { player.hud_counter_enemies setValue(0); } } } } } } return; }