red1500z Posted April 29, 2022 Share Posted April 29, 2022 I'm trying to make an item like the telltale heart but I haven't been able to make it work. Does anyone know how to make an item that is capable of reviving players? Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/ Share on other sites More sharing options...
Bumber64 Posted April 29, 2022 Share Posted April 29, 2022 (edited) There's some code about reviving in "player_common_extensions.lua", in addition to the obvious "prefabs/reviver.lua". You'll have to copy and modify some stuff from there. Edited April 29, 2022 by Bumber64 Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1564750 Share on other sites More sharing options...
red1500z Posted April 29, 2022 Author Share Posted April 29, 2022 (edited) 15 hours ago, Bumber64 said: There's some code about reviving in "player_common_extensions.lua", in addition to the obvious "prefabs/reviver.lua". You'll have to copy and modify some stuff from there. thanks but do you know any idea what i should copy or change to do Edited April 29, 2022 by red1500z Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1565149 Share on other sites More sharing options...
Bumber64 Posted April 30, 2022 Share Posted April 30, 2022 (edited) Just did some deeper digging and it looks like you'll actually need to mess with the player's "trader" component using AddPlayerPostInit. Put this code in your modmain.lua and replace "your_reviver_name_here" with your prefab: local function new_test(inst, item) --based on player_common.lua's check for reviver if inst:HasTag("playerghost") then return item.prefab == "your_reviver_name_here" and inst:IsOnPassablePoint() end end local function new_accept(inst, giver, item) --based on player_common.lua's check for reviver if item ~= nil and item.prefab == "your_reviver_name_here" and inst:HasTag("playerghost") then if item.skin_sound then item.SoundEmitter:PlaySound(item.skin_sound) end item:PushEvent("usereviver", { user = giver }) giver.hasRevivedPlayer = true GLOBAL.AwardPlayerAchievement("hasrevivedplayer", giver) item:Remove() inst:PushEvent("respawnfromghost", { source = item, user = giver }) inst.components.health:DeltaPenalty(TUNING.REVIVE_HEALTH_PENALTY) --NOTE: change this if you don't want the default max health penalty giver.components.sanity:DoDelta(TUNING.REVIVE_OTHER_SANITY_BONUS) --NOTE: change this if you don't want the default sanity boost end end AddPlayerPostInit(function(inst) if not GLOBAL.TheNet:GetIsServer() then return --don't do on client end local trader = inst.components.trader if trader == nil then --somebody removed trader component. Abort! return end local old_test = trader.test --save the old AcceptTest fn trader:SetAcceptTest(function(inst, item) if new_test(inst, item) then return true --player should accept our reviver elseif old_test ~= nil then return old_test(inst, item) --run the old test fn end end) local old_accept = trader.onaccept --save the old onaccept fn inst.components.trader.onaccept = function(inst, giver, item) new_accept(inst, giver, item) if old_accept ~= nil then old_accept(inst, giver, item) --also run the old onaccept fn end end end) Looks like the existing "player_common_extensions.lua" functions should handle custom revivers okay. There's also nothing special about the "reviver" prefab other than its name and having the "tradable" and "inventoryitem" components. Then you'll need to mess with component actions (as defined in "componentactions.lua") to allow giving your item to ghosts: AddComponentAction("USEITEM", "inventoryitem", function(inst, doer, target, actions, right) if inst.prefab == "your_reviver_name_here" and target:HasTag("playerghost") then table.insert(actions, GLOBAL.ACTIONS.GIVETOPLAYER) --give to player ghost end end) That also goes in your modmain.lua. Edited May 7, 2022 by Bumber64 Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1565495 Share on other sites More sharing options...
red1500z Posted May 6, 2022 Author Share Posted May 6, 2022 (edited) Thank you very much I'll get to work to see if I can and I have a question the object only revives if another player gives it to the ghost? and in the code of the object to revive you have to put something besides what is here? local assets = { Asset("ANIM", "anim/masamaligna.zip"), Asset("ATLAS", "images/inventoryimages/masamaligna.xml"), Asset("IMAGE", "images/inventoryimages/masamaligna.tex"), } local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("masamaligna") inst.AnimState:SetBuild("masamaligna") inst.AnimState:PlayAnimation("idle") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/masamaligna.xml" inst:AddComponent("inspectable") inst:AddComponent("tradable") MakeHauntableLaunch(inst) return inst end return Prefab("common/inventory/reviverinator", fn, assets) Edited May 6, 2022 by red1500z Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1567938 Share on other sites More sharing options...
Bumber64 Posted May 6, 2022 Share Posted May 6, 2022 (edited) On 5/6/2022 at 10:44 AM, red1500z said: and I have a question the object only revives if another player gives it to the ghost? Yes. If you want it to resurrect from haunting, I think you just need to replace MakeHauntableLaunch(inst) with: inst:AddComponent("hauntable") inst.components.hauntable:SetHauntValue(TUNING.HAUNT_INSTANT_REZ) That's from the red amulet's code, which also has inst:AddTag("resurrector"), but I'm not sure that tag is actually required, since I don't see it checked anywhere. On 5/6/2022 at 10:44 AM, red1500z said: and in the code of the object to revive you have to put something besides what is here? No, that's fine for the scripts/prefab file. You just need to add the code I posted into "modmain.lua", replacing "your_reviver_name_here" with "reviverinator". If you haven't already, you also need to put this at the top of "modmain.lua": PrefabFiles = { "reviverinator", } (Or include it in your existing PrefabFiles list.) Edited May 11, 2022 by Bumber64 Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1568034 Share on other sites More sharing options...
red1500z Posted May 7, 2022 Author Share Posted May 7, 2022 (edited) Thank you so much It works but how do I make it have a single use, do you know anything about that? Edited May 7, 2022 by red1500z Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1568247 Share on other sites More sharing options...
Bumber64 Posted May 8, 2022 Share Posted May 8, 2022 (edited) On 5/7/2022 at 9:49 AM, red1500z said: Thank you so much It works but how do I make it have a single use, do you know anything about that? That should be handled by "item:Remove()" in our "new_accept" function. If that's not happening, something's broken somewhere. Let's try not running the old_accept fn on our item if the revive succeeds. Add "return true" to new_accept here: giver.components.sanity:DoDelta(TUNING.REVIVE_OTHER_SANITY_BONUS) --NOTE: change this if you don't want the default sanity boost return true end end And replace the onaccept part of AddPlayerPostInit with these lines here: local old_accept = trader.onaccept --save the old onaccept fn inst.components.trader.onaccept = function(inst, giver, item) if not new_accept(inst, giver, item) and old_accept ~= nil then old_accept(inst, giver, item) --run the old onaccept fn if ours failed end end end) If that doesn't fix the issue, we can also try adding a 0 second delay somewhere to make sure the item is fully in the target's inventory before we attempt to remove it. Edited May 8, 2022 by Bumber64 Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1568585 Share on other sites More sharing options...
red1500z Posted May 9, 2022 Author Share Posted May 9, 2022 6 hours ago, Bumber64 said: That should be handled by "item:Remove()" in our "new_accept" function. If that's not happening, something's broken somewhere. Let's try not running the old_accept fn on our item if the revive succeeds. Add "return true" to new_accept here: giver.components.sanity:DoDelta(TUNING.REVIVE_OTHER_SANITY_BONUS) --NOTE: change this if you don't want the default sanity boost return true end end And replace the onaccept part of AddPlayerPostInit with these lines here: local old_accept = trader.onaccept --save the old onaccept fn inst.components.trader.onaccept = function(inst, giver, item) if not new_accept(inst, giver, item) and old_accept ~= nil then old_accept(inst, giver, item) --run the old onaccept fn if ours failed end end end) If that doesn't fix the issue, we can also try adding a 0 second delay somewhere to make sure the item is fully in the target's inventory before we attempt to remove it. in fact I think the code is fine but I think the problem is that the ghost when it revives by itself with the object on the ground does not add the object to its inventory and it only remains on the ground and it never touched the inventory Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1568639 Share on other sites More sharing options...
Bumber64 Posted May 10, 2022 Share Posted May 10, 2022 On 5/8/2022 at 7:15 PM, red1500z said: in fact I think the code is fine but I think the problem is that the ghost when it revives by itself with the object on the ground does not add the object to its inventory and it only remains on the ground and it never touched the inventory You mean you can haunt your item to revive? What did you do to get that working? It should be simple enough to just remove the item on the ground with that code. Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1569119 Share on other sites More sharing options...
red1500z Posted May 10, 2022 Author Share Posted May 10, 2022 (edited) 7 hours ago, Bumber64 said: You mean you can haunt your item to revive? What did you do to get that working? It should be simple enough to just remove the item on the ground with that code. i just use this on the item prefab to revive: inst:AddComponent("hauntable") inst.components.hauntable:SetHauntValue(TUNING.HAUNT_INSTANT_REZ) if this is not in the prefab you cannot revive from the object on the ground (I don't know why) 6 minutes ago, red1500z said: i just use this on the item prefab to revive: inst:AddComponent("hauntable") inst.components.hauntable:SetHauntValue(TUNING.HAUNT_INSTANT_REZ) if this is not in the prefab you cannot revive from the object on the ground (I don't know why) the full prefab looks like this local assets = { Asset("ANIM", "anim/masamaligna.zip"), Asset("ATLAS", "images/inventoryimages/masamaligna.xml"), Asset("IMAGE", "images/inventoryimages/masamaligna.tex"), } local function fn() local inst = CreateEntity() inst.entity:AddTransform() inst.entity:AddAnimState() inst.entity:AddSoundEmitter() inst.entity:AddNetwork() MakeInventoryPhysics(inst) inst.AnimState:SetBank("masamaligna") inst.AnimState:SetBuild("masamaligna") inst.AnimState:PlayAnimation("idle") inst.entity:SetPristine() if not TheWorld.ismastersim then return inst end inst:AddComponent("inventoryitem") inst.components.inventoryitem.atlasname = "images/inventoryimages/masamaligna.xml" inst:AddComponent("inspectable") inst:AddComponent("tradable") inst:AddComponent("hauntable") inst.components.hauntable:SetHauntValue(TUNING.HAUNT_INSTANT_REZ) return inst end return Prefab("common/inventory/reviverinator", fn, assets) Edited May 10, 2022 by red1500z Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1569286 Share on other sites More sharing options...
Bumber64 Posted May 11, 2022 Share Posted May 11, 2022 (edited) Looks like you just need to add this to the prefab: inst.components.hauntable:SetOnHauntFn(function(inst) inst:Remove() return true --let the game know the haunt succeeded so it can revive end) You don't even need any of the modmain.lua code I posted earlier if you don't want to have it revive from giving to other players. Edited May 11, 2022 by Bumber64 Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1569391 Share on other sites More sharing options...
red1500z Posted May 11, 2022 Author Share Posted May 11, 2022 thanks it works but I'll try to test with another computer if reviving with 2 players works correctly (thanks a lot) Link to comment https://forums.kleientertainment.com/forums/topic/139760-help-does-anyone-know-how-to-make-an-item-that-can-revive-players/#findComment-1569535 Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now