Sign in to follow this  
. . .

How to make mod character speed up other players?

Recommended Posts

. . .    4164

Hello, I need your help... So, I would like when my character's insane to give other player characters (that are kinda close to my character) a 50% speed boost but I really have no clue how I would do this :?... I feel so ashamed I ask for so much help but it's all I can do :(...

Any kind of help makes me super happy :) & thanks for reading as always :D!

Share this post


Link to post
Share on other sites
DarkXero    2892
if GLOBAL.TheNet:GetIsMasterSimulation() then

	local SPEED_RADIUS = 15
	local SPEED_MULTIPLIER = 1.5

	local function SpeedUp(inst, guy)
		guy.components.locomotor:SetExternalSpeedMultiplier(inst, "sparkspeed", SPEED_MULTIPLIER)
		guy.sparkspeedgiver = inst
	end

	local function SlowDown(inst, guy)
		guy.components.locomotor:RemoveExternalSpeedMultiplier(inst, "sparkspeed")
		guy.sparkspeedgiver = nil
	end

	local function UpdateSlowness(inst)
		for i, v in ipairs(GLOBAL.AllPlayers) do
			if v.sparkspeedgiver == inst then
				SlowDown(inst, v)
			end
		end
	end

	local function CheckAndSpeedUp(inst)
		for i, v in ipairs(GLOBAL.AllPlayers) do
			if v ~= inst then
				if inst:IsNear(v, SPEED_RADIUS) then
					if not v.sparkspeedgiver then
						SpeedUp(inst, v)
					end
				else
					if v.sparkspeedgiver == inst then
						SlowDown(inst, v)
					end
				end
			end
		end
	end

	local function ApplyFearSpeed(inst)
		if inst.fearspeedtask == nil then
			inst.fearspeedtask = inst:DoPeriodicTask(1, CheckAndSpeedUp)
		end
	end

	local function RemoveFearSpeed(inst)
		if inst.fearspeedtask ~= nil then
			inst.fearspeedtask:Cancel()
			inst.fearspeedtask = nil
		end
		UpdateSlowness(inst)
	end

	local function AddSpeedStimulator(inst)
		inst:ListenForEvent("goinsane", ApplyFearSpeed)
		inst:ListenForEvent("gosane", RemoveFearSpeed)
		inst:ListenForEvent("onremove", UpdateSlowness)
	end

	AddPrefabPostInit("wilson", AddSpeedStimulator)

end

Goes in modmain. Replace "wilson" for your character.

Multiple characters like you won't stack multipliers. Also, the multiplier doesn't apply to your character.

Share this post


Link to post
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
Sign in to follow this