Just remember to switch Hero to your character id, HeroWalkX animation names to your walk animations ids and MainHeroOutfit to your character outfit id. Also depending on your resolution tweak minSpeed and fullWalkSpeed variables.
Also I wrote 360-23 etc. instead of 337 because it's more obvious what it means feel free to change that as well.
fullWalkSpeed = 300
minSpeed = 100function OnMainLoop()
if( getObject( "Characters[Hero]" ):getInt( VCharacterState )==3 ) then
local direction = getObject("Characters[Hero]"):getInt(VCharacterDirection)
if( direction > 360-23 or direction < 23 ) then
weight = getObject("ActiveAnimations[HeroWalkE]"):getInt(VAnimationSize)
elseif( direction > 315-23) then
weight = getObject("ActiveAnimations[HeroWalkSE]"):getInt(VAnimationSize)
elseif( direction > 270-23) then
weight = getObject("ActiveAnimations[HeroWalkS]"):getInt(VAnimationSize)
elseif( direction > 225-23) then
weight = getObject("ActiveAnimations[HeroWalkSW]"):getInt(VAnimationSize)
elseif( direction > 180-23) then
weight = getObject("ActiveAnimations[HeroWalkW]"):getInt(VAnimationSize)
elseif( direction > 135-23) then
weight = getObject("ActiveAnimations[HeroWalkNW]"):getInt(VAnimationSize)
elseif( direction > 90-23) then
weight = getObject("ActiveAnimations[HeroWalkN]"):getInt(VAnimationSize)
elseif( direction > 45-23) then
weight = getObject("ActiveAnimations[HeroWalkNE]"):getInt(VAnimationSize)
end
weight=weight/100.0
getObject("Outfits[MainHeroOutfit]"):setValue(VOutfitCharacterSpeed,weight*fullWalkSpeed+minSpeed)
end
end
registerEventHandler("mainLoop", "OnMainLoop")
-- let's create some initial variables
local minSpeed = 120 -- min speed value
local maxSpeed = 350 -- approx normal walking speed value
local initialTime = getTime() -- store the initial time of the timer
local targetTime = 500 -- set target time in ms (to prevent setWalkSpeed from being called 100's of times in under a second)
-- let's create the function in which we set the walk speed of the current character
function setWalkSpeed()
tblWalk = {}
tblWalk["_temporary_"] = ""
tblWalk[1] = game:getLink(VGameCurrentCharacter) -- store current character
tblWalk[2] = tblWalk[1]:getInt(VCharacterSize) / 100 -- store current character scale & divide by "100"
tblWalk[3] = tblWalk[1]:getLink(VCharacterCurrentOutfit) -- store current character outfit
tblWalk[4] = tblWalk[3]:getInt(VOutfitCharacterSpeed) -- store current outfit speed
tblWalk[5] = tblWalk[2] * maxSpeed + minSpeed -- calculate the new walk speed
-- * break * --
if tblWalk[5] > maxSpeed then tblWalk[5] = maxSpeed end -- check if walk speed is more than max speed
if tblWalk[4] ~= tblWalk[5] then tblWalk[3]:setValue(VOutfitCharacterSpeed, tblWalk[5] ) end -- set the new walk speed
end
-- let's create the onMainLoop function in which we store functions we want to loop
function onMainLoop()
if (game:getLink(VGameCurrentCharacter):getInt(VCharacterState) == 3) and (getTime() >= initialTime + targetTime) then -- is character walking & has the timer elapsed a specific time?
getTime({flags=1, reset=true}) -- reset the timer back to 0
setWalkSpeed() -- call walk speed function
end
end
-- let's create the mainLoop handler
registerEventHandler("mainLoop", "onMainLoop")
02:50:23: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:24: the mainLoop handler loops rapidly
02:50:25: the mainLoop handler loops rapidly
02:50:25: the mainLoop handler loops rapidly
02:50:25: the mainLoop handler loops rapidly
-- * begin walk speed code * --
-- let's create some initial variables
local minSpeed = 120 -- min speed value
local maxSpeed = 350 -- approx normal walking speed value
-- let's create the function in which we set the walk speed of the current character
function setWalkSpeed()
tblWalk = {} -- empty table
tblWalk["_temporary_"] = "" -- set as temporary table
tblWalk[1] = game:getLink(VGameCurrentCharacter) -- store current character
tblWalk[2] = tblWalk[1]:getInt(VCharacterSize) / 100 -- store current character scale & divide by "100"
tblWalk[3] = tblWalk[1]:getLink(VCharacterCurrentOutfit) -- store current character outfit
tblWalk[4] = tblWalk[3]:getInt(VOutfitCharacterSpeed) -- store current outfit speed
tblWalk[5] = tblWalk[2] * maxSpeed + minSpeed -- calculate the new walk speed
-- * break * --
if tblWalk[5] > maxSpeed then tblWalk[5] = maxSpeed end -- check if walk speed is more than max speed
if tblWalk[4] ~= tblWalk[5] then tblWalk[3]:setValue(VOutfitCharacterSpeed, tblWalk[5] ) end -- set the new walk speed (only if new speed is not same as current speed value)
end
-- * end walk speed code * --