Jump to content

Recommended Posts

I'm working on a mod, but the code for "componentactions" in "stewer" has recently been changed, so I make a similar code and work on it, but even if I press the space key, the harvest action doesn't work.

 

Quote

actions.lua

DRINK_HARVEST = AddAction("DRINK_HARVEST",STRINGS.ACTIONS.HARVEST,function(act)
    if act.target.components.brewing ~= nil then
        return act.target.components.brewing:Harvest(act.doer)  
    elseif act.target ~= nil and act.target.components.pickable ~= nil then
        act.target.components.pickable:Pick(act.doer)
        return true
    end
end)

ACTIONS.PICK.priority = 1
DRINK_HARVEST.priority = 3
DRINK_HARVEST.canforce = true 
DRINK_HARVEST.rangecheckfn = DefaultRangeCheck
DRINK_HARVEST.extra_arrive_dist = ExtraPickupRange
DRINK_HARVEST.mount_valid = true

BREWING = AddAction("BREWING",STRINGS.ACTIONS.BOIL,function(act)
        if act.target.components.cooker ~= nil then
            local cook_pos = act.target:GetPosition()
            local ingredient = act.doer.components.inventory:RemoveItem(act.invobject)

            ingredient.Transform:SetPosition(cook_pos:Get())

            if not act.target.components.cooker:CanCook(ingredient, act.doer) then
                act.doer.components.inventory:GiveItem(ingredient, nil, cook_pos)
                return false
            end

            if ingredient.components.health ~= nil then
                act.doer:PushEvent("murdered", { victim = ingredient, stackmult = 1 }) -- NOTES(JBK): Cooking something alive.
                if ingredient.components.combat ~= nil then
                    act.doer:PushEvent("killed", { victim = ingredient })
                end
            end

            local product = act.target.components.cooker:CookItem(ingredient, act.doer)
            if product ~= nil then
                act.doer.components.inventory:GiveItem(product, nil, cook_pos)
                return true
            elseif ingredient:IsValid() then
                act.doer.components.inventory:GiveItem(ingredient, nil, cook_pos)
            end
            return false
        elseif act.target.components.brewing ~= nil then
            if act.target.components.brewing:IsCooking() then
                return true
            end
            local container = act.target.components.container
            if container ~= nil and container:IsOpenedByOthers(act.doer) then
                return false, "INUSE"
            elseif not act.target.components.brewing:CanCook() then
                return false
            end
            act.target.components.brewing:StartCooking(act.doer)
            return true
        elseif act.target.components.cookable ~= nil
            and act.invobject ~= nil
            and act.invobject.components.cooker ~= nil then

            local cook_pos = act.target:GetPosition()

            if act.doer:GetPosition():Dist(cook_pos) > 2 then
                return false, "TOOFAR"
            end

            local owner = act.target.components.inventoryitem:GetGrandOwner()
            local container = owner ~= nil and (owner.components.inventory or owner.components.container) or nil
            local stacked = act.target.components.stackable ~= nil and act.target.components.stackable:IsStack()
            local ingredient = stacked and act.target.components.stackable:Get() or act.target

            if ingredient ~= act.target then
                ingredient.Transform:SetPosition(cook_pos:Get())
            end

            if not act.invobject.components.cooker:CanCook(ingredient, act.doer) then
                if container ~= nil then
                    container:GiveItem(ingredient, nil, cook_pos)
                elseif stacked and ingredient ~= act.target then
                    act.target.components.stackable:SetStackSize(act.target.components.stackable:StackSize() + 1)
                    ingredient:Remove()
                end
                return false
            end

            if ingredient.components.health ~= nil and ingredient.components.combat ~= nil then
                act.doer:PushEvent("killed", { victim = ingredient })
            end

            local product = act.invobject.components.cooker:CookItem(ingredient, act.doer)
            if product ~= nil then
                if container ~= nil then
                    container:GiveItem(product, nil, cook_pos)
                else
                    product.Transform:SetPosition(cook_pos:Get())
                    if stacked and product.Physics ~= nil then
                        local angle = math.random() * 2 * PI
                        local speed = math.random() * 2
                        product.Physics:SetVel(speed * math.cos(angle), GetRandomWithVariance(8, 4), speed * math.sin(angle))
                    end
                end
                return true
            elseif ingredient:IsValid() then
                if container ~= nil then
                    container:GiveItem(ingredient, nil, cook_pos)
                elseif stacked and ingredient ~= act.target then
                    act.target.components.stackable:SetStackSize(act.target.components.stackable:StackSize() + 1)
                    ingredient:Remove()
                end
            end
            return false
        end
    end)

BREWING.stroverridefn = function(act)
    return act.target ~= nil and act.target:HasTag("brewery") and STRINGS.ACTIONS.FERMENT or nil
end
BREWING.mount_valid = true
BREWING.priority = 2

 

Quote

componentactions.lua

local SCENE = {
	brewing = function(inst, doer, actions, right)
        if not inst:HasTag("burnt") and
            not (doer.replica.rider ~= nil and doer.replica.rider:IsRiding()) then
            if inst:HasTag("donebrewing") then
                table.insert(actions, ACTIONS.DRINK_HARVEST)
            elseif right and (
                (   
                    inst:HasTag("readybrewing") and
                    --(not inst:HasTag("professionalcookware") or doer:HasTag("professionalchef")) and
                    (not inst:HasTag("mastercookware") or doer:HasTag("masterchef"))
                ) or
                (   inst.replica.container ~= nil and
                    inst.replica.container:IsOpenedBy(doer) and
                    inst.replica.container:IsFull() and
                    inst.replica.waterlevel:HasWater()
                )
            ) then
                table.insert(actions, ACTIONS.BREWING)
            end
        end
    end,
}

The chords are like this What more do I need to work on?

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...