View Full Version : Help with attaching entities

07-12-2008, 04:03 AM
Hypno-Joe as some of you may know, will be using some mouse aim stuff. I need to attach his eyeball animations to his entity. Which means I'll need to make the eyeballs an entity itself. According to the scripting reference, there's the SetAttach function. Only problem is that it takes an entity ID. I know there's a GetID function but how do I get the id of an entity not in "this" namespace? Also what about RunFunction -- I've noticed it's there, what's the difference between that and just running the function directly? I noticed in the description it said it's useful for running functions of other entities? So how does it know which entity to run the function from?

Any help anyone can give is appreciated.

07-13-2008, 02:02 AM
You could use GetEntityIDByName (http://www.rtsoft.com/novashell/docs/api/files/GlobalScriptFunctionBindings-cpp.html#GetEntityIDByName) to get the player ID.

Or, you could create and attach your eyeballs from the player script. For instance, I call this function from OnPostInit to attach a weapon entity to my player:

function MakePaperDoll()

m_doll = CreateEntity(this:GetMap(), this:GetPos(), "weapons/paper_doll.lua");
m_doll:SetAttach(this:GetID(), Vector2(0,0));
m_doll:SetLayerByName("Overlay 1");


And, yes, RunFunction is used to run a function in another script. The entity with the function in its script is the one which will actually be running it.

For example, when my player changes weapons, I tell the paper_doll.lua entity created above to change weapons as well with this line in player.lua:

m_doll:RunFunction("ChangeWeapon", name, weaponStrength);