I will share my code.
This script will always set movement speed to 40, doesn't matter if you have any bonus movement speed from items, mounts or spells.
Don't add dispel haste condition, because if you dispel haste, it will instantly remove players speed to minimum and he won't be able to move...