Post: Script Model & Attack Dog Spawning Error Fix
12-06-2015, 08:06 PM #1
BullyWiiPlaza
Climbing up the ladder
(adsbygoogle = window.adsbygoogle || []).push({}); Have you ever ran into g_spawn error messages caused by spawning too many care packages, via shooting attack dogs or something like that? If you follow this tutorial, you can fix your patch to prevent those common spawning errors altogether. I recommend you to do this since it becomes impossible to cause the lobby to crash due to spawning too much once you added my scripts. This is a similar fix to the You must login or register to view this content. one which you shouldn't disregard either. Let's begin!

To fix the spawning errors on attack dogs and so called script_models, you need to add the following functions somewhere in your GSC:
    preventDogSpawningOverflow()
{
level.dogSpawnedNotification = "dogSpawned";

preventEntitySpawningOverflow(30, level.dogSpawnedNotification, "attack_dog", "targetname");
}

preventScriptModelSpawningOverflow()
{
level.scriptModelSpawnedNotification = "scriptModelSpawned";

preventEntitySpawningOverflow(400, level.scriptModelSpawnedNotification, "script_model", "classname");
}

dogSpawned()
{
level notify(level.dogSpawnedNotification);
}

scriptModelSpawned()
{
level notify(level.scriptModelSpawnedNotification);
}

safeSpawnScriptModel(origin)
{
spawnedEntity = spawn("script_model", origin);
scriptModelSpawned();

return spawnedEntity;
}

preventEntitySpawningOverflow(maximumSpawned, spawnedNotification, entityType, targetName)
{
level endon("game_ended");

while(true)
{
level waittill(spawnedNotification);

spawnedEntitiesArray = getEntArray(entityType, targetName);
spawnedEntities = spawnedEntitiesArray.size;

while(spawnedEntities >= maximumSpawned)
{
// Delete an old entity to make room for a new one
spawnedEntitiesArray[0] delete();

spawnedEntitiesArray = getEntArray(entityType, targetName);
spawnedEntities = spawnedEntitiesArray.size;

wait 0.1;
}
}
}

Now you also need to call both overflow fix functions in your init() function, namely preventScriptModelSpawningOverflow() and preventDogSpawningOverflow(). Make sure you thread them as well:

    init()
{
level thread preventDogSpawningOverflow();
level thread preventScriptModelSpawningOverflow();
}

Next you need to find every piece of code which spawns a script_model entity. In particular you need to look for code lines like the following:
    stairz[i] = spawn("script_model", newPos);

This is taken from the You must login or register to view this content. since it can quickly cause g_spawn errors when used multiple times in a single match. It spawns many care packages forming stairs which you can walk upwards on. As you can see, it uses the spawn() function to spawn an entity at a specific position. To fix this for g_spawn errors, you need to replace the call to spawn() with my custom function:
    safeSpawnScriptModel(origin);

Now the g_spawn error fixed spawning code should look like this:
    stairz[i] = safeSpawnScriptModel(newPos);

My function "safely" spawns a script model meaning that it will make sure that the maximum limit of script_model entities being spawned is not exceeded. By testing I found that it is slightly above 400 so that's our maximum. If you do request more entities to be spawned, older ones will automatically be deleted before any new ones are spawned to make sure the lobby does not crash.

For the dog spawning case I made it work a bit differently. Every time you spawn a dog via the spawn() function like the following
    maps\mp\killstreaks\_dogs::dog_manager_spawn_dog(s  elf, self.team, node, 5);

you then have to call dogSpawned() right afterwards to let the script know that a new dog has been spawned. This is needed to recheck if the limit has been reached yet. If the limit is reached, an older dog is deleted to make room for the new one. You can in fact hold down the trigger and spawn dogs constantly, it will not crash, unlike before. Again, the limit of active dogs at the same time is slightly above 30 so do not go any higher than that.

If you didn't understand everything so far, no problem. Here are the two full example scripts including my spawning fix for you to try:
    spawnStairs()
{
iprintlnBold("Spawning Stairs");

self thread stairz(70);
}

stairz(size)
{
stairz=[];
stairPos = self.origin + ( 100, 0, 0 );

for( i=0;i<=size;i++ )
{
newPos = ( stairPos +((58 * i / 2), 0, (17 * i / 2)) );
stairz[i] = safeSpawnScriptModel(newPos); // This fixes script_model spawning errors
// stairz[i].angles =(0, 90, 0);
stairz[i].angles = self.angles;
wait .1;
stairz[i] setModel("t6_wpn_supply_drop_ally");
}
}


    shootRealDogs()
{
self endon("disconnect");
self endon("stopShootingDogs");

while(true)
{
self waittill("weapon_fired");

dog_spawner = getEnt("dog_spawner", "targetname");
level.dog_abort = false;

// No dog spawners
if(!isDefined(dog_spawner))
{
return;
}

direction = self getPlayerAngles();
direction_vec = anglesToForward(direction);
eye = self GetEye();

scale = 8000;
direction_vec = (direction_vec[0] * scale, direction_vec[1] * scale, direction_vec[2] * scale);
trace = bulletTrace(eye, eye + direction_vec, 0, undefined);

nodes = getNodesInRadius(trace["position"], 256, 0, 128, "Path", Cool Man (aka Tustin);

// No nodes found
if (nodes.size == 0)
{
return;
}

node = getClosest(trace["position"], nodes);
maps\mp\killstreaks\_dogs::dog_manager_spawn_dog(s elf, self.team, node, 5);

dogSpawned(); // This fixes dog spawn errors
}
}
If you want to see this in action, I also made a video showing off some entity overflow fixed scripts in case you're wondering how it is like:
Credits for the spawning fix code & tutorial:
Me

Happy modding Enzo
(adsbygoogle = window.adsbygoogle || []).push({});

The following 6 users say thank you to BullyWiiPlaza for this useful post:

BlueeHasSwag, Im_YouViolateMe, itsSorrow, OfficialCoolJay, Patrick, Terrorize 420
12-06-2015, 08:57 PM #2
EternalHabit
Former Staff
there's one piece to this that you overlooked. if you spawn 39 dogs, and 399 carepackages etc. the game will entity overflow. This was fixed already almost a year ago. Just look at dynamic v2 and jwm614's forge menu

The following user thanked EternalHabit for this useful post:

itsSorrow
12-06-2015, 09:01 PM #3
BullyWiiPlaza
Climbing up the ladder
Originally posted by xTurntUpLobbies View Post
there's one piece to this that you overlooked. if you spawn 39 dogs, and 399 carepackages etc. the game will entity overflow. This was fixed already almost a year ago. Just look at dynamic v2 and jwm614's forge menu

No because the overflow will occur with about 32 dogs and 406 entities so yeah, it works now that I edited it again a bit since it was possible to pass the equal to maximum condition somehow but no longer.

The following user thanked BullyWiiPlaza for this useful post:

sandro oliveira

Copyright © 2026, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo