DevilXD Posted May 4, 2014 Share Posted May 4, 2014 (edited) 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 May 5, 2014 by DevilXD Link to comment https://forums.kleientertainment.com/forums/topic/35920-problems-with-custom-action/ Share on other sites More sharing options...
DevilXD Posted May 5, 2014 Author Share Posted May 5, 2014 Anyone can help me ? :-/ Link to comment https://forums.kleientertainment.com/forums/topic/35920-problems-with-custom-action/#findComment-470937 Share on other sites More sharing options...
_Q_ Posted May 5, 2014 Share Posted May 5, 2014 (edited) 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) endendYour action is not targeting pond at all atm. fishableFILL.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) endendYour CanBeFilled function should just return true or false, depending on bucket state, to be used in that action check check. Edited May 5, 2014 by _Q_ Link to comment https://forums.kleientertainment.com/forums/topic/35920-problems-with-custom-action/#findComment-470948 Share on other sites More sharing options...
DevilXD Posted May 5, 2014 Author Share Posted May 5, 2014 Thank you so much @_Q_, I made two components, filler and fillable, and it works now Link to comment https://forums.kleientertainment.com/forums/topic/35920-problems-with-custom-action/#findComment-470988 Share on other sites More sharing options...
Recommended Posts
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