Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "StdAfx.h"
- #include "entity.hpp"
- #include "lua\init.hpp"
- #include "lua\sugar\object_reg.hpp"
- object(IEntity, entity)
- function(GetClass)
- lua_pushstring(L, self->GetClass()->GetName());
- end
- function(Remove)
- gEnv->pEntitySystem->RemoveEntity(self->GetId(), true);
- lua_pushnil(L);
- end
- function(SetSize)
- self->SetScale(Vec3(1,1,1) * lua_tonumber(L, 2));
- ends
- // ends will return self again. this means you can do
- // fancy shit like local ent = CreateEntity("myent"):SetPos(Vec3(0,0,100)):SetAngles(Ang3(90,0,0))
- function(__tostring)
- lua_pushfstring(L, "%s[%d][%s]", PRINTNAME, self->GetId(), self->GetClass()->GetName());
- end
- function(__len)
- lua_pushnumber(L, self->GetId());
- end
- function(__index1) // __index1 is called if __index doesn't return anything
- string key = lua_tostring(L, 2);
- if (key == "id")
- {
- __len(L);
- return 1;
- }
- else if (key == "omg")
- {
- lua_pushstring(L, "HHPOOøPYLSHIT");
- return 1;
- }
- __luaindex() // this will try to call __luaindex which entities can override
- end
- // R will register the given function like so _R.IEntity.MyFunc where MyFunc is the argument
- // RR will do the same as R but the second argument can be an alias of your function
- declare{
- REG(SetSize)
- REG(Remove)
- ALIAS(Remove, Destroy) // Destroy will become an alias of Remove
- ALIAS(Remove, Delete)
- REG(__index)
- REG(__newindex)
- REG(__eq)
- REG(__tostring)
- REG(__len)
- REG(__index1)
- }}
Advertisement
Add Comment
Please, Sign In to add comment