NamelessDude77 Posted March 11, 2018 Share Posted March 11, 2018 Hello everyone, I think I'll need some expert help here! I'm making a mod that will let you pick which variant of flower or fern or succulent you want to plant, everything works fine on a server without caves. Basically you press a button to open a menu, click on an icon, close and plant your desired variant. However when running on a caves server, some information from the menu functions can't be sent to the server, I suppose. Actually I only need some strings from the buttons functions to be saved outside the menu function but it fails because the menu seems to be ran on client side. I tried using RPC but I don't quite understand how to use it properly. modmain: Assets = { Asset("IMAGE", "images/tabs.tex"), Asset("ATLAS", "images/tabs.xml"), Asset("IMAGE", "images/flowers.tex"), Asset("ATLAS", "images/flowers.xml"), Asset("IMAGE", "images/ferns.tex"), Asset("ATLAS", "images/ferns.xml"), Asset("IMAGE", "images/succulents.tex"), Asset("ATLAS", "images/succulents.xml") } local require = GLOBAL.require local MenuScreen = require "screens/menuscreen" local Names = { ["tab"] = "Flowers", ["fern"] = "random", ["flower"] = "random", ["succulent"] = "random", } AddPrefabPostInit("pottedfern", function(inst) local name = Names.fern local function SetFernType(inst, name) inst.animname = name inst.AnimState:PlayAnimation(inst.animname) end if name ~= "random" then SetFernType(inst, name) end end) AddPrefabPostInit("planted_flower", function(inst) local name = Names.flower local names = {"f1","f2","f3","f4","f5","f6","f7","f8","f9","f10"} local ROSE_CHANCE = GetModConfigData("Rose_Chance") local function SetFlowerType(inst, name) inst.animname = name inst.AnimState:PlayAnimation(inst.animname) end if name ~= "random" then SetFlowerType(inst, name) else SetFlowerType(inst, math.random() < ROSE_CHANCE and "rose" or names[math.random(#names)]) end end) AddPrefabPostInit("succulent_potted", function(inst) local name = Names.succulent:gsub("s", "") local number = GLOBAL.tonumber(name) local function SetSucculentType(inst, number) inst.plantid = number end if name ~= "random" then SetSucculentType(inst, number) end end) Toggle_Key = GetModConfigData("Toggle_Key") local function GetActiveScreenName() local screen = GLOBAL.TheFrontEnd:GetActiveScreen() return screen and screen.name or "" end local function IsDefaultScreen() return GetActiveScreenName():find("HUD") ~= nil end local function IsScoreboardScreen() return GetActiveScreenName():find("PlayerStatusScreen") ~= nil end local ignore_key = false local function set_ignore() ignore_key = true end local function PushOptionsScreen() local screen = MenuScreen() screen.togglekey = Toggle_Key screen.callbacks.tab = function(name) Names.tab = name end for name, button in pairs(screen.tab_buttons) do if name == Names.tab then button:Select() button.image:SetTint(.8, 1, .4, 1) screen:SetTab(name) else button:Unselect() end end screen.callbacks.fern = function(name) Names.fern = name -- This is what I need end for name, button in pairs(screen.fern_buttons) do if name == Names.fern then button:Select() button.image:SetTint(1, .8, .4, 1) else button:Unselect() end end screen.callbacks.flower = function(name) Names.flower = name -- This is what I need end for name, button in pairs(screen.flower_buttons) do if name == Names.flower then button:Select() button.image:SetTint(1, .8, .4, 1) else button:Unselect() end end screen.callbacks.succulent = function(name) Names.succulent = name -- This is what I need end for name, button in pairs(screen.succulent_buttons) do if name == Names.succulent then button:Select() button.image:SetTint(1, .8, .4, 1) else button:Unselect() end end screen.callbacks.ignore = set_ignore GLOBAL.TheFrontEnd:PushScreen(screen) end GLOBAL.TheInput:AddKeyUpHandler(Toggle_Key, function() if IsDefaultScreen() then if ignore_key then ignore_key = false else PushOptionsScreen() end end end) I used some code from the geometric placement mod from rezecib to make the ui, in modmain, only the callbacks stuff. Also, would it work on all clients separetely? I fear I'll have to keep this as a server admin mod only Link to comment https://forums.kleientertainment.com/forums/topic/88554-trying-to-make-mod-work-on-server-with-caves-enabled/ 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