iuiu Posted April 26, 2021 Share Posted April 26, 2021 I want to let game time speed x2. then I execute TheSim:SetTimeScale(2) in game console (open with `). It works. And It not work when i execute that within mod. So I guess it may be because the code permissions executed in the mod does not have mastersim. Alse may be mod env not mastersim? How can I make TheSim:SetTimeScale(2) effective when executed in mod? Thx Link to comment https://forums.kleientertainment.com/forums/topic/129325-how-to-let-theworldismastersim-true-in-mod/ Share on other sites More sharing options...
CarlZalph Posted April 26, 2021 Share Posted April 26, 2021 If the client is the server (world without caves, self hosted), then the client can freely run that command without issue. Most cases, however, the client and server are two processes and as such you should be using an RPC to control it in this case. 1 Link to comment https://forums.kleientertainment.com/forums/topic/129325-how-to-let-theworldismastersim-true-in-mod/#findComment-1452886 Share on other sites More sharing options...
iuiu Posted April 26, 2021 Author Share Posted April 26, 2021 3 hours ago, CarlZalph said: If the client is the server (world without caves, self hosted), then the client can freely run that command without issue. Most cases, however, the client and server are two processes and as such you should be using an RPC to control it in this case. thank you! I defined a RPC handler with AddModRPCHandler() ,And use SendModRPCToServer() when input event trigger . Then TheNet:Announce() is worked. but TheSim:SetTimeScale(2) is not work Here is the code: AddModRPCHandler( "world_time", "scale", function(player, timeScale) if TheNet:GetIsClient() then print("[DEBUG LOG]: client, skip input event!!") else TheSim:SetTimeScale(timeScale) -- not work TheNet:Announce("当前世界时间流速为: x" .. timeScale) -- work well! end end ) local currentTimeScale = 1 TheInput:AddKeyHandler( function(key, down) if down then print(key) if key == 91 then -- [ if currentTimeScale > 1 then currentTimeScale = currentTimeScale - 1 SendModRPCToServer(MOD_RPC["world_time"]["scale"], currentTimeScale) end elseif key == 93 then -- ] if currentTimeScale < 4 then currentTimeScale = currentTimeScale + 1 SendModRPCToServer(MOD_RPC["world_time"]["scale"], currentTimeScale) end elseif key == 48 then -- 0 currentTimeScale = 1 SendModRPCToServer(MOD_RPC["world_time"]["scale"], currentTimeScale) end end end ) Link to comment https://forums.kleientertainment.com/forums/topic/129325-how-to-let-theworldismastersim-true-in-mod/#findComment-1452912 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