Jump to content

Unsure how to apply a runspeed effect for a short duration


Recommended Posts

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

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

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

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

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
 Share

×
  • Create New...