zUsername Posted January 28, 2016 Share Posted January 28, 2016 I have a problems with my mod, the mod only work fine on host side but client side can't pick up the cookpot. local function stewerfix(inst, doer, actions, right) local function CanBePickUp(inst) return inst.components.container ~= nil and inst.components.stewer ~= nil and not inst.components.container:IsOpen() and inst.components.container:IsEmpty() and not inst.components.stewer:IsCooking() and inst.components.stewer.product == nil and #inst.replica.container:GetItems() == 0 end if inst.prefab == "portablecookpot" and right and CanBePickUp(inst) then table.insert(actions, GLOBAL.ACTIONS.PICKUP) end end AddComponentAction("SCENE", "stewer", stewerfix) On the client side components.container = nil and components.stewer = nil. And in my prefab file local function fn(Sim) local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddMiniMapEntity() inst.entity:AddLight() inst.entity:AddNetwork() MakeObstaclePhysics(inst, .6) inst.MiniMapEntity:SetIcon("portablecookpot.tex") inst.Light:Enable(false) inst.Light:SetRadius(.6) inst.Light:SetFalloff(1) inst.Light:SetIntensity(.5) inst.Light:SetColour(235/255,62/255,12/255) inst:AddTag("structure") inst.AnimState:SetBank("cook_pot_warly") inst.AnimState:SetBuild("cook_pot_warly") inst.AnimState:PlayAnimation("idle_empty") MakeSnowCoveredPristine(inst) if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() inst:AddComponent("stewer") inst.components.stewer.onstartcooking = startcookfn inst.components.stewer.oncontinuecooking = continuecookfn inst.components.stewer.oncontinuedone = continuedonefn inst.components.stewer.ondonecooking = donecookfn inst.components.stewer.onharvest = harvestfn inst.components.stewer.onspoil = spoilfn inst:AddComponent("container") inst.components.container:WidgetSetup("cookpot") inst.components.container.onopenfn = onopen inst.components.container.onclosefn = onclose inst:ListenForEvent("itemget", function(inst, data) if inst.components.container ~= nil then inst.components.container:Open(ThePlayer) end end) inst:AddComponent("inventoryitem") inst.components.inventoryitem.imagename = "portablecookpot" inst.components.inventoryitem.atlasname = "images/inventoryimages/portablecookpot.xml" inst.components.inventoryitem.canbepickedup = false inst:AddComponent("pickupable") inst.components.pickupable:SetOnPickupFn(pickupfn) inst:AddComponent("inspectable") inst.components.inspectable.getstatus = getstatus inst:AddComponent("playerprox") inst.components.playerprox:SetDist(3,5) inst.components.playerprox:SetOnPlayerFar(onfar) inst:AddComponent("hauntable") inst.components.hauntable:SetOnHauntFn(OnHaunt) MakeSnowCovered(inst, .01) inst:ListenForEvent("onbuilt", onbuilt) return inst end I'm know : if not TheWorld.ismastersim then return inst end will return before added component. So are there any way to fix it? Thanks in advance. Link to comment https://forums.kleientertainment.com/forums/topic/63377-using-components-with-addcomponentaction-on-client-side/ Share on other sites More sharing options...
Muche Posted January 28, 2016 Share Posted January 28, 2016 As I discovered a while back in http://forums.kleientertainment.com/topic/61458-help-with-component-on-client-machines/#comment-704039, actions run on the server, component action collecting on the client. What happens is that when you mouseover a building, it goes through all registered component actions of the building (i.e. all appropriate component actions for of all building's components), runs their functions which may or may not add actions into actions table. This table is then sorted (based on actions' priorities) and first item is picked to be displayed for a user and then sent to the server. If two actions have the same priority (in this case COOK's 1 and PICKUP's 1, the behavior could be unpredictable - sometimes one action could be displayed, other times the other). Since most components are available only on the server (like stewer), although some are replicable (like container), decisions whether an action is available are usually based on tags (which are set on the server in all the various callbacks). Link to comment https://forums.kleientertainment.com/forums/topic/63377-using-components-with-addcomponentaction-on-client-side/#findComment-714724 Share on other sites More sharing options...
zUsername Posted January 28, 2016 Author Share Posted January 28, 2016 3 hours ago, Muche said: As I discovered a while back in http://forums.kleientertainment.com/topic/61458-help-with-component-on-client-machines/#comment-704039, actions run on the server, component action collecting on the client. What happens is that when you mouseover a building, it goes through all registered component actions of the building (i.e. all appropriate component actions for of all building's components), runs their functions which may or may not add actions into actions table. This table is then sorted (based on actions' priorities) and first item is picked to be displayed for a user and then sent to the server. If two actions have the same priority (in this case COOK's 1 and PICKUP's 1, the behavior could be unpredictable - sometimes one action could be displayed, other times the other). Since most components are available only on the server (like stewer), although some are replicable (like container), decisions whether an action is available are usually based on tags (which are set on the server in all the various callbacks). So can I use this: local function stewerfix(inst, doer, actions, right) local function CanBePickUp(inst) return not inst:HasTag("donecooking") and not inst:HasTag("readytocook") and inst.replica.container ~= nil and #inst.replica.container:GetItems() == 0 and not inst.replica.container._isopen end if inst.prefab == "portablecookpot" and right and CanBePickUp(inst) then table.insert(actions, GLOBAL.ACTIONS.PICKUP) end end AddComponentAction("SCENE", "stewer", stewerfix) But I have problem now. Are there any way to check container is open in replica ? I already tried IsBusy(), _isopen but it's can't check container is open. Link to comment https://forums.kleientertainment.com/forums/topic/63377-using-components-with-addcomponentaction-on-client-side/#findComment-714773 Share on other sites More sharing options...
zUsername Posted January 28, 2016 Author Share Posted January 28, 2016 Solved. By adding tag with onOpen and onClose, Thanks you @Muche Link to comment https://forums.kleientertainment.com/forums/topic/63377-using-components-with-addcomponentaction-on-client-side/#findComment-714788 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