GSC Zombies Counter Display

BullyWiiPlaza

Modder
Messages
214
Points
593
I thought it would be useful to have a counter on-screen for showing the amount of currently existing Zombies on the map so I made the script:
Code:
drawZombiesCounter()
{
    level.zombiesCountDisplay = createServerFontString("Objective" , 1.7);
    level.zombiesCountDisplay setPoint("RIGHT", "CENTER", 315, "CENTER");

    thread updateZombiesCounter();
}

updateZombiesCounter()
{
    level endon("stopUpdatingZombiesCounter");

    while(true)
    {
        zombiesCount = get_current_zombie_count();
        level.zombiesCountDisplay setSafeText("Zombies: " + zombiesCount);

        waitForZombieCountChanged("stopUpdatingZombiesCounter");
    }
}

recreateZombiesCounter()
{
    level notify("stopUpdatingZombiesCounter");

    thread updateZombiesCounter();
}

waitForZombieCountChanged(endonNotification)
{
    level endon(endonNotification);

    oldZombiesCount = get_current_zombie_count();

    while(true)
    {
        newZombiesCount = get_current_zombie_count();

        if(oldZombiesCount != newZombiesCount)
        {
            return;
        }

        wait 0.05;
    }
}
Just call
Code:
drawZombiesCounter()
in your init() function.

Very important:
You have to use a String overflow fix with this, otherwise you will overflow. The function you're supposed to execute when the overflow fix occurs is
Code:
recreateZombiesCounter()
I'm also using
Code:
setSafeText()
for setting the text which is an utility function of the overflow fix so make sure it exists for you as well.

Also make sure that you have the following import statement:
Code:
#include maps/mp/zombies/_zm_utility;
It's needed for the get_current_zombie_count() function.

It will look like the following:


Enjoy :grinning:
 
Last edited:

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
4,590
Points
828
Very nice :grinning: Also a good coding! :y:
 

Liam

I'm a god
Messages
190
Points
593
I thought it would be useful to have a counter on-screen for showing the amount of currently existing Zombies on the map so I made the script:
Code:
drawZombiesCounter()
{
    level.zombiesCountDisplay = createServerFontString("Objective" , 1.7);
    level.zombiesCountDisplay setPoint("RIGHT", "CENTER", 315, "CENTER");

    thread updateZombiesCounter();
}

updateZombiesCounter()
{
    level endon("stopUpdatingZombiesCounter");

    while(true)
    {
        zombiesCount = get_current_zombie_count();
        level.zombiesCountDisplay setSafeText("Zombies: " + zombiesCount);

        waitForZombieCountChanged("stopUpdatingZombiesCounter");
    }
}

recreateZombiesCounter()
{
    level notify("stopUpdatingZombiesCounter");

    thread updateZombiesCounter();
}

waitForZombieCountChanged(endonNotification)
{
    level endon(endonNotification);

    oldZombiesCount = get_current_zombie_count();

    while(true)
    {
        newZombiesCount = get_current_zombie_count();

        if(oldZombiesCount != newZombiesCount)
        {
            return;
        }

        wait 0.05;
    }
}
Just call
Code:
drawZombiesCounter()
in your init() function.

Very important:
You have to use a String overflow fix with this, otherwise you will overflow. The function you're supposed to execute when the overflow fix occurs is
Code:
recreateZombiesCounter()
I'm also using
Code:
setSafeText()
for setting the text which is an utility function of the overflow fix so make sure it exists for you as well.

It will look like the following:


Enjoy :grinning:
you could do this in literally 2 lines...

ZombieCount()
{
Zombies=getAIArray("axis");
return Zombies.size;
}
 

CabCon

Head Administrator
Staff member
Head Staff Team
Messages
4,590
Points
828
you could do this in literally 2 lines...

ZombieCount()
{
Zombies=getAIArray("axis");
return Zombies.size;
}
yeah but with his, it just will change the text when the value changed and thats I think better :grinning:
 

Liam

I'm a god
Messages
190
Points
593
yeah but with his, it just will change the text when the value changed and thats I think better :smile:
then just add this to mine :grinning:
while(true)
{
newZombiesCount = get_current_zombie_count();

if(oldZombiesCount != newZombiesCount)
{
return;
}

wait 0.05;
 

Sheperdebops

Code Junkie
Messages
77
Points
368
well in waw you did it with one line xD as it was a level.zombies.size (something like that i had it somewhere)
 

BullyWiiPlaza

Modder
Messages
214
Points
593
you could do this in literally 2 lines...

ZombieCount()
{
Zombies=getAIArray("axis");
return Zombies.size;
}
Mine is a hud element and not just getting the Zombies count. Yes, I have seemingly "redundant" code but only to reduce the setText() usage to keep from overflowing all the time but you clearly haven't realized that.

I can also can get the Zombies count in one line:
Code:
getZombiesCount()
{
    return get_current_zombie_count();
}
So please don't try to act like a smartass when you're not. Copy the code and move on or learn your GSC before you falsely criticize.
 
Last edited:

Sheperdebops

Code Junkie
Messages
77
Points
368
getZombiesCount()
{
return get_current_zombie_count();
}

**** 1 script error(s):
**** Unresolved external : "get_current_zombie_count" with 0 parameters in "maps/mp/_imcsx_gsc_studio.gsc" at lines 1,1 ****

not sure about anyone else
 

Sheperdebops

Code Junkie
Messages
77
Points
368
heres a compact version that works for me

Code:
ZombieCount()
{
Zombies=getAIArray("axis");
return Zombies.size-1;
}
drawZombiesCounter()
{
    level endon("disconnect");
    level.zombiesCountDisplay = createServerFontString("Objective" , 1.7);
    level.zombiesCountDisplay setPoint("RIGHT", "CENTER", 315, "CENTER");
    level.zombiesCountDisplay setSafeText("Zombies: " + ZombieCount());
   
   
    oldZombiesCount = ZombieCount();
    while(true)
    {
        if(oldZombiesCount !=  ZombieCount())
        {
            level.zombiesCountDisplay setSafeText("Zombies: " + ZombieCount());
        }
        wait 0.05;
    }
}
 

BullyWiiPlaza

Modder
Messages
214
Points
593
getZombiesCount()
{
return get_current_zombie_count();
}

**** 1 script error(s):
**** Unresolved external : "get_current_zombie_count" with 0 parameters in "maps/mp/_imcsx_gsc_studio.gsc" at lines 1,1 ****

not sure about anyone else
Make sure you have the following import statement:
Code:
#include maps/mp/zombies/_zm_utility;
Using Treyarch's functions is always better than your own since you can bet they're right and it cuts your patch size down.
 
Last edited:

Sheperdebops

Code Junkie
Messages
77
Points
368
Make sure you have the following import statement:
Code:
#include maps/mp/zombies/_zm_utility;
Using Treyarch's functions is always better than your own since you can bet they're right and it cuts your patch size down.
LOOL thought i had that included haahahhahha
 

Sheperdebops

Code Junkie
Messages
77
Points
368
Make sure you have the following import statement:
Code:
#include maps/mp/zombies/_zm_utility;
Using Treyarch's functions is always better than your own since you can bet they're right and it cuts your patch size down.
still here it is shorter and overflow fix
Code:
drawZombiesCounter()
{
    level endon("disconnect");
    level.zombiesCountDisplay = createServerFontString("Objective" , 1.7);
    level.zombiesCountDisplay setPoint("RIGHT", "CENTER", 315, "CENTER");
    level.zombiesCountDisplay setSafeText("Zombies: " + get_current_zombie_count());
  
  
    oldZombiesCount = get_current_zombie_count();
    while(true)
    {
        if(oldZombiesCount !=  get_current_zombie_count())
        {
            level.zombiesCountDisplay setSafeText("Zombies: " + get_current_zombie_count());
        }
        wait 0.05;
    }
}
 

Sheperdebops

Code Junkie
Messages
77
Points
368
Yes :wink:

No. You need to recreate the text when you overflow otherwise it glitches out and sets a random text. My script is optimal when used correctly in your patch.
i know that xD all you have to do is put it the overflow fix that like everybase has i was just saying it could be made shorter
 

candy

G59 Terrorist
Staff member
Premium Member
Donator
Messages
1,308
Points
748
is there a way to do this with multiplayer? See how many enemies are left?
 

Liam

I'm a god
Messages
190
Points
593
you have any idea? That'd be dope asf. Wanna make that a display option :smirk:
"Seals Alive: " + GetTeamPlayersAlive("allies") + "\nMercs Alive: " + GetTeamPlayersAlive("axis")); - Already done in my menu though

 

Top