Jump to content

Recommended Posts

So, I made custom action for my bucket mod, but it doesn't seem to work properly...

Here is the code for it:

local ACTIONS = GLOBAL.ACTIONSlocal Action = GLOBAL.Actionlocal FILL = Action()FILL.str = "Fill"FILL.id = "FILL"FILL.fn = function(act)    print("FILL ACTION")    if act.doer and act.target and act.invobject and act.invobject.components.fillable and act.invobject.components.fillable:CanBeFilled(act.doer, act.target) then        return act.invobject.components.fillable:Fill(act.target, act.doer)    endendAddAction(FILL)ACTIONS.FILL = FILLAddStategraphActionHandler("wilson", GLOBAL.ActionHandler(FILL, "dolongaction"))

..., and "fillable" component:

local Fillable = Class(function(self, inst)    self.inst = inst    self.filltest = nil    self.product = nilend)function Fillable:SetFillTestFn(fn)    self.filltest = fnendfunction Fillable:SetProduct(prd)    self.product = prdendfunction Fillable:CanBeFilled(doer, target)    if self.filltest then        self.filltest(self.inst, doer, target)    endendfunction Fillable:Fill(target, doer)	    local owner = inst.components.inventoryitem and inst.components.inventoryitem.owner    local holder = owner and (owner.components.container or owner.components.inventory)    local slot = holder and holder:GetItemSlot(inst)    	target:PushEvent("drain")        self.inst:Remove()        if self.product then                local item = SpawnPrefab(self.product)        holder:GiveItem(item, slot)        return true            end    endfunction Fillable:CollectUseActions(doer, target, actions, right)    if self:CanBeFilled(doer, target) then        table.insert(actions, ACTIONS.FILL)    endendreturn Fillable

..., and in the "bucket" prefab:

inst:AddComponent("fillable")inst.components.fillable:SetFillTestFn( CanDry )  --function "CanDry" correctly returns true, when I mouse-over with bucket on a pondinst.components.fillable:SetProduct("waterbucket")

In the prefab I have filltest, which correctly return true, when I mouse-over with bucket on a pond, however, pond doesn't highlight and I can't click it...

 

After doing some detective work, I found, that my custom action isn't adding properly...

Edited by DevilXD

Look how repair action is structured:

ACTIONS.REPAIR.fn = function(act)	if act.target and act.target.components.repairable and act.invobject and act.invobject.components.repairer then		return act.target.components.repairable:Repair(act.doer, act.invobject)	endend

Your action is not targeting pond at all atm.

 

fishable

FILL.fn = function(act)    print("FILL ACTION")    if act.target and act.target.components.fishable and act.invobject and act.invobject.components.fillable then        return act.invobject.components.fillable:Fill(act.target, act.doer)    endend

Your CanBeFilled function should just return true or false, depending on bucket state, to be used in that action check check.

Edited by _Q_

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