CapsAdmin

Untitled

Sep 6th, 2011
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. // c++
  2.  
  3. class LuaEntity : public BaseEntity
  4. {
  5.     public:
  6.    
  7.     void Initialize()
  8.     {
  9.         // do nothing here
  10.         BaseEntity::Initialize();
  11.     }
  12.    
  13.     bool PreCollide(PhysicsObject *phys)
  14.     {
  15.         oh->StartEntityHook(this->GetEntity(), "PreCollide");
  16.             oh->Push(phys);
  17.         oh->EndEntityHook(0, 1);
  18.             // dont allow it to collide if we return false in the scripted entity
  19.             if (oh->IsFalse(-1))
  20.                 return false;
  21.                
  22.         // call the BaseEntity's function to let it handle the rest
  23.        
  24.         return BaseEntity::PreCollide(phys)
  25.     }
  26. }
  27.  
  28. // lua
  29.  
  30. local SENT = {}
  31.  
  32. -- this is called from the hook ScriptedEntityInitialized when it's ready
  33. function SENT:Initialize()
  34.     -- self here is this->GetEntity()
  35.     -- it's basically like doing ent:SetModel() anywhere
  36.     self:SetModel("barrel.cgf")
  37. end
  38.  
  39. function SENT:PreCollide(phys)
  40.     -- collide with nothing but world
  41.     if not phys:IsWorld() then
  42.         return false
  43.     end
  44. end
  45.  
  46. sents.Register(SENT, "foobarrel")
  47.  
  48. -- sents lib
  49.  
  50. sents.Registered = {}
  51.  
  52. function sents.Register(SENT, classname)
  53.     SENT.ClassName = classname
  54.     sents.Registered[classname] = SENT
  55. end
  56.  
  57. function sents.Create(classname)
  58.     local ent = ents.Create("base_entity")
  59.     ent:SetTable(sents.Registered[classname])
  60.     ent:Initialize()
  61.    
  62.     return ent
  63. end
  64.  
  65. function sents.Call(ent, func_name, ...)
  66.     if ent[func_name] then
  67.         ent[func_name](ent, ...)
  68.     end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment