Ixzine Posted January 7, 2018 Share Posted January 7, 2018 I am creating a custom character and doing scripting. I want to increase runspeed by ~35% (from 6 to 8?) for 1.5 seconds when picking up an item. This is intended to apply when picking an item up off the ground, although it'd be fun if this could work when picking items up from containers and also when players give him an item. I assume I start in the character's prefab.lua under the master_postinit with something like Quote if data.target.components.workable.action == TAKEITEM = Action() then . . . ? I failed to think of any prefab I could read off the top of my head that applies an effect only in the duration of seconds, or how exactly runspeed should be altered in this case, so can anyone help me out here? Thanks. Link to comment Share on other sites More sharing options...
caioketo Posted January 7, 2018 Share Posted January 7, 2018 I believe there is events on pickup, or something that you could listen too. Need to do a search inside the files to see which event it fires when an item is picked up, and listen for that. Link to comment Share on other sites More sharing options...
. . . Posted January 9, 2018 Share Posted January 9, 2018 for like a speed boost when you get a item pot this code in YOURCHAR.lua above the master_postinit local function get_item_speedboost(inst) if inst.item_speedboost == nil then inst.item_speedboost = true inst.components.locomotor:SetExternalSpeedMultiplier(inst, "item_speedboost", 2) -- replace 2 with how much faster you get, 2 is like double speed inst:DoTaskInTime(3, function() inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "item_speedboost") inst.item_speedboost = nil end) -- you replace 3 with how many seconds you want the boost to last end end and this one inside the master_postinit inst:ListenForEvent("onpickupitem", get_item_speedboost) inst:ListenForEvent("itemget", get_item_speedboost) inst:ListenForEvent("picksomething", get_item_speedboost) inst:ListenForEvent("gotnewitem", get_item_speedboost) Link to comment Share on other sites More sharing options...
Ixzine Posted January 10, 2018 Author Share Posted January 10, 2018 2 hours ago, SuperDavid said: for like a speed boost when you get a item pot this code in YOURCHAR.lua above the master_postinit Thanks, this helps a lot! Though, I'm playing around with it but I can't figure out how to get the effect to apply again if it's already going. Is there any way to adjust this so that it refreshes the duration? I assume it's running a second task if I pick up a second item while the first boost is running, but ends them both simultaneously? I don't know how this works. Anyway, thanks again. Link to comment Share on other sites More sharing options...
. . . Posted January 10, 2018 Share Posted January 10, 2018 Just now, Ixzine said: Thanks, this helps a lot! Though, I'm playing around with it but I can't figure out how to get the effect to apply again if it's already going. Is there any way to adjust this so that it refreshes the duration? I assume it's running a second task if I pick up a second item while the first boost is running, but ends them both simultaneously? I don't know how this works. Anyway, thanks again. If the speed boost is already in effect it won't apply the effect again, sorry I don't know how to do that Link to comment 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