Jump to content

Ghost speed doesn't work


Recommended Posts

What I was trying to make is to increase ghost speed to 300%, and the speed after reviving to 300% (for 45 secs after revive).
However it doesn't work.

modmain.lua

Spoiler

local speedmultiplier = 3


local function onDeath(inst, data, ...)
	inst:AddComponent("locomotor")
    if inst.components.locomotor then
		--print("[bGSU] setMultiplier")
        inst.components.locomotor:SetExternalSpeedMultiplier(inst, "ghostspeed", speedmultiplier)
    end
end

local function onRessurection(inst, data, ...)
	inst:AddComponent("locomotor")
    if inst.components.locomotor then
	--	print("[bGSU] RemoveExternalSpeedMultiplier(")
        inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "ghostspeed")
    end
end

local function afterResurrection(inst, data, ...)
    inst:AddComponent("locomotor")
    if inst.components.locomotor then
        inst.components.locomotor:SetExternalSpeedMultiplier(inst, "resurrectionspeed", speedmultiplier)
        inst:DoTaskInTime(45, function()
            inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "resurrectionspeed")
        end)
    end
end

local function overrideGhostSpeed(player_inst)
    player_inst:ListenForEvent("makeplayerghost", onDeath)
    player_inst:ListenForEvent("respawnfromghost", onRessurection)
    player_inst:ListenForEvent("respawnfromghost", afterRessurection)
	--print("[bGSU] handlers registered")
end

AddPlayerPostInit(overrideGhostSpeed)

 

modinfo.lua

Spoiler

name = "Ghost and revive speedup"

description = "Increased ghost speed and speed after revival"

author = "Aurorance"

version = "0.1"

api_version = 10

dont_starve_compatible = false
reign_of_giants_compatible = false
dst_compatible = true

forumthread = ""

all_clients_require_mod = true
clients_only_mod = false

server_filter_tags = { "Tweak" }

icon_atlas = "modicon.xml"
icon = "modicon.tex"


priority = -7.0037857501

 

Any help would be greatly appreciated !

Edited by Aurorance
Link to comment
Share on other sites

On 5/12/2021 at 2:34 AM, TheSkylarr said:

I Believe esctemplate resets character speed on revive and death to configured values in the characters prefab, you may wanna take a look in there.

I finished the code with the advice and suggestions from Electroely.
(Might be useful for anyone that shares the same question)
Here's the code:

AddPlayerPostInit(function(inst, data)
	inst:ListenForEvent("makeplayerghost", function(inst, data, ...)
        if inst:HasTag("player") and inst.components.locomotor ~= nil then
            inst.components.locomotor:SetExternalSpeedMultiplier(inst, "ghostspeed", 3)
        end
    end)

    inst:ListenForEvent("respawnfromghost", function(inst, data, ...)
        if inst:HasTag("player") and inst.components.locomotor ~= nil then
            inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "ghostspeed")
        end
    end)

    inst:ListenForEvent("respawnfromghost", function(inst, data, ...)
        if inst:HasTag("player") and inst.components.locomotor ~= nil and (data == nil or data.source == nil or (data.source.prefab ~= "amulet" and data.source.prefab ~= "reviver" and data.source.prefab ~= "resurrectionstatue")) then
            inst.components.locomotor:SetExternalSpeedMultiplier(inst, "resurrectionspeed", 3)
            inst:DoTaskInTime(25, function()
                inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "resurrectionspeed")
            end)
        end
    end)
end)

Thanks for the reply anyway!

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