Bloodysanta Posted November 21, 2020 Share Posted November 21, 2020 (edited) Hi, I am very new to modding of any kind but I figured I'd give it a shot, although I'm unsure of how doable this is especially for a beginner- Please help if you can Basically, I want to make it so instead of a skeleton the character drops a custom item. I know there is plenty of info on custom items but I cant find a single thing to help replace a skeleton upon death. Secondly, is it possible to make this character respawn after a set time at their point of death? (Like after two days the character gets transported back to the point of death and the respawn animation plays) And finally (least important to me, I could go without being able to) is it possible to make it so they don't drop inventory? And also possibly if you interact with the custom item it drop their inventory? I highly doubt that last bit is anywhere near possible but might as well ask. I know this is a lot to ask but if you can, I'd appreciate some help. Thanks! Edited November 21, 2020 by Bloodysanta grammar was hard to comprehend Link to comment Share on other sites More sharing options...
Psychomaniac Posted November 21, 2020 Share Posted November 21, 2020 (edited) For the "don't drop inventory" there is a mod on work shop, download it and take a look at the code. https://steamcommunity.com/sharedfiles/filedetails/?id=2110246021&searchtext=dont+drop I know next to zero about coding, so can't help you much, best ways to learn (for me) is go to steam workshop, search for char that have the same ability you want (like i searched "don't drop") > subcribe > have a look at there script and try to figure out, and if i can't figure out try look for help on the 4rum, try other mods, compare code between mod, pick all the line and post it on the 4rum, and some pro-coder will help....eventually :D. (but you need to be very specific about what you want). Try read some topic with the [Solved] in the name and see how the op ask for help. The mods is located in Steam\steamapps\common\Don't Starve Together\mods folder, see the id=2110246021, the number part is the name of the mod's folder Edited November 21, 2020 by Psychomaniac 1 Link to comment Share on other sites More sharing options...
Ziro2k Posted November 27, 2020 Share Posted November 27, 2020 For your first question, player skeleton spawning is handled in the player_common_extensions file. You will need to override the OnMakePlayerGhost function in order to prevent a skeleton from spawning when a player becomes a ghost (note, in gamemodes without ghosts enabled OnPlayerDied will need to be overridden instead, but I'll leave that to you if you care for that edge case). Check if the player that died is your custom character, and spawn your custom item instead of a skeleton if it is: local ex_fns = GLOBAL.require "prefabs/player_common_extensions" local _OnMakePlayerGhost = ex_fns.OnMakePlayerGhost ex_fns.OnMakePlayerGhost = function(inst, data) if inst:HasTag("playerghost") then return end --This won't spawn your custom item if not on solid ground. Move the spawning code out from within the check if you want it to do so. if data ~= nil and data.skeleton and GLOBAL.TheSim:HasPlayerSkeletons() and inst.prefab == "your character name here" then local item = GLOBAL.SpawnPrefab("your custom item name here") if item ~= nil then item.Transform:SetPosition(inst.Transform:GetWorldPosition()) end --Set skeleton data to nil so it won't spawn one when we call _OnMakePlayerGhost. data.skeleton = nil end _OnMakePlayerGhost(inst, data) end For your second question, you can manually perform a resurrection by pushing the "respawnfromghost" event for the target player. You can use the "timer" and "knownlocations" components to do this. When your character dies, start a new timer (Timer:StartTimer, two days would be 960 seconds), and also save the location via KnownLocations:RememberLocation. When the timer is up, it will push an event that you can listen for, and when this event triggers you can teleport the character to the saved location and resurrect them. The benefit of using these two components is that it will automatically save and load the location data and remaining time with the player, but note that you will need to manually add these components to the player as they are not included by default. For your third question, there is an in-game setting related to dropping inventory on death, but unfortunately this has no effect on players because they handle dropping their inventories manually in their stategraph. You will need to override the Inventory:DropEverything function to prevent dropping the inventory when dying based on a certain criteria. You might consider adding some kind of "nodropondeath" tag to the custom character's prefab, that way you can reuse this method for other situations if you want to. Something like this would work: AddClassPostConstruct("components/inventory", function(self) local _DropEverything = self.DropEverything function self:DropEverything(ondeath, keepequip) if ondeath and self.inst:HasTag("nodropondeath") then return end _DropEverything(self, ondeath, keepequip) end end) Finally, it's certainly possible to "interact with the custom item to drop their inventory," but you would probably need to define a new component action to do so. I'm not really sure what your goals are with that though, so I can't really offer anymore assistance at this time. Hope this helps. 1 Link to comment Share on other sites More sharing options...
Bloodysanta Posted November 29, 2020 Author Share Posted November 29, 2020 On 11/27/2020 at 10:00 AM, Ziro2k said: For your first question, player skeleton spawning is handled in the player_common_extensions file. You will need to override the OnMakePlayerGhost function in order to prevent a skeleton from spawning when a player becomes a ghost (note, in gamemodes without ghosts enabled OnPlayerDied will need to be overridden instead, but I'll leave that to you if you care for that edge case). Check if the player that died is your custom character, and spawn your custom item instead of a skeleton if it is: local ex_fns = GLOBAL.require "prefabs/player_common_extensions" local _OnMakePlayerGhost = ex_fns.OnMakePlayerGhost ex_fns.OnMakePlayerGhost = function(inst, data) if inst:HasTag("playerghost") then return end --This won't spawn your custom item if not on solid ground. Move the spawning code out from within the check if you want it to do so. if data ~= nil and data.skeleton and GLOBAL.TheSim:HasPlayerSkeletons() and inst.prefab == "your character name here" then local item = GLOBAL.SpawnPrefab("your custom item name here") if item ~= nil then item.Transform:SetPosition(inst.Transform:GetWorldPosition()) end --Set skeleton data to nil so it won't spawn one when we call _OnMakePlayerGhost. data.skeleton = nil end _OnMakePlayerGhost(inst, data) end For your second question, you can manually perform a resurrection by pushing the "respawnfromghost" event for the target player. You can use the "timer" and "knownlocations" components to do this. When your character dies, start a new timer (Timer:StartTimer, two days would be 960 seconds), and also save the location via KnownLocations:RememberLocation. When the timer is up, it will push an event that you can listen for, and when this event triggers you can teleport the character to the saved location and resurrect them. The benefit of using these two components is that it will automatically save and load the location data and remaining time with the player, but note that you will need to manually add these components to the player as they are not included by default. For your third question, there is an in-game setting related to dropping inventory on death, but unfortunately this has no effect on players because they handle dropping their inventories manually in their stategraph. You will need to override the Inventory:DropEverything function to prevent dropping the inventory when dying based on a certain criteria. You might consider adding some kind of "nodropondeath" tag to the custom character's prefab, that way you can reuse this method for other situations if you want to. Something like this would work: AddClassPostConstruct("components/inventory", function(self) local _DropEverything = self.DropEverything function self:DropEverything(ondeath, keepequip) if ondeath and self.inst:HasTag("nodropondeath") then return end _DropEverything(self, ondeath, keepequip) end end) Finally, it's certainly possible to "interact with the custom item to drop their inventory," but you would probably need to define a new component action to do so. I'm not really sure what your goals are with that though, so I can't really offer anymore assistance at this time. Hope this helps. Wow! I've since solved the inventory and skeleton thing but have been having zero luck with the respawn function! This is amazing! Thank you so much, the code looks 1000 times cleaner, I'll see how well it works but even if it doesn't I really appreciate the help, this has been killing me. Link to comment Share on other sites More sharing options...
Bloodysanta Posted November 29, 2020 Author Share Posted November 29, 2020 On 11/27/2020 at 10:00 AM, Ziro2k said: For your second question, you can manually perform a resurrection by pushing the "respawnfromghost" event for the target player. You can use the "timer" and "knownlocations" components to do this. When your character dies, start a new timer (Timer:StartTimer, two days would be 960 seconds), and also save the location via KnownLocations:RememberLocation. When the timer is up, it will push an event that you can listen for, and when this event triggers you can teleport the character to the saved location and resurrect them. The benefit of using these two components is that it will automatically save and load the location data and remaining time with the player, but note that you will need to manually add these components to the player as they are not included by default. I've been searching around but I'm still a little confused, could you possibly give a small example of this type of code? If no that's okay, I'll just keep looking, but if you have the time or courtesy to do so it would help greatly. I understand if you don't wanna take the time out of your day to do this, but either way thanks for giving me some real answers, you've certainly already helped a ton Link to comment Share on other sites More sharing options...
Ziro2k Posted December 1, 2020 Share Posted December 1, 2020 On 11/29/2020 at 3:48 PM, Bloodysanta said: I've been searching around but I'm still a little confused, could you possibly give a small example of this type of code? If no that's okay, I'll just keep looking, but if you have the time or courtesy to do so it would help greatly. I understand if you don't wanna take the time out of your day to do this, but either way thanks for giving me some real answers, you've certainly already helped a ton Have you tried looking through the game's code itself? There are plenty of examples of using event listeners, knownlocations and timers. I'm not sure which part you're confused on though. If you're more specific with exactly what you'd like to see an example of, I may be able to help you. 1 Link to comment Share on other sites More sharing options...
Bloodysanta Posted December 2, 2020 Author Share Posted December 2, 2020 1 hour ago, Ziro2k said: Have you tried looking through the game's code itself? There are plenty of examples of using event listeners, knownlocations and timers. I'm not sure which part you're confused on though. If you're more specific with exactly what you'd like to see an example of, I may be able to help you. Its mostly the location code. I have no idea what it would look like other than 'KnownLocations:RememberLocation'. I guess im mostly having trouble understanding what comes after? Like what the teleport function looks like or the code that specifies that i want to go to the location I just logged. You don't have to write anything although it would be a big help, if you don't want to can you maybe recommend me some items in the code that might help? Thanks a lot for responding btw, I really appreciate it. Link to comment 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