Jump to content

How to let TheWorld.ismastersim == true in mod ?


Recommended Posts

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
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...