Jump to content

[Help]How to reset the data of a player?

Recommended Posts

I try to write a mod let a player eat somthing increase speed temporarily. At time up, I want to reset the original speed of this player, How count I do?


my code:


this item.


local function fn()  .....  inst:AddComponent("edible")  inst.components.edible.healthvalue = 0  inst.components.edible.hungervalue = 0  inst.components.edible.foodtype = "VEGGIE"  inst.components.edible:SetOnEatenFn(oneaten)  MakeHauntableLaunch(inst)  return instendlocal function oneaten(inst, eater)    if eater and eater.components.locomotor.runspeed < 20 then      -- Speedup 30%      eater.components.locomotor.runspeed = math.min(maxspeed, eater.components.locomotor.runspeed *1.3)      eater:DoTaskInTime(100, normspeed)        end    endlocal function normspeed(eater)      how to do? Reset eater's original speedend



Link to comment
Share on other sites

Well, you can store the old speed before changing it:

local oldspeed = eater.components.locomotor.runspeed

Then you change it within oneaten.


Then you make it reset:

eater.components.locomotor.runspeed = oldspeed

You can also make use of the SetExternalSpeedMultiplier function of locomotor, to apply a multiplier identified by a key, and then RemoveExternalSpeedMultiplier with that key. As in here: http://forums.kleientertainment.com/topic/51520-what-if-two-mods-are-going-to-tweak-charater-speed/ to replace your runspeed line with AddMultiplier and your normal function with RemoveMultiplier.


You can also apply the arithmetic inversed:

eater.components.locomotor.runspeed = eater.components.locomotor.runspeed / 1.3 
Edited by DarkXero
Link to comment
Share on other sites

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...