- AddComponent
function EntityScript:AddComponent(name) local lower_name = string.lower(name) if self.lower_components_shadow[lower_name] ~= nil then print("component "..name.." already exists on entity "..tostring(self).."!"..debugstack_oneline(3)) end local cmp = LoadComponent(name) if not cmp then error("component ".. name .. " does not exist!") end self:ReplicateComponent(name) local loadedcmp = cmp(self) self.components[name] = loadedcmp self.lower_components_shadow[lower_name] = true local postinitfns = ModManager:GetPostInitFns("ComponentPostInit", name) for i, fn in ipairs(postinitfns) do fn(loadedcmp, self) end self:RegisterComponentActions(name) return loadedcmp end function EntityScript:RegisterComponentActions(name) local id = ACTION_COMPONENT_IDS[name] if id ~= nil then table.insert(self.actioncomponents, id) if self.actionreplica ~= nil then self.actionreplica.actioncomponents:set(self.actioncomponents) end end for modname, idmap in pairs(MOD_ACTION_COMPONENT_IDS) do id = idmap[name] if id ~= nil then if self.modactioncomponents == nil then self.modactioncomponents = { [modname] = {} } elseif self.modactioncomponents[modname] == nil then self.modactioncomponents[modname] = {} end table.insert(self.modactioncomponents[modname], id) if self.actionreplica ~= nil then self.actionreplica.modactioncomponents[modname]:set(self.modactioncomponents[modname]) end end end end
in some case, when entity is attempted to add reduplicated component, for example AddComponent("slipperyfeet") for twice, Entityscript:AddComponent so far just print a warning and make it go on and override the existed one. I'm afraid this could cause to RegisterComponentActions again.
- Get/Clear BufferedAction
function EntityScript:GetBufferedAction() return self.bufferedaction or (self.components.locomotor ~= nil and self.components.locomotor.bufferedaction) or nil end function EntityScript:ClearBufferedAction() if self.bufferedaction ~= nil then self.bufferedaction:Fail() self.bufferedaction = nil end end
Get function consider the locomotor.bufferedaction, but Clear function not yet
Steps to Reproduce
As Above
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now