Jump to content

Recommended Posts

Hi there! I'm very new to modding and having some trouble putting together the correct code for a universal base speed boost for all characters on the server, that can still be affected by variables like equippables and turfs. I've been making my way through the tutorials and searching for folks who have asked similar questions, but it seems like most are with regards character-specific boosts, whereas I'd like to add a flat 20% boost for everyone, regardless of character. I've tried messing around with the walk and run speeds as found in the locomotor.lua file, as well as peeking at the code other modders have used for similar functions, but just about everything I've found has some sort of contingency that I don't need (such as steadily increasing and decreasing speed over time).

Any help would be appreciated and I apologize in advance if this has already been covered somewhere super obvious!

Link to comment
https://forums.kleientertainment.com/forums/topic/168120-universal-speed-boost/
Share on other sites

2 hours ago, Pooklet said:

Hi there! I'm very new to modding and having some trouble putting together the correct code for a universal base speed boost for all characters on the server, that can still be affected by variables like equippables and turfs. I've been making my way through the tutorials and searching for folks who have asked similar questions, but it seems like most are with regards character-specific boosts, whereas I'd like to add a flat 20% boost for everyone, regardless of character. I've tried messing around with the walk and run speeds as found in the locomotor.lua file, as well as peeking at the code other modders have used for similar functions, but just about everything I've found has some sort of contingency that I don't need (such as steadily increasing and decreasing speed over time).

Any help would be appreciated and I apologize in advance if this has already been covered somewhere super obvious!

You can do it like this:

-- modmain.lua
GLOBAL.SpeedMultiply = function()
  for _,player in pairs(GLOBAL.AllPlayers) do 
    if player.components and player.components.locomotor then 
      player.components.locomotor:SetExternalSpeedMultiplier(player, "name_of_bonus", 1.20) 
    end 
  end 
end

Although you don't have to put it in GLOBAL.SpeedMultiply, you can put it wherever you need. If you put it somewhere other than modmain.lua, then delete the GLOBAL from AllPlayers. Also, remember that this function must be running on the server side for it to work.

32 minutes ago, FerniFrenito said:

You can do it like this:

-- modmain.lua
GLOBAL.SpeedMultiply = function()
  for _,player in pairs(GLOBAL.AllPlayers) do 
    if player.components and player.components.locomotor then 
      player.components.locomotor:SetExternalSpeedMultiplier(player, "name_of_bonus", 1.20) 
    end 
  end 
end

Although you don't have to put it in GLOBAL.SpeedMultiply, you can put it wherever you need. If you put it somewhere other than modmain.lua, then delete the GLOBAL from AllPlayers. Also, remember that this function must be running on the server side for it to work.

Thank you very much! And, making sure the function is running on the server side, is that handled in modinfo.lua or in a separate file?

5 hours ago, Pooklet said:

Thank you very much! And, making sure the function is running on the server side, is that handled in modinfo.lua or in a separate file?

It's more complex than that. I'm thinking it would be helpful to make a guide on it based on what I know. Well, to answer your question, it depends on how the code is handled. If I'm not mistaken, the code in modmain.lua always runs on the server, and from there you can send an RPC to the client or the caves server, and everything that runs in that RPC will be executed on that side.

It's also worth mentioning that it depends on how you create the world. If you create it without caves and in local mode, the server won't exist and will merge with the client, but if you create a world with caves (even if it's local) or one in which more people can join, then a server will exist separate from the client. It's necessary to take this into account whenever creating a mod because the objects that exist on the client are not the same as those that exist on the server. On the client, they usually have many fewer properties than on the server and that can cause your mod to crash.

Edited by FerniFrenito

Thank you for the explanation and for you ongoing help with this! I would definitely be interested in that tutorial if you do end up writing it. :) I'm still in the early stages of muddling my way through stuff like RPC. The world I'm running does have caves, it's a friends-only server for just my wife and I (online, not local mode).

2 minutes ago, Pooklet said:

Thank you for the explanation and for you ongoing help with this! I would definitely be interested in that tutorial if you do end up writing it. :) I'm still in the early stages of muddling my way through stuff like RPC. The world I'm running does have caves, it's a friends-only server for just my wife and I (online, not local mode).

I see, I'll try to do it, although I don't know much about RPCs either.
Anyway, if you need help with something specific, you can send me a DM here or on Discord and I'll be happy to help.

22 hours ago, FerniFrenito said:

I see, I'll try to do it, although I don't know much about RPCs either.
Anyway, if you need help with something specific, you can send me a DM here or on Discord and I'll be happy to help.

I don't have DMing privileges yet (I've had this account since 2017, but I've only ever lurked) so hopefully it's alright if I continue to message you here. I tried using the code you posted in my modmain but still no luck for some reason. I assume it's not configured correctly to run server side? But I'm not sure how to get it to do that.

20 minutes ago, Pooklet said:

I don't have DMing privileges yet (I've had this account since 2017, but I've only ever lurked) so hopefully it's alright if I continue to message you here. I tried using the code you posted in my modmain but still no luck for some reason. I assume it's not configured correctly to run server side? But I'm not sure how to get it to do that.

Can you pass me the code you have in your modmain.lua?

On 9/22/2025 at 10:32 PM, FerniFrenito said:

Can you pass me the code you have in your modmain.lua?

I copy/pasted the code you provided above into the modmain.lua, there's nothing else in there other than this:

GLOBAL.SpeedMultiply = function()
  for _,player in pairs(GLOBAL.AllPlayers) do 
    if player.components and player.components.locomotor then 
      player.components.locomotor:SetExternalSpeedMultiplier(player, "name_of_bonus", 1.20) 
    end 
  end 
end
57 minutes ago, Pooklet said:

I copy/pasted the code you provided above into the modmain.lua, there's nothing else in there other than this:

GLOBAL.SpeedMultiply = function()
  for _,player in pairs(GLOBAL.AllPlayers) do 
    if player.components and player.components.locomotor then 
      player.components.locomotor:SetExternalSpeedMultiplier(player, "name_of_bonus", 1.20) 
    end 
  end 
end

To apply the speed you need to write in the console

SpeedMultiply()

Now, to put the speed bonus somewhere specific in your code, just copy what's inside the function and paste it where you want it to run.

On 9/24/2025 at 12:11 PM, FerniFrenito said:

To apply the speed you need to write in the console

SpeedMultiply()

Now, to put the speed bonus somewhere specific in your code, just copy what's inside the function and paste it where you want it to run.

Hi, sorry for the late reply, it's been a busy week!


So, is there not a way to automatically apply the buff without a console command? I've actually been experiencing this effect as a bug with another mod, Coffee & More, where the coffee buff is applied eternally if at any point you drink a coffee, let it run out, and log out of the game, and then just never drink another coffee. Now every single time I log back in, I still have the 1.2 speed buff unless I change characters at the postern (although it can be recreated with the same initial method). I have no idea if this is inherent to this mod or if it's a conflict with something else I'm running, but I think it would be cool to have the boost intentionally, without having to rely on a bug in a very large mod that I mostly don't use anymore.

13 minutes ago, Pooklet said:

Hi, sorry for the late reply, it's been a busy week!


So, is there not a way to automatically apply the buff without a console command? I've actually been experiencing this effect as a bug with another mod, Coffee & More, where the coffee buff is applied eternally if at any point you drink a coffee, let it run out, and log out of the game, and then just never drink another coffee. Now every single time I log back in, I still have the 1.2 speed buff unless I change characters at the postern (although it can be recreated with the same initial method). I have no idea if this is inherent to this mod or if it's a conflict with something else I'm running, but I think it would be cool to have the boost intentionally, without having to rely on a bug in a very large mod that I mostly don't use anymore.

Of course, you can put it wherever you need it without having to call a command in the console, but its implementation depends on where you want to put it. I think all of this is beyond the thread's initial question, and to avoid cluttering the thread with "unnecessary" answers for those who come to view it with the same question, I can help you through the Steam messages. Should I give you my friend code or can you give me yours?

As far as I know, the mod shouldn't persist, since saving things between world loads usually requires a special code. So that's probably due to something else.

local modnamespace = "YOUR_MOD_NAME" -- It should be a name that is difficult for someone else to repeat, since the goal is for this to be unique.
local speed_bonus_name = "your_bonus_name" -- Bonus name. This can be used to remove the bonus.
local function AddSpeedBonus(player)
    if player.components and player.components.locomotor then 
        player.components.locomotor:SetExternalSpeedMultiplier(player, speed_bonus_name, 1.20) 
    end 
end
AddModRPCHandler(modnamespace, "addSpeedBonus", AddSpeedBonus) -- RPC handler for server forest
AddShardModRPCHandler(modnamespace, "addSpeedBonus", AddSpeedBonus) -- RPC handler for caves (i think)
AddPrefabPostInit("world",function(instWorld) -- Set a listener in the world
    instWorld:ListenForEvent("playeractivated", function(world, player) -- Listening when a player spawns
        if #GLOBAL.Shard_GetConnectedShards() > 0 then -- Check if the world has shards
            SendModRPCToShard(GetShardModRPC(modnamespace, "addSpeedBonus"), nil, player) -- send RPC to caves (i think)
        end
        SendModRPCToServer(GetModRPC(modnamespace, "addSpeedBonus"), player) -- Send RPC to forest
    end)
end)

This is the final code. It adds the speed bonus when a player joins the game, whether in the forest or caves.

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
×
  • Create New...