The following warnings occurred:
Warning [2] count(): Parameter must be an array or an object that implements Countable - Line: 906 - File: showthread.php PHP 7.2.24-0ubuntu0.18.04.17 (Linux)
File Line Function
/showthread.php 906 errorHandler->error



Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
limit number of dynamically created entities
darksky Offline
Member

Posts: 52
Threads: 8
Joined: Nov 2012
Reputation: 2
#1
limit number of dynamically created entities

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
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"

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?
02-10-2013, 05:24 PM
Find


Messages In This Thread
limit number of dynamically created entities - by darksky - 02-10-2013, 05:24 PM



Users browsing this thread: 1 Guest(s)