coldfire Posted December 7, 2009 Share Posted December 7, 2009 Hello, I've been working on converting an old project of mine to Leadwerks. The project was a procedural building generator. My question is, is it possible to create a point entity that at spawn, generates a model of its own? I figure it may be possible to use the point entity and attach limbs to it, but unfortunately every which way I've tried to accomplish this I have failed with countless engine crashes. Thanks for any advice. Randy Quote AMD 64 X2 3800+ | 3G DDR2 667 | Windows 7 Ultimate 64 Bit | Nvidia Geforce 9800 GT 512MB DDR3 Link to comment Share on other sites More sharing options...
Niosop Posted December 7, 2009 Share Posted December 7, 2009 Hello, I've been working on converting an old project of mine to Leadwerks. The project was a procedural building generator. My question is, is it possible to create a point entity that at spawn, generates a model of its own? I figure it may be possible to use the point entity and attach limbs to it, but unfortunately every which way I've tried to accomplish this I have failed with countless engine crashes. Thanks for any advice. Randy Should be able to do it via Lua Scripting easily enough. In the Spawn function you'd just have it load models and position them. As long as the mass is set to 0 then you won't have to create joints or anything. Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
coldfire Posted December 7, 2009 Author Share Posted December 7, 2009 Should be able to do it via Lua Scripting easily enough. In the Spawn function you'd just have it load models and position them. As long as the mass is set to 0 then you won't have to create joints or anything. Hmm... I didnt think about making it as a model seperate from the entity... I've been trying to replace the entity, and I think thats where most of my problems were coming from. One way to find out though Thanks for the idea niosop. Quote AMD 64 X2 3800+ | 3G DDR2 667 | Windows 7 Ultimate 64 Bit | Nvidia Geforce 9800 GT 512MB DDR3 Link to comment Share on other sites More sharing options...
Rick Posted December 7, 2009 Share Posted December 7, 2009 From my understanding the entity is a lua table where the model is an LE TModel. You can create/load any number of models and add a variable to the entity assigning your loaded model. entity = base_Entity(model) entity.mycrazyvariablename = LoadModel("abstract::mymodel.gmf") entity.anothercrazyvariablename = 5 And now these variables added to the entity table can be used anytime in your entities script I think Josh mentioned he might change the naming from entity to object since LE has a TEntity and it can be confusing when we see the word entity because does it mean a TEntity or just a lua variable? It's a lua variable but it can be confusing. Quote Link to comment Share on other sites More sharing options...
coldfire Posted December 8, 2009 Author Share Posted December 8, 2009 Alright, finally making some progress. Now I am having a different problem, however. dofile ("Scripts/base.lua") function Spawn(model) local entity=base_Spawn(model) local RootPosition = entity.model:GetPosition(1) entity.chunk = {} entity.chunk[0] = CreateCube() entity.chunk[0]:SetPosition(RootPosition,1) function entity:Update() RootPosition = entity.model:GetPosition(1) entity.chunk[0]:SetPosition(RootPosition,1) end end function Update(world) if world==world_main then local model,entity for model,entity in pairs(entitytable) do if model.world==world then entity:Update() end end end end function Cleanup(world) end The code creates a cube and places it at the position of the point entity and also repositions at update() in the event that it is moved. The problem I am having is that when I delete the entity, the cube still stays. How would I go about cleaning it up after delete? Quote AMD 64 X2 3800+ | 3G DDR2 667 | Windows 7 Ultimate 64 Bit | Nvidia Geforce 9800 GT 512MB DDR3 Link to comment Share on other sites More sharing options...
Rick Posted December 8, 2009 Share Posted December 8, 2009 Use the Kill function. Example: function Kill(model) local entity entity=entitytable[model] if entity~=nil then if entity.tire[0]~=nil then entity.tire[0]:Free() end if entity.tire[1]~=nil then entity.tire[1]:Free() end if entity.tire[2]~=nil then entity.tire[2]:Free() end if entity.tire[3]~=nil then entity.tire[3]:Free() end end end 1 Quote Link to comment Share on other sites More sharing options...
coldfire Posted December 8, 2009 Author Share Posted December 8, 2009 Use the Kill function. Example: function Kill(model) local entity entity=entitytable[model] if entity~=nil then if entity.tire[0]~=nil then entity.tire[0]:Free() end if entity.tire[1]~=nil then entity.tire[1]:Free() end if entity.tire[2]~=nil then entity.tire[2]:Free() end if entity.tire[3]~=nil then entity.tire[3]:Free() end end end Ah, thanks again Rick. I was trying to mess with that before, but as you can tell from my leftover lines at the end, I thought the function was Cleanup(), lol. Thank you very much. Edit: Awesome... worked like a charm. Quote AMD 64 X2 3800+ | 3G DDR2 667 | Windows 7 Ultimate 64 Bit | Nvidia Geforce 9800 GT 512MB DDR3 Link to comment Share on other sites More sharing options...
Niosop Posted December 8, 2009 Share Posted December 8, 2009 Another thing you could do is just set the parent of the chunk. Then you won't even have to move the chunk because it will be translated w/ the parent. It will also be destroyed when the parent is (I think). Quote Windows 7 x64 - Q6700 @ 2.66GHz - 4GB RAM - 8800 GTX ZBrush - Blender Link to comment Share on other sites More sharing options...
macklebee Posted December 8, 2009 Share Posted December 8, 2009 Another thing you could do is just set the parent of the chunk. Then you won't even have to move the chunk because it will be translated w/ the parent. It will also be destroyed when the parent is (I think). yes, this is correct. Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
coldfire Posted December 8, 2009 Author Share Posted December 8, 2009 Hmm... didn't know you could do that. I got it working the other way, but cleaner code is always welcome. Thank you all. Quote AMD 64 X2 3800+ | 3G DDR2 667 | Windows 7 Ultimate 64 Bit | Nvidia Geforce 9800 GT 512MB DDR3 Link to comment Share on other sites More sharing options...
Recommended Posts
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.