Jump to content

Reviving Ghosts with no item + Craftable Tab opening on two players proximity


Recommended Posts

If I wanted to add an executable option to other player characters, how would I go about that? Like mainly the ghosts. I'm working on a mod that lets you resurrect ghosts (depending on the character prefab -- like you have to be a particular character to resurrect a particular character) without any items required. No penalty either, though of course I could tweak that. Would I have to add an action and a tag?

Also, I'd like to be able to figure out how to make an item craftable at the Ancient Pseudoscience Station if two particular characters are in the vicinity. Not unlike how the sacred chest works, but with the condition they're these two characters in particular, and with the effect they both receive an item after a couple of animations. Is that even possible?

Link to comment
Share on other sites

1 hour ago, DarkXero said:

You should try doing another stuff if you are not able to come up with code.

Here's some example code:

 

stuff.zip

Yeeeaah. I shall now stop making a fool of myself. Thanks! No, legit thanks for the stuff, you've been a huge help and it means a lot.

(Holy manure that is thorough. You're incredible. Thanks so much.)

Edited by Zampano
did not mean to sound PA
Link to comment
Share on other sites

But uh, I guess I'll finish what I started!

I want to replace the animation for the resurrection doer, something aside from the 'give' state. I'm experimenting with this:
 

local require = GLOBAL.require
local Action = GLOBAL.Action
local ActionHandler = GLOBAL.ActionHandler 
local State = GLOBAL.State
local EventHandler = GLOBAL.EventHandler
local STRINGS = GLOBAL.STRINGS



AddStategraphState("wilson", State {
	name = "modfreerez",
	tags = {"busy", "freerezacthand"},

onenter = function(inst)
        local sX, sY, sZ = inst.Transform:GetScale()
        inst.Transform:SetScale(-sX, sY, sZ)
		local sX, sY, sZ = inst.Transform:GetRotation()
		inst.Transform:SetRotation(-sX, sY, sZ)
		inst.AnimState:PlayAnimation("emoteXL_kiss")  
		
		 inst:PerformPreviewBufferedAction()
         inst.sg:SetTimeout(TIMEOUT)
	end,

	       ontimeout = function(inst)
            inst:ClearBufferedAction()
            inst.sg:GoToState("idle", true)
        end,
	
	events = {
		EventHandler("animqueueover", function(inst)
		    local sX, sY, sZ = inst.Transform:GetScale()
		    inst.Transform:SetScale(-sX, sY, sZ)
			local sX, sY, sZ = inst.Transform:GetRotation()
			inst.Transform:SetRotation(-sX, sY, sZ)
			inst.sg:GoToState("idle")
		end),
	},
})


-- Revive action
-- The actual happening
-- Stuff checked does not have to be networked, this is server side
local FREEREZACT = AddAction("MODFREEREZ", "Revive", function(act)
	local doer = act.doer
	local target = act.target
	if doer and target and doer.prefab == "wilson" and target:HasTag("playerghost") then
		target:PushEvent("respawnfromghost", {user = doer})
		return true
	end
end)

-- Relate the action to a state name
local freerezacthand = ActionHandler(FREEREZACT, "modfreerez")

-- Add the action handler to the player stategraph
-- Now Wilson will go to the "give" state to try and perform the freerez buffered action
AddStategraphActionHandler("wilson", freerezacthand)

-- The "give" state does not have a "pausepredict" or "nopredict" tag in tags table
-- This stategraph works out what to do with people that has movement prediction enabled
AddStategraphActionHandler("wilson_client", freerezacthand)

-- Wilson can right click on stuff (entities on the scene) with the modfreerez component
-- Remember to use networked stuff (like tags, prefab names, replicas) inside component actions
-- This makes the prompts on stuff appear
AddComponentAction("SCENE", "modfreerez", function(inst, doer, actions, right)
	if right and doer.prefab == "wilson" and inst:HasTag("playerghost") then
		table.insert(actions, FREEREZACT)
	end
end)

-- Now Willow can be revived by Wilson
AddPrefabPostInit("willow", function(inst)
	inst:AddComponent("modfreerez")
end)

But while everything plays out fine the resurrection doesn't happen? And if I wanted Willow to be able to return the favor do I just replicate the prefab and tag checks?

Edited by Zampano
Link to comment
Share on other sites

10 hours ago, Zampano said:

But while everything plays out fine the resurrection doesn't happen?

You are forgetting inst:PerformBufferedAction() to carry out the action.

10 hours ago, Zampano said:

And if I wanted Willow to be able to return the favor do I just replicate the prefab and tag checks?

You can check for doer:HasTag("modrezzer"). On both the component action and the action function.

And then do inst:AddTag("modrezzer") on both Wilson and Willow. And also add the component to both of them.

Link to comment
Share on other sites

Oh, oops. This is what it looks like now, but it still can't get it to work for some reason. :(
 

local require = GLOBAL.require
local Action = GLOBAL.Action
local ActionHandler = GLOBAL.ActionHandler 
local State = GLOBAL.State
local EventHandler = GLOBAL.EventHandler
local STRINGS = GLOBAL.STRINGS



AddStategraphState("wilson", State {
	name = "modfreerez",
	tags = {"busy", "freerezacthand"},

onenter = function(inst)
        local sX, sY, sZ = inst.Transform:GetScale()
        inst.Transform:SetScale(-sX, sY, sZ)
		local sX, sY, sZ = inst.Transform:GetRotation()
		inst.Transform:SetRotation(-sX, sY, sZ)
		inst.AnimState:PlayAnimation("emoteXL_kiss")  
        inst:PerformBufferedAction()
		
	end,
	
	events = {
		EventHandler("animqueueover", function(inst)
		    local sX, sY, sZ = inst.Transform:GetScale()
		    inst.Transform:SetScale(-sX, sY, sZ)
			local sX, sY, sZ = inst.Transform:GetRotation()
			inst.Transform:SetRotation(-sX, sY, sZ)
			inst.sg:GoToState("idle")
		end),
	},
})


-- Revive action
-- The actual happening
-- Stuff checked does not have to be networked, this is server side
local FREEREZACT = AddAction("MODFREEREZ", "Kiss of Life", function(act)
	local doer = act.doer
	local target = act.target
	if doer and target and doer.prefab == "wilson" and doer:HasTag("modrezzer") and target:HasTag("playerghost") then
		target:PushEvent("respawnfromghost", {user = doer})
		return true
	end
end)

-- Relate the action to a state name
local freerezacthand = ActionHandler(FREEREZACT, "modfreerez")

-- Add the action handler to the player stategraph
-- Now Wilson will go to the "give" state to try and perform the freerez buffered action
AddStategraphActionHandler("wilson", freerezacthand)

-- The "give" state does not have a "pausepredict" or "nopredict" tag in tags table
-- This stategraph works out what to do with people that has movement prediction enabled
AddStategraphActionHandler("wilson_client", freerezacthand)

-- Wilson can right click on stuff (entities on the scene) with the modfreerez component
-- Remember to use networked stuff (like tags, prefab names, replicas) inside component actions
-- This makes the prompts on stuff appear
AddComponentAction("SCENE", "modfreerez", function(inst, doer, actions, right)
	if right and doer.prefab == "wilson" and doer:HasTag("modrezzer") and inst:HasTag("playerghost") then
		table.insert(actions, FREEREZACT)
	end
end)

-- Now Willow can be revived by Wilson
AddPrefabPostInit("willow", function(inst)
	inst:AddTag("modrezzer")
	inst:AddComponent("modfreerez")

end)

AddPrefabPostInit("wilson", function(inst)
	inst:AddTag("modrezzer")
	inst:AddComponent("modfreerez")
end)

Also when my gf tries to play on my hosted server she gets error messages...

Link to comment
Share on other sites

3 hours ago, Zampano said:

Also when my gf tries to play on my hosted server she gets error messages...

Most likely.

Try this:

local require = GLOBAL.require
local Action = GLOBAL.Action
local ActionHandler = GLOBAL.ActionHandler 
local State = GLOBAL.State
local EventHandler = GLOBAL.EventHandler
local STRINGS = GLOBAL.STRINGS



AddStategraphState("wilson", State {
	name = "modfreerez",
	tags = {"busy", "freerezacthand", "pausepredict"},

	onenter = function(inst)
		local sX, sY, sZ = inst.Transform:GetScale()
		inst.Transform:SetScale(-sX, sY, sZ)
		local sX, sY, sZ = inst.Transform:GetRotation()
		inst.Transform:SetRotation(-sX, sY, sZ)
		inst.AnimState:PlayAnimation("emoteXL_kiss")

		if inst.components.playercontroller ~= nil then
			inst.components.playercontroller:RemotePausePrediction()
		end

		inst:PerformBufferedAction()
	end,

	events = {
		EventHandler("animqueueover", function(inst)
			local sX, sY, sZ = inst.Transform:GetScale()
			inst.Transform:SetScale(-sX, sY, sZ)
			local sX, sY, sZ = inst.Transform:GetRotation()
			inst.Transform:SetRotation(-sX, sY, sZ)
			inst.sg:GoToState("idle")
		end),
	},
})


-- Revive action
-- The actual happening
-- Stuff checked does not have to be networked, this is server side
local FREEREZACT = AddAction("MODFREEREZ", "Kiss of Life", function(act)
	local doer = act.doer
	local target = act.target
	local valid_doer = doer and doer.components.modfreerez and not doer:HasTag("playerghost")
	local valid_target = target and target.components.modfreerez and target:HasTag("playerghost")
	if valid_doer and valid_target then
		target:PushEvent("respawnfromghost", {user = doer})
		return true
	end
end)

-- Relate the action to a state name
local freerezacthand = ActionHandler(FREEREZACT, "modfreerez")

-- Add the action handler to the player stategraph
-- Now Wilson will go to the "give" state to try and perform the freerez buffered action
AddStategraphActionHandler("wilson", freerezacthand)

-- Wilson can right click on stuff (entities on the scene) with the modfreerez component
-- Remember to use networked stuff (like tags, prefab names, replicas) inside component actions
-- This makes the prompts on stuff appear
AddComponentAction("SCENE", "modfreerez", function(inst, doer, actions, right)
	if right and doer.components.modfreerez and inst:HasTag("playerghost") then
		table.insert(actions, FREEREZACT)
	end
end)

-- Now Willow can be revived by Wilson
AddPrefabPostInit("willow", function(inst)
	inst:AddComponent("modfreerez")
end)

AddPrefabPostInit("wilson", function(inst)
	inst:AddComponent("modfreerez")
end)

Since the component is added server and client side, there's no need for extra tag.

Also the state is now server only, it pauses the prediction and sends the corresponding animation (automatically).

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