speedChanger Updates for Modders

Discuss coding questions, pull requests, and implementation details.
Post Reply
l3lessed
Posts: 787
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

speedChanger Updates for Modders

Post by l3lessed »

Hey Everyone, people are starting to request mods that affect player movement speed. Specifically, people want tiles to affect movement speed, which is understandable. Walking through a few feet of snow should feel different than walking on a nice cobbled path/road. Also, it really would be a great synergy feature/mod for expanded roads by giving them the purpose of being the fastest way to travel/move.

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.
  • float currentWalkSpeed: The current walk speed after being computed sequentially.
  • float currentRunSpeed: The current runspeed after being computed sequentially.
  • 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.
Currently we have these public routines:
  • Bool AddWalkSpeedMod(out string UUID, 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 UUID, 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 UUID, 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.
Current console command settings are. These apply the same to set_walkspeed console command:
  • 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 UUID 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 UUID: Checks to see if dictionary modifier list contains UUID modifer. If it does, will remove the added modifier. If not will return normal error message saying invalid input.
any negative number, other than -1 or -2 will return an error, since we never want a negative multiplier in our list. Also, users can put up to 4 characters into the console, so they can do more precise percentages if they wish.

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
Last edited by l3lessed on Tue Mar 09, 2021 12:31 am, edited 5 times in total.
My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 787
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: speedChanger Updates for Modders

Post by l3lessed »

Here is an example of how to use it in your own mods.

First, you need to setup a string property to contain the unique ID of your custom run and walk speed modification. This is critical to ensure you can remove and manipulate your speed change value later, and the properties will not allow you to run them without these setup for the out var.

Code: Select all

    private string walkModiferValueID;
    private string runModiferValueID;
After that, all you need to do is use the speed changer AddWalkSpeedMod() and AddRunSpeedMod() to add and store your custom movement modifier. Note that the UID is pushed as an out var to ensure you always store it for later use.

Code: Select all

        playerSpeedChanger.AddWalkSpeedMod(out walkModiferValueID, moveModifier);
        playerSpeedChanger.AddRunSpeedMod(out runModiferValueID, moveModifier);
At this point, it will update the players speed by the percentage inputted. You want to slow the player down by 25% of their current movement rate, then use the multipler .75f. This will make them run 75% of their current speed or a 25% reduction is the other way to see it.

Once you are ready to restore the players movement speeds, you now will use those stored string ids to remove your specific added modifiers, like so

Code: Select all

        playerSpeedChanger.RemoveSpeedMod(walkModiferValueID,false,true);
        playerSpeedChanger.RemoveSpeedMod(runModiferValueID,true, true);
The one thing to pay attention to here is the RemoveSpeedMod() property defaults to removing walk speed modifiers. If you wish to remove run speed modifiers instead, there is a removeRunSpeed bool switch you need to switch to true. Make sure to use the proper stored UID when choosing the run or walk speed removal.

And that is it. You have added, stored, and removed your custom movement speeds with three lines of code really.
Last edited by l3lessed on Tue Mar 09, 2021 12:29 am, edited 2 times in total.
My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 787
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: speedChanger Updates for Modders

Post by l3lessed »

Updated above documentation with the last modifications and refactoring.
  • Changed AddRunSpeedMod and AddWalkSpeedMod to bool outputs and then used an out string var to capture the added speed modifiers UUID. This was done to ensure modders know to create and store the UUID's for modification and removal, AKA minimize possible coding bugs for future modders.
  • Added UUID Modifier console output for when user adds a speed modifier through console. It now reads out the the added speed modifier Universal Unique Identifier along with changed speed.
  • Added console check for set_walkspeed/set_runspeed to see if the input was a UUID in the modifier dictionary list, and if it finds it, to remove it. This will allow players to add and remove individual modifiers through console without having to clear the whole list, if they don't want to reset all the other modifiers added by other mods.
  • Some bug oversight fixes.
  • Changed it so user can input as many characters/numbers into console without it returning an error. I had to do this to ensure UUID's could be inserted into the console and used.
Documentation above was updated to reflect the changes and how to use them in code.
Last edited by l3lessed on Tue Mar 09, 2021 12:37 am, edited 1 time in total.
My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 787
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: speedChanger Updates for Modders

Post by l3lessed »

Tested on clean base repo build. Everything is working as intended. Cleaned up console messages some and fixed a small copy/past notation copyright notation error. Pushed to master for acceptance.
My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 787
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: speedChanger Updates for Modders

Post by l3lessed »

Player speed not changing when loading a new game has been found and fixed. Player speed will be reset and recalculated any time a new game is loaded.

Player speed not changing when the base walk or run speed is updated through an increased stat or skill has been found and fixed. Now, anytime your base walk or run speed changes, it will trigger the update cycle and ensure proper speed is calculated using the new base run or walk speed.

This stops speeds from carrying over from previous games and ensures speeds will update properly when stats change from items or leveling.

This should make these additions to speedChanger bug free and ready for use by developers who want to modify player speed.

Only addition I would like at this point, but is not required, is a lerp calculator to allow speed changes to take place over time. This would be nice for added nuance and control and would allow for more immersive things, like water or snow slowing you down over a second or two versus the jerkiness of an instant speed change.
My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

l3lessed
Posts: 787
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: speedChanger Updates for Modders

Post by l3lessed »

Any chance this can make it into one of the new builds? Until this, or another method is coded to handle multiple player speed change inputs, there is no easy way for mods to change player speed, especially the moment you end up with more than one mod changing them. I can't develop my interactive terrain mod and combat overhaul mod in this area until this is remedied in some form.
My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

User avatar
Interkarma
Posts: 6211
Joined: Sun Mar 22, 2015 1:51 am

Re: speedChanger Updates for Modders

Post by Interkarma »

l3lessed wrote: Wed Mar 24, 2021 6:25 pm Any chance this can make it into one of the new builds?
Please submit a PR with your changes if you'd like something reviewed to go into game. :)

https://github.com/Interkarma/daggerfall-unity/pulls

Please also consider that I recently completed a review of movement speed to better match classic. This required many hours of tedious tuning that I don't wish to repeat. Any changes would need to not affect the core game speeds as a baseline.

l3lessed wrote: Mon Mar 22, 2021 10:30 pm Player speed not changing when loading a new game has been found and fixed. Player speed will be reset and recalculated any time a new game is loaded.
I can't recall this one being reported before. If you submit a PR, please separate the bug fix from the feature change request. I'm better able to expedite a bug fix when it's not combined with other changes.

l3lessed
Posts: 787
Joined: Mon Aug 12, 2019 4:32 pm
Contact:

Re: speedChanger Updates for Modders

Post by l3lessed »

As always thanks for the info and assist.

Iam submitting it the wrong way for review. I'll submit it to the proper repo for review.

Thanks for the update on your speed changes. This should not affect base speed numbers at all. It will take the new base speed calculations you put all the effort into and then run them through the sequential multiplier loop to get the end adjusted movement speed. Base formulas will not be touched in anyway.

Sorry, didn't clarify. Those bugs I mentioned are only a result of my changes. My sequential calculator was not triggering when base speeds would change and stored movement modifier values carried into loaded saves because of my additions.
My Beth Mods: l3lessed Nexus Page

Daggerfall Unity mods: Combat Overhaul Mod

Enjoy the free work I'm doing? Consider lending your support.

Post Reply