Anyways, I spent some spare hours on it, and I updated speedChanger to allow easier injection and manipulation of player speeds by using a dictionary and sequential percentage multiplication. This creates a system where any modder who wants to can inject their custom movement change and whatever mod is first will inject first and whichever mod is last will inject last. This means players can also use load order priority to choose what mods affect speed in what sequence.
I also updated the console to work with this.
Currently we have these public properties:
- bool walkSpeedOverride: turns on and off using walk modifier list to change player movement speed. Does not clear list, merely ignores it.
- bool runSpeedOverride: turns on and off using run modifier list to change player movement speed. Does not clear list, merely ignores it.
- bool updateWalkSpeed: turn true to recompute the walk speed; will flip false once done on next frame.
- bool updateRunSpeed: turn true to recompute the run speed; will flip false once done on next frame.
- Bool AddWalkSpeedMod(out string UID, float walkSpeedModifier = 0, bool refreshWalkSpeed = true): Add a percentage multiplier to the walk speed modifier list. Returns true if the unique ID is output as an out string value to refer to/manipulate modifier. Returns false if it couldn't add it.
- Bool AddRunSpeedMod(out string UID, float speedModifier = 0, bool refreshRunSpeed = true): Add a percentage multiplier to the runspeed modifier list. Returns true if the unique ID is output as an out string value to refer to/manipulate modifier. Returns false if it couldn't add it.
- bool RemoveSpeedMod(string UID, bool removeRunSpeed = false, bool refresSpeed = true): Remove a speed modifier using previously generated unique ID string value. Allows you to select if your removing running or walking speed modifiers. Returns true or false based on if modifier was removed or not.
- bool ResetSpeed(bool walkSpeedReset = true, bool runSpeedReset = true): Remove a speed modifier using previously generated unique ID string value. Allows you to select if your removing running or walking speed modifiers. Returns true or false based on if modifier was removed or not.
- float RefreshWalkSpeed(): Updates the players walk speed using for loop and dictionary values to ensure proper sequential processing to get proper end speed and returns updated walk speed value. Processing of modifiers is processed by their addition order. First added by modder is multiplied first, and so on.
- float RefreshRunSpeed(): Updates the players run speed using for loop and dictionary values to ensure proper sequential processing to get proper end speed and returns updated run speed value. Processing of modifiers is processed by their addition order. First added by modder is multiplied first, and so on.
- set_runspeed -1: Enable/Disable run speed sequential modifier. Does not clear modifier list, just ignores it and returns base run speed.
- set_runspeed -2: Run speed modifiers cleared. Clears out current run speed modifier list.
- set_runspeed #: Adds percentage multiplier to run speed modifier list for sequential calculation; tells user UID for added modifier so they can remove it without clearing list if they want. Users cannot insert negative numbers, other than -1 and -2.
- set_runspeed UID: Checks to see if dictionary modifier list contains UID modifer. If it does, will remove the added modifier. If not will return normal error message saying invalid input.
- set_runspeed : Returns basic error and current updated run speed.
Using these properties and routines, anyone should be able to modify player speeds how they want without fear of overriding or breaking previous mod changes. As of now, whoever adds first to the list gets computed first, and so on. I think i'll keep it this way, as it makes the most sense, and allows players to shift mods to pick which takes priority when being computed.
I was going to submit it to the base branch to be included in next update. I already have two mods that need it to work smoothly together. Would that be okay for next branch update?
Updated PlayerSpeedChanger Script
Updated DefaultCommands Script