Jump to content

ForEachEntityInAABBDo to find entities


martyj
 Share

Recommended Posts

I have several entities that I'm trying to get a reference to a bunch of entities to be able to spawn copies of them.

 

All my entities are at the same location. (-100, -100, -100).

 

My code is as follows

 


function ParseWorldItemsCallback(entity, extra)
local name = entity:GetKeyValue("name")
System:Print("name:"..name);
end

function ParseWorldItems()
local aabb = AABB(-101, -101, -101, -99, -99, -99)

local world = World:GetCurrent();
world:ForEachEntityInAABBDo(aabb, "ParseWorldItemsCallback", nil);
end


My problem is that the name of the entity is empty string "".

 

Am I using ForEachEntityInAABBDo wrong? Or is there something wrong with how I'm getting the entity name?

 

Thanks,

Marty

Link to comment
Share on other sites

Sorry my mistake, I was messing around with that to see if it was the AABB that was the problem. I changed the code back to had I first had it. That doesn't change the entity name problem I am having.

 

Both versions get entities passed to the callback. The problem is their name is empty.

Link to comment
Share on other sites

The easier and less costly way is to make a table of prefabs, ie. PreFab{}, and then place a dummy of each in a distant place on the map with the editor to preload them at start. when you want one to be called (copied) just use the PreFab:Load(). this also lets you randomize spawns. If you have 5 zombie models you can call a math:random(1,5) and pass that as the table position and randomly pick the prefab to add some coolness. I have done this for mobs as well as items for drops before. It looks like this assuming you have populated a PreFab table with paths to the entities you want to spawn.

 

local random = math(1,5)

local spawn = PreFab:Load(PreFab[random])

spawn.SetPosition(whateverPos)

spawn.SetRotation(whateverRot)

spawn.script:Start()

 

you could copy the entity but if something happens to your master the copy will be messed up. with the preload you don't have that issue because you are making a fresh one when you need it but all the assets are already in memory because of the dummies.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...