Jump to content

Recommended Posts

Hi! I am not great at coding and I want to make a character mod with my friend, but we want a character, who can revive after a couple second, but with a little low stats. I can't find an example for my code, so I'm a little confused about it.                                                    image.thumb.png.b61b34ac80e139d2783c613412a01c06.png

Do you want the stats to simply not start at max value, or for the max value to be lowered like what happens to your health when revived with a telltale heart?

Either way, you can do this with a DoTaskInTime in the onbecameghost function in your character prefab (If you're starting from the template)

Spoiler
-- New function, somewhere above onbecameghost
local function DoRessurect(inst)
  	if inst:HasTag("playerghost") then
		inst:PushEvent("respawnfromghost") -- This sends a pushevent which is listened to in player_common_extensions that handles respawning
	end
	if inst.revivetimer ~= nil then
		inst.revivetimer:Cancel()
		inst.revivetimer = nil
	end
end

local function onbecameghost(inst)
	-- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "mycharacter_speed_mod")
  
  -- The new parts of this function, RemoveExternalSpeedMultiplier above should already be here
   if inst.revivetimer ~= nil then
		inst.revivetimer:Cancel()
   end
   inst.revivetimer = inst:DoTaskInTime(5, DoRessurect) -- 5 can be whatever you want, I recommend adding a TUNING variable in your modmain to handle the number, so it can be changed easily along with other TUNING variables you might add
end

This will already spawn you with lowered stats, but they may not be what you want them to be yet

 

  • Like 1
11 hours ago, Merkyrrie said:

Do you want the stats to simply not start at max value, or for the max value to be lowered like what happens to your health when revived with a telltale heart?

Either way, you can do this with a DoTaskInTime in the onbecameghost function in your character prefab (If you're starting from the template)

  Hide contents
-- New function, somewhere above onbecameghost
local function DoRessurect(inst)
  	if inst:HasTag("playerghost") then
		inst:PushEvent("respawnfromghost") -- This sends a pushevent which is listened to in player_common_extensions that handles respawning
	end
	if inst.revivetimer ~= nil then
		inst.revivetimer:Cancel()
		inst.revivetimer = nil
	end
end

local function onbecameghost(inst)
	-- Remove speed modifier when becoming a ghost
   inst.components.locomotor:RemoveExternalSpeedMultiplier(inst, "mycharacter_speed_mod")
  
  -- The new parts of this function, RemoveExternalSpeedMultiplier above should already be here
   if inst.revivetimer ~= nil then
		inst.revivetimer:Cancel()
   end
   inst.revivetimer = inst:DoTaskInTime(5, DoRessurect) -- 5 can be whatever you want, I recommend adding a TUNING variable in your modmain to handle the number, so it can be changed easily along with other TUNING variables you might add
end

This will already spawn you with lowered stats, but they may not be what you want them to be yet

 

Thank you so much for help! 
but I don't think I wrote it right..?image.thumb.png.c28a612e8df19046d5610b3dd6df6ac8.pngimage.thumb.png.53c596337dd5a30373bae4ca3a9624d3.png

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
×
  • Create New...