Atena Posted March 3, 2015 Share Posted March 3, 2015 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 Thanks. Link to comment https://forums.kleientertainment.com/forums/topic/51694-helphow-to-reset-the-data-of-a-player/ Share on other sites More sharing options...
DarkXero Posted March 3, 2015 Share Posted March 3, 2015 (edited) Well, you can store the old speed before changing it:local oldspeed = eater.components.locomotor.runspeedThen you change it within oneaten. Then you make it reset:eater.components.locomotor.runspeed = oldspeedYou 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 March 3, 2015 by DarkXero Link to comment https://forums.kleientertainment.com/forums/topic/51694-helphow-to-reset-the-data-of-a-player/#findComment-618906 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now