Skip to content
This repository was archived by the owner on Dec 23, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
359 changes: 316 additions & 43 deletions lua/starfall/libs_sh/ents.lua

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions lua/starfall/libs_sh/ents_npc.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-------------------------------------------------------------------------------
-- NPC functions.
-------------------------------------------------------------------------------

assert(SF.Entities)

SF.NPC = {}
local npc_methods, npc_metamethods = SF.Typedef("NPC", SF.Entities.Metatable)

SF.NPC.Methods = npc_methods
SF.NPC.Metatable = npc_metamethods

-- Overload entity wrap functions to handle NPC
local dsetmeta = debug.setmetatable
local old_ent_wrap = SF.Entities.Wrap
function SF.Entities.Wrap(obj)
local w = old_ent_wrap(obj)
if type(obj) == "NPC" then
dsetmeta(w, npc_metamethods)
end
return w
end

local function isValid(entity)
return (SF.Entities.IsValid(entity) and entity:IsNPC())
end

-- ------------------------- Entity Methods ------------------------- --

local ents_methods = SF.Entities.Methods
local ents_metatable = SF.Entities.Metatable

local wrap, unwrap = SF.Entities.Wrap, SF.Entities.Unwrap

function ents_methods:isNPC( )
SF.CheckType( self, ents_metatable )
local ent = SF.Entities.Unwrap( self )
if not SF.Entities.IsValid(ent) then return false, "invalid entity" end
return ent:IsNPC( )
end

-- ------------------------- NPC Methods ------------------------- --
Loading