Jump to content

Recommended Posts

As you can see from the title, I am running into a problem when editing a component function using postInIt(). What I am trying to change is components/weapon:CollectEquippableActions(...) because I need to remove the IsAlly test.  This is what the function looks like in the don't starve weapon file...

function Weapon:CollectEquippedActions(doer, target, actions)
    if doer.components.combat
       and not target:HasTag("wall")
       and doer.components.combat:CanTarget(target)
       and target.components.combat:CanBeAttacked(doer)
       and not doer.components.combat:IsAlly(target)
       and (not self.canattack or self.canattack(self.inst, target) ) then
        table.insert(actions, ACTIONS.ATTACK)
    end
end

And what I did was port this function to my modmain and make this adjustment...

AddComponentPostInit("weapon", function(self)
    local oldfunction1 = self.CollectEquippedActions         -- Keep the old function in case we need it later.
    function self:CollectEquippedActions(doer, target, actions)
        if self.inst:HasTag("myweapon")
           and target:HasTag("rocky")
           and not target:HasTag("rocky_k")
           and doer.components.combat
           and not target:HasTag("wall")
           and doer.components.combat:CanTarget(target)
           and target.components.combat:CanBeAttacked(doer)
--           and not doer.components.combat:IsAlly(target)
           and (not self.canattack or self.canattack(self.inst, target) ) then
            table.insert(actions, ACTIONS.ATTACK)
        elseif doer.components.combat
           and not target:HasTag("wall")
           and doer.components.combat:CanTarget(target)
           and target.components.combat:CanBeAttacked(doer)
           and not doer.components.combat:IsAlly(target)
           and (not self.canattack or self.canattack(self.inst, target) ) then
            table.insert(actions, ACTIONS.ATTACK)
        end
    end
end)

I have tried..
#1) the above giving me attempt to index global 'ACTIONS' (a nil value)
#2) placing local actions = GLOBAL.ACTIONS in my modmain which gives me attempt to index global 'ACTIONS' (a nil value)
#3) table.insert(GLOBAL.actions, ACTIONS.ATTACK) which gives me variable actions is not declared.

I don't want to just put the component file in my mod because of compatibility problems.  What am I missing? I bet it is something super simple...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...