HUD killstreak Player
-
I have been looking for this for a long time and I think I could do it, so I share with you I know that I am not the only one who needed it.
I have relied on coding found in this same forum and the guides given.Credits: https://forum.plutonium.pw/topic/2113/storing-players-data-with-chaiscript/3
:: CODE UPDATE :: 23-05-2021 ::
Now correctly registers the kills that the player gets when he has a hard line pro and gets 2 assists counting as kill/* * Black Ops 2 - GSC Studio by iMCSx * * Creator : Kalitos * Project : killstreakHUD * Mode : Multiplayer * Date : 2021/05/15 - 11:22:19 * */ #include maps\mp\gametypes\_hud_util; init() { level thread onPlayerConnect(); } onPlayerConnect() { for(;;) { level waittill("connected", player); player thread killstreakPlayer(); } } killstreakPlayer () { self endon ("disconnect"); level endon("game_ended"); self.hudkillstreak = createFontString ("Objective", 1); self.hudkillstreak setPoint ("CENTER", "TOP", "CENTER", 10); self.hudkillstreak.label = &"^2 KILLSTREAK: ^7"; while(true) { self.hudkillstreak setValue(self.pers["cur_kill_streak"]); wait 0.5; } }
To implement it they must create a .GSC file and paste the code in it, then follow the guide on how to load a scripthere
-
Kalitos This code can be improved, self.killstreaks in onPlayerConnected does not make any sense. It is also completely useless since it is a value you take from a function. Just use that function and you're done.
Also, as far as anything goes, if you can avoid non-stop loops, that's better. In this case you just need to see when an enemy is killed to update the value./* * Black Ops 2 - GSC Studio by iMCSx * * Creator : Kalitos * Project : killstreakHUD * Mode : Multiplayer * Date : 2021/05/15 - 11:22:19 * */ #include maps\mp\gametypes\_hud_util; init() { level thread onPlayerConnect(); } onPlayerConnect() { for(;;) { level waittill("connected", player); player thread killstreakPlayer(); } } killstreakPlayer () { self endon ("disconnect"); level endon("game_ended"); hudkillstreak = createFontString ("Objective", 1); hudkillstreak setPoint ("CENTER", "TOP", "CENTER", 10); hudkillstreak.label = &"^2 KILLSTREAK: ^7"; while (true) { self waittill_any("killed_enemy", "spawned_player"); hudkillstreak setValue(self getPlayerData("killstreaksState","count")); } }
-
Kalitos This code can be improved, self.killstreaks in onPlayerConnected does not make any sense. It is also completely useless since it is a value you take from a function. Just use that function and you're done.
Also, as far as anything goes, if you can avoid non-stop loops, that's better. In this case you just need to see when an enemy is killed to update the value./* * Black Ops 2 - GSC Studio by iMCSx * * Creator : Kalitos * Project : killstreakHUD * Mode : Multiplayer * Date : 2021/05/15 - 11:22:19 * */ #include maps\mp\gametypes\_hud_util; init() { level thread onPlayerConnect(); } onPlayerConnect() { for(;;) { level waittill("connected", player); player thread killstreakPlayer(); } } killstreakPlayer () { self endon ("disconnect"); level endon("game_ended"); hudkillstreak = createFontString ("Objective", 1); hudkillstreak setPoint ("CENTER", "TOP", "CENTER", 10); hudkillstreak.label = &"^2 KILLSTREAK: ^7"; while (true) { self waittill_any("killed_enemy", "spawned_player"); hudkillstreak setValue(self getPlayerData("killstreaksState","count")); } }
Sorex you'd want to wait for player spawn also, so the value is updated if they die or switch teams
-
birchy I do not remeber if killstreaks on iw5 keep going also if player die. idk so if not happen its needed another system to reset the value
-
birchy I do not remeber if killstreaks on iw5 keep going also if player die. idk so if not happen its needed another system to reset the value
Sorex what i'm saying is you only get the new value on player_killed, so the HUD won't be updated if the player switches team or dies
-
Sorex said in HUD killstreak Player:
self getPlayerData("killstreaksState","count")
this will only get killstreak toward killstreaks as in UAV and all that stuff, so if ur highest selected killstreak is let's say a osprey gunner which is a 18 killstreak, once u get to that, this will reset back to 0, so i'd just use self.pers["cur_kill_streak"]
-
Thanks for the info, good to know
-
I have been looking for this for a long time and I think I could do it, so I share with you I know that I am not the only one who needed it.
I have relied on coding found in this same forum and the guides given.Credits: https://forum.plutonium.pw/topic/2113/storing-players-data-with-chaiscript/3
:: CODE UPDATE :: 23-05-2021 ::
Now correctly registers the kills that the player gets when he has a hard line pro and gets 2 assists counting as kill/* * Black Ops 2 - GSC Studio by iMCSx * * Creator : Kalitos * Project : killstreakHUD * Mode : Multiplayer * Date : 2021/05/15 - 11:22:19 * */ #include maps\mp\gametypes\_hud_util; init() { level thread onPlayerConnect(); } onPlayerConnect() { for(;;) { level waittill("connected", player); player thread killstreakPlayer(); } } killstreakPlayer () { self endon ("disconnect"); level endon("game_ended"); self.hudkillstreak = createFontString ("Objective", 1); self.hudkillstreak setPoint ("CENTER", "TOP", "CENTER", 10); self.hudkillstreak.label = &"^2 KILLSTREAK: ^7"; while(true) { self.hudkillstreak setValue(self.pers["cur_kill_streak"]); wait 0.5; } }
To implement it they must create a .GSC file and paste the code in it, then follow the guide on how to load a scripthere
Kalitos You should do it like this, this way it does not update all the time
KillstreakPlayer()
{
self endon ("disconnect");
level endon("game_ended");
self.hudkillstreak = createFontString( "Objective", 1 );
self.hudkillstreak setPoint( "CENTER", "TOP", "CENTER", 10 );
self.hudkillstreak.label = &"^2 KILLSTREAK: ^7";
while(true)
{
if(self.playerstreak != self.pers["cur_kill_streak"])
{
self.playerstreak = self.pers["cur_kill_streak"];
self.hudkillstreak setValue(self.pers["cur_kill_streak"]);
}
wait 0.01;
}
} -
I fixed the warnings in the console, I included the explanations at the bottom for those who are curious about it.
I also made it not unnecessarily thread on bots, just a small performance "fix"
Kalitos Maybe this will interest you or maybe you wanna update your script on the OP#include maps\mp\gametypes\_hud_util; Init() { level thread OnPlayerConnected(); } OnPlayerConnected() { for(;;) { level waittill("connected", player); // Don't thread DisplayPlayerKillstreak() on bots if (isDefined(player.pers["isBot"])) { if (player.pers["isBot"]) { continue; // skip } } player thread DisplayPlayerKillstreak(); } } DisplayPlayerKillstreak() { self endon ("disconnect"); level endon("game_ended"); self.killstreak_text = createFontString( "Objective", 0.65 ); self.killstreak_text setPoint( 0, "TOP", 0, 7.5 ); self.killstreak_text.label = &"^1KILLSTREAK: "; while(true) { if(!IsDefined(self.playerstreak) || self.playerstreak != self.pers["cur_kill_streak"]) { self.playerstreak = self.pers["cur_kill_streak"]; self.killstreak_text setValue(self.pers["cur_kill_streak"]); } wait 0.01; } }
For some reason the game seems to throw a warning when you pass "CENTER" in the setPoint function so I replaced it with 0.
This was happening because when doing thisif(self.playerstreak != self.pers["cur_kill_streak"]) { self.playerstreak = self.pers["cur_kill_streak"]; self.killstreak_text setValue(self.pers["cur_kill_streak"]); }
the first time the playerstreak variable isn't defined yet because it's a variable created by the script in that if condition.
So to make sure the script works normally I added another case!IsDefined(self.playerstreak) ||
so that it will work both when our HUD needs to be updated and also when our variable isn't defined yet (first iteration)
Same than above, when comparing undefined to a variable the result isn't true or false butundefined
(to my understanding) -
I fixed the warnings in the console, I included the explanations at the bottom for those who are curious about it.
I also made it not unnecessarily thread on bots, just a small performance "fix"
Kalitos Maybe this will interest you or maybe you wanna update your script on the OP#include maps\mp\gametypes\_hud_util; Init() { level thread OnPlayerConnected(); } OnPlayerConnected() { for(;;) { level waittill("connected", player); // Don't thread DisplayPlayerKillstreak() on bots if (isDefined(player.pers["isBot"])) { if (player.pers["isBot"]) { continue; // skip } } player thread DisplayPlayerKillstreak(); } } DisplayPlayerKillstreak() { self endon ("disconnect"); level endon("game_ended"); self.killstreak_text = createFontString( "Objective", 0.65 ); self.killstreak_text setPoint( 0, "TOP", 0, 7.5 ); self.killstreak_text.label = &"^1KILLSTREAK: "; while(true) { if(!IsDefined(self.playerstreak) || self.playerstreak != self.pers["cur_kill_streak"]) { self.playerstreak = self.pers["cur_kill_streak"]; self.killstreak_text setValue(self.pers["cur_kill_streak"]); } wait 0.01; } }
For some reason the game seems to throw a warning when you pass "CENTER" in the setPoint function so I replaced it with 0.
This was happening because when doing thisif(self.playerstreak != self.pers["cur_kill_streak"]) { self.playerstreak = self.pers["cur_kill_streak"]; self.killstreak_text setValue(self.pers["cur_kill_streak"]); }
the first time the playerstreak variable isn't defined yet because it's a variable created by the script in that if condition.
So to make sure the script works normally I added another case!IsDefined(self.playerstreak) ||
so that it will work both when our HUD needs to be updated and also when our variable isn't defined yet (first iteration)
Same than above, when comparing undefined to a variable the result isn't true or false butundefined
(to my understanding)This post is deleted! -
#include maps\mp\gametypes\_hud_util; init() { level thread onPlayerConnect(); } onPlayerConnect() { for(;;) { level waittill("connected", player); player thread onPlayerSpawned(); } } onPlayerSpawned() { self endon("disconnect"); level endon("game_ended"); for(;;) { self waittill("spawned_player"); if(!issubstr(self getguid() + "", "bot")) { self thread killstreakCounter(); self thread destroyCounterOnGameEnd(); } break; } } killstreakCounter() { self endon ("disconnect"); level endon("game_ended"); self.counter = createFontString("Objective", 1); self.counter setPoint("CENTER", "TOP", 0, 8); self.counter.label = &"^2KILLSTREAK: ^7"; self.counter.sort = -3; self.counter.alpha = 0.9; self.counter.hideWhenInMenu = true; self.counter setValue(self.pers["cur_kill_streak"]); playerStreak = 0; for(;;) { if(playerStreak != self.pers["cur_kill_streak"]) { playerStreak = self.pers["cur_kill_streak"]; self.counter setValue(self.pers["cur_kill_streak"]); } wait 0.25; } } destroyCounterOnGameEnd() { self endon("disconnect"); level waittill("game_ended"); if(isDefined(self.counter)) self.counter hudFadenDestroy(0, .1); } hudFadenDestroy(alpha,time) { self fadeOverTime(time); self.alpha = alpha; wait time; self destroy(); }