Wolf_EX Posted May 10, 2019 Share Posted May 10, 2019 I have a container with a button and when you press that button, it executes a function. The issue is that I'm doing this from the modmain and the function is from a serverside component, so it causes an error when I click it. function params.refinechest.widget.buttoninfo.fn(inst, doer) if REFINECHESTFUEL then if not inst.components.fueled:IsEmpty() then inst.components.machine:TurnOn() end else inst.components.machine:TurnOn() end end I tried moving "if not TheWorld.ismastersim then return inst end" after the components on the container prefab so it will be on both client and server but that gives me an error when I load the game about not being enough memory. I also tried using remote procedure calls to have the client send to server to execute the function but wasn't having much luck with that. I never messed with that before so might of been doing it wrong. the whole modmain is local require = GLOBAL.require local Vector3 = GLOBAL.Vector3 local STRINGS = GLOBAL.STRINGS local Ingredient = GLOBAL.Ingredient local RECIPETABS = GLOBAL.RECIPETABS local TECH = GLOBAL.TECH local containers = require "containers" local refinerecipe = require "refinerecipe" PrefabFiles = { "repairchest", "refinechest", } Assets = { Asset("ANIM", "anim/ui_chest_3x2.zip"), Asset("ANIM", "anim/ui_chest_3x1.zip"), Asset("ATLAS", "images/inventoryimages/refinery.xml"), Asset("IMAGE", "images/inventoryimages/refinery.tex"), } --strings STRINGS.NAMES.REPAIRCHEST = "Repair Chest" STRINGS.CHARACTERS.GENERIC.DESCRIBE.REPAIRCHEST = "It can repair all my weapons!" STRINGS.NAMES.REFINECHEST = "Refinery" --STRINGS.CHARACTERS.GENERIC.DESCRIBE.REFINECHEST = "" --recipes AddRecipe("repairchest", {Ingredient("gears", 2), Ingredient("boards", 6), Ingredient("transistor", 2), Ingredient("hammer", 1)}, RECIPETABS.TOWN, TECH.SCIENCE_TWO, "repairchest_placer", nil, nil, nil, nil, "images/inventoryimages/refinery.xml", "refinery.tex") AddRecipe("refinechest", {Ingredient("gears", 1), Ingredient("boards", 2), Ingredient("transistor", 1)}, RECIPETABS.TOWN, TECH.SCIENCE_TWO, "refinechest_placer", nil, nil, nil, nil,"images/inventoryimages/refinery.xml", "refinery.tex") --configurations TUNING.REPAIRCHESTFUEL = GetModConfigData("repairchestfuel") TUNING.REFINECHESTFUEL = GetModConfigData("refinechestfuel") --containers --repair chest local params = {} params.repairchest = { widget = { slotpos ={}, animbank = "ui_chest_3x2", animbuild = "ui_chest_3x2", pos = GLOBAL.Vector3(0, 200, 0), side_align_tip = 160, }, type = "chest", } for y = 1, 0, -1 do for x = 0, 2 do table.insert(params.repairchest.widget.slotpos, GLOBAL.Vector3(80 * x - 80 * 2 + 80, 80 * y - 80 * 2 + 120, 0)) end end function params.repairchest.itemtestfn(container, item, slot) return item.components.armor or item.components.weapon or item.prefab == "telestaff" or item.prefab == "orangestaff" or item.prefab == "opalstaff" end containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, params.repairchest.widget.slotpos ~= nil and #params.repairchest.widget.slotpos or 0) --refine chest params.refinechest = { widget = { slotpos = { Vector3(-72, 0, 0), Vector3(72, 0, 0), }, animbank = "ui_chest_3x1", animbuild = "ui_chest_3x1", pos = GLOBAL.Vector3(0, 200, 0), side_align_tip = 160, buttoninfo = { text = "Refine", position = Vector3(0, -100, 0), }, }, type = "chest", } function params.refinechest.itemtestfn(container, item, slot) return refinerecipe[item.prefab] and (slot == 1 or slot == 2 and container.inst.components.machine:IsOn()) end function params.refinechest.widget.buttoninfo.fn(inst, doer) if REFINECHESTFUEL then if not inst.components.fueled:IsEmpty() then inst.components.machine:TurnOn() end else inst.components.machine:TurnOn() end end containers.MAXITEMSLOTS = math.max(containers.MAXITEMSLOTS, params.refinechest.widget.slotpos ~= nil and #params.refinechest.widget.slotpos or 0) local containers_widgetsetup_base = containers.widgetsetup function containers.widgetsetup(container, prefab, data) local t = params[prefab or container.inst.prefab] if t ~= nil then for k, v in pairs(t) do container[k] = v end container:SetNumSlots(container.widget.slotpos ~= nil and #container.widget.slotpos or 0) else containers_widgetsetup_base(container, prefab, data) end end and the mod is https://steamcommunity.com/sharedfiles/filedetails/?id=1567856396 Link to comment Share on other sites More sharing options...
s1m13 Posted June 11, 2019 Share Posted June 11, 2019 Could you fix it? Link to comment Share on other sites More sharing options...
Wolf_EX Posted June 24, 2019 Author Share Posted June 24, 2019 (edited) For some reason I never got a notification to your reply. Nope couldn't fix it. I might mess around with remote procedure calls in the future, I feel like that is the answer. Edited June 24, 2019 by Wolf_EX Link to comment 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