02-10-2013, 05:24 PM
hi
I am currently making a map where I create entities every x seconds. but after some time I get some performance problems with 600 entities^^. so I am now looking for a way to limit the number of entities which are active at the same time. Let's say the limit is 100.
the script without limit looks like this
I wanted to do something like that but then I realized there is no method "RemoveEntity"
is there an other way to do this?
I am currently making a map where I create entities every x seconds. but after some time I get some performance problems with 600 entities^^. so I am now looking for a way to limit the number of entities which are active at the same time. Let's say the limit is 100.
the script without limit looks like this
Code:
int count = 0;
float timerInterval;
void spawnstone(string &in asTimer){
count++;
CreateEntityAtArea("stone_"+count, "stone_small01.ent", "SpawnArea_"+x+"_"+z, false);
AddEntityCollideCallback("stone_"+count,"ShootArea_1", "setReady",false, 1);
AddPropImpulse("stone_"+count, RandFloat(-2, 2), 0, RandFloat(-2, 2), "world");
if (!(timerInterval<0)){
AddTimer(asTimer,timerInterval,"spawnstone");
}
}
I wanted to do something like that but then I realized there is no method "RemoveEntity"
Code:
int count = 0;
float timerInterval;
const int maxCount = 100; // <------------
void spawnstone(string &in asTimer){
count++;
count = count % maxCount; // <------------
if (GetEntityExists("stone_"+count)){// <------------
RemoveEntity("stone_"+count); // <------------
} // <------------
CreateEntityAtArea("stone_"+count, "stone_small01.ent", "SpawnArea_"+x+"_"+z, false);
AddEntityCollideCallback("stone_"+count,"ShootArea_1", "setReady",false, 1);
AddPropImpulse("stone_"+count, RandFloat(-2, 2), 0, RandFloat(-2, 2), "world");
if (!(timerInterval<0)){
AddTimer(asTimer,timerInterval,"spawnstone");
}
}
is there an other way to do this?