AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Calling a function with a maximum number of times at once (https://forums.alliedmods.net/showthread.php?t=194022)

Backstabnoob 08-24-2012 15:55

Calling a function with a maximum number of times at once
 
I'm trying to create a kind-of waves. In each wave, different amount of zombies of each type spawn. It looks like this:

PHP Code:

enum CLASSES //list of classes
{
    
class_1,
    
class_2
}

new 
Total_Npcs11 ][ CLASSES ] = // total zombies at each wave
{
    { 
0}, // wave 0 (0 of each type spawn)
    
0}, // wave 1 (0 of the first class, one of the second class spawns)
    
1}, // wave 2 (one of the first class, two of the second class spawn)
    
2}, // ...
    
3},
    { 
4},
    { 
5},
    { 
6},
    { 
7},
    { 
8},
    { 
910 }
}

new 
Spawn_At_Once11 ] =
{
    
0,  // 0 max zombies spawn at once
    
1,  // one zombie spawns 
    
3,  // three zombies spawn
    
5,  // ...
    
7,
    
7,
    
7,
    
7// wave 7 - maximum of 7 zombies spawn at the first point, though total amount of zombies is 13
    
7,
    
7,
    
7


The problem is I have no clue how to do this. Let's say a zombie is spawned with this stock: spawn_zombie( class ). It is non-existant, but should be enough for an example of doing this.

It should spawn 7 zombies at the initial moment, then one extra zombie whenever one dies until the total amount is reached (a forward zombie_death( class ) get's called). The amount of each class should be similar in the ratio (for example, if it is { 10, 12 } and it should create 7 zombies at the initial moment, spawn 3 of the first type, 4 of the second at once (10/3, 12/3) ). The order in which zombies are spawned after one dies doesn't matter and can be left random.

It probably is a lot, but if you manage to find some time to do this, I would greatly appreciate it. I at least need to have a basic idea of doing this, since I'm really stuck right now.

Thanks in advance. It is a bit complicated, so if you couldn't understand something, let me know.

nikhilgupta345 08-25-2012 01:55

Re: Calling a function with a maximum number of times at once
 
Could you clarify this part please: "The amount of each class should be similar in the ratio (for example, if it is { 10, 12 } and it should create 7 zombies at the initial moment, spawn 3 of the first type, 4 of the second at once (10/3, 12/3) )."

Not sure what you mean by that.

Backstabnoob 08-25-2012 05:52

Re: Calling a function with a maximum number of times at once
 
To calculate a ratio in which the zombies spawn. It doesn't have to be exactly right, I just don't want it to spawn 7 zombies of the first class and 0 of the other.

nikhilgupta345 08-26-2012 01:52

Re: Calling a function with a maximum number of times at once
 
Try this:

PHP Code:


enum _
:CLASSES //list of classes
{
    
class_1,
    
class_2
}

new 
g_iNumZombiesCLASSES ];
new 
g_iZombiesSpawned 0;
new 
g_iCurWave 1;

// called when a zombie dies
zombie_deathiClass )
{
    if( 
g_iZombiesSpawned == TotalNpcsg_iCurWave ][ class_1 ] + TotalNpcsg_iCurWave ][ class_2 ] )
        return;
        
    new 
Float:flRatio g_iNumZombiesclass_1 ] * 1.0 g_iNumZombiesclass_2 ];
    new 
Float:flTargetRatio TotalNpcsg_iCurWave ][ class_1 ] * 1.0 TotalNpcsg_iCurWave ][ class_2 ];
    
    if( 
flRation flTargetRatio )
    {
        
spawn_zombieclass_1 );
    }
    
    else
    {
        
spawn_zombieclass_2 );
    }
}

// call this whenever you want a new wave to start. make sure you increment g_iCurWave/set it to what you want beforehand.
startWave()
{
    new 
iTotal TotalNpcsg_iCurWave ][ class_1 ] + TotalNpcsg_iCurWave ][ class_2 ];
    
    new 
iSpawnCLASSES ];
    
iSpawnclass_1 ] = floatroundSpawn_At_Onceg_iCurWave ] * ( TotalNpcsg_iCurWave ][ class_1 ] * 1.0 iTotal ) );
    
iSpawnclass_2 ] = Spawn_At_Onceg_iCurWave ] - iSpawnclass_2 ];
    
    for( new 
0CLASSESi++ )
    {
        for( new 
0iSpawn]; j++ )
        {
            
spawn_zombie);
        }
    }
}

spawn_zombieiClass )
{
    
// code to create a zombie here



Backstabnoob 08-28-2012 20:00

Re: Calling a function with a maximum number of times at once
 
Thanks, works perfectly :)


All times are GMT -4. The time now is 05:45.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.