Serpens Posted August 24, 2019 Share Posted August 24, 2019 (edited) What is the equivalent of "if world.ismastershard then" which also clients can pass? I just want to know if the world is master or slave and execute the following code only on master, but for servers and clients. I could do world:HasTag("forest"), but I want my code to also work in case any mod renamed the worlds or created a new world with different name. Or should/will the master alsways have the Tag forest, regardless of its worldprefab/location ? edit: For TheShard seems to be a proxy at clients, but if I ask TheShard:IsMaster() at client, it will always return false, same for IsSlave... So is there no way fo this and I have to use netvars/RPC to tell the clients which shard it is? edit2 Solution: The Gem API Mod introduced with version 4.0.0 TheWorld.net.components.server_info:IsMasterShard() Edited September 26, 2019 by Serpens Link to comment Share on other sites More sharing options...
Maris Posted August 24, 2019 Share Posted August 24, 2019 (edited) Put this code in the root of modmain. It won't work in many functions and won't work in root of prefab and component files but in root of modmain it works perfectly. Then you may use constnts in any functions. local TheNet = GLOBAL.TheNet local SERVER_SIDE, DEDICATED_SIDE, CLIENT_SIDE, ONLY_CLIENT_SIDE if TheNet:GetIsServer() then SERVER_SIDE = true if TheNet:IsDedicated() then --Dont use GetServerIsDedicated cos it tells only about existence of --dedicated server in game session, and not about current computer. DEDICATED_SIDE = true else CLIENT_SIDE = true --Solution for "ismastersim" issue. <------- You are welcome, Serp! ;) --Use only for net vars but not with "return" operator. end elseif TheNet:GetIsClient() then SERVER_SIDE = false CLIENT_SIDE = true ONLY_CLIENT_SIDE = true end --If you are not in the game, e.g. on main menu, SERVER_SIDE will be nil. Many other common issues I fixed in mod "Top Mod". So you can add to your mod dependency or just copypaste what you need. Example of using for net vars (from my mod): AddPrefabPostInit("player_classified",function(inst) inst.showme_hint = "" inst.net_showme_hint = _G.net_string(inst.GUID, "showme_hint", "showme_hint_dirty") if CLIENT_SIDE then inst:ListenForEvent("showme_hint_dirty",function(inst) inst.showme_hint = inst.net_showme_hint:value() end) end end) Edited August 24, 2019 by Maris Link to comment Share on other sites More sharing options...
Serpens Posted August 24, 2019 Author Share Posted August 24, 2019 6 minutes ago, Maris said: Put this code in the root of modmain. It won't work in many functions and won't work in root of prefab and component files but in root of modmain it works perfectly. Then you may use constnts in any functions. local TheNet = GLOBAL.TheNet local SERVER_SIDE, DEDICATED_SIDE, CLIENT_SIDE, ONLY_CLIENT_SIDE if TheNet:GetIsServer() then SERVER_SIDE = true if TheNet:IsDedicated() then --Dont use GetServerIsDedicated cos it tells only about existence of --dedicated server in game session, and not about current computer. DEDICATED_SIDE = true else CLIENT_SIDE = true --Solution for "ismastersim" issue. <------- You are welcome, Serp! ;) --Use only for net vars but not with "return" operator. end elseif TheNet:GetIsClient() then SERVER_SIDE = false CLIENT_SIDE = true ONLY_CLIENT_SIDE = true end --If you are not in the game, e.g. on main menu, SERVER_SIDE will be nil. Many other common issues I fixed in mod "Top Mod". So you can add to your mod dependency or just copypaste what you need. thank you ,but I can't see how this is related to Shards? The aim is to find out if the shard is master (usually forest) or slave (usually caves). But problem is that ismastershard / TheShard does not work as expected on clients. Link to comment Share on other sites More sharing options...
Maris Posted August 24, 2019 Share Posted August 24, 2019 4 hours ago, Serpens said: TheShard:IsMaster() at client, it will always return false, same for IsSlave What do you mean by saying "always"? Always in PrefabPostInit function? Where? Try to check it in root of modmain and if you like those values, cache it in local vars. I'm not sure if it will help, but try. Link to comment Share on other sites More sharing options...
Serpens Posted August 24, 2019 Author Share Posted August 24, 2019 (edited) 4 minutes ago, Maris said: What do you mean by saying "always"? Always in PrefabPostInit function? Where? Try to check it in root of modmain and if you like those values, cache it in local vars. I'm not sure if it will help, but try. your code is about server/client. my question is about master/slave. That is a big difference Forest is a master shard cave is a slave shard. I tried TheShard:IsMaster() in console while being in a world with caves, being in the forest and with "Local" console. That printed false, while on Remote it printed true on the server. Edited August 24, 2019 by Serpens Link to comment Share on other sites More sharing options...
Maris Posted August 24, 2019 Share Posted August 24, 2019 (edited) I told that API functions may work different depending on the moment you use them. It's not about client/server or master/slave. It's about API functions in general, e.g. TheSomething:WhateverFn() So my suggestion is to try to cache it if you found right moment to get true value. Edited August 24, 2019 by Maris 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