Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // c++
- class LuaEntity : public BaseEntity
- {
- public:
- void Initialize()
- {
- // do nothing here
- BaseEntity::Initialize();
- }
- bool PreCollide(PhysicsObject *phys)
- {
- oh->StartEntityHook(this->GetEntity(), "PreCollide");
- oh->Push(phys);
- oh->EndEntityHook(0, 1);
- // dont allow it to collide if we return false in the scripted entity
- if (oh->IsFalse(-1))
- return false;
- // call the BaseEntity's function to let it handle the rest
- return BaseEntity::PreCollide(phys)
- }
- }
- // lua
- local SENT = {}
- -- this is called from the hook ScriptedEntityInitialized when it's ready
- function SENT:Initialize()
- -- self here is this->GetEntity()
- -- it's basically like doing ent:SetModel() anywhere
- self:SetModel("barrel.cgf")
- end
- function SENT:PreCollide(phys)
- -- collide with nothing but world
- if not phys:IsWorld() then
- return false
- end
- end
- sents.Register(SENT, "foobarrel")
- -- sents lib
- sents.Registered = {}
- function sents.Register(SENT, classname)
- SENT.ClassName = classname
- sents.Registered[classname] = SENT
- end
- function sents.Create(classname)
- local ent = ents.Create("base_entity")
- ent:SetTable(sents.Registered[classname])
- ent:Initialize()
- return ent
- end
- function sents.Call(ent, func_name, ...)
- if ent[func_name] then
- ent[func_name](ent, ...)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment