. . . Posted June 5, 2019 Share Posted June 5, 2019 (edited) Hello, I was wondering if there's a code to make players lose no sanity from dead players? I remember using this long time ago in master_postinit, but it didn't seem to work? inst.components.sanity.ghost_drain_mult = 0 Edited June 10, 2019 by Warbucks Link to comment https://forums.kleientertainment.com/forums/topic/107147-solved-how-to-make-player-lose-no-sanity-from-dead-players/ Share on other sites More sharing options...
CarlZalph Posted June 5, 2019 Share Posted June 5, 2019 Hook the function: function Sanity:RecalcGhostDrain() And apply the ghost_drain_mult to zero after it. Alternatively setup a metatable hook to return a static, which I have an example at: Link to comment https://forums.kleientertainment.com/forums/topic/107147-solved-how-to-make-player-lose-no-sanity-from-dead-players/#findComment-1205244 Share on other sites More sharing options...
. . . Posted June 6, 2019 Author Share Posted June 6, 2019 Hey, thanks for the help! Unfortunately, I don't really know what "hook the function" means cause I'm a code noob lol I tried my best to guess and did this, but it didn't work local function Sanity:RecalcGhostDrain(inst) inst.components.sanity.ghost_drain_mult = 0 end Link to comment https://forums.kleientertainment.com/forums/topic/107147-solved-how-to-make-player-lose-no-sanity-from-dead-players/#findComment-1205910 Share on other sites More sharing options...
Hornete Posted June 6, 2019 Share Posted June 6, 2019 50 minutes ago, Warbucks said: Try this function Sanity:RecalcGhostDrain() if GetGhostSanityDrain(TheNet:GetServerGameMode()) then local num_ghosts = TheWorld.shard.components.shard_players:GetNumGhosts() local num_alive = TheWorld.shard.components.shard_players:GetNumAlive() local group_resist = num_alive > num_ghosts and 1 - num_ghosts / num_alive or 0 self.ghost_drain_mult = 0 else self.ghost_drain_mult = 0 end end Put this into the master_postinit of your character. Link to comment https://forums.kleientertainment.com/forums/topic/107147-solved-how-to-make-player-lose-no-sanity-from-dead-players/#findComment-1205947 Share on other sites More sharing options...
. . . Posted June 7, 2019 Author Share Posted June 7, 2019 It gives a crash saying "variable 'Sanity' is not declared" and thanks for your help !! Link to comment https://forums.kleientertainment.com/forums/topic/107147-solved-how-to-make-player-lose-no-sanity-from-dead-players/#findComment-1205980 Share on other sites More sharing options...
Hornete Posted June 7, 2019 Share Posted June 7, 2019 1 hour ago, Warbucks said: It gives a crash saying "variable 'Sanity' is not declared" and thanks for your help !! Right, Get rid of Sanity: That might work. Link to comment https://forums.kleientertainment.com/forums/topic/107147-solved-how-to-make-player-lose-no-sanity-from-dead-players/#findComment-1206036 Share on other sites More sharing options...
. . . Posted June 7, 2019 Author Share Posted June 7, 2019 This code (without sanity) Spoiler function RecalcGhostDrain() if GetGhostSanityDrain(TheNet:GetServerGameMode()) then local num_ghosts = TheWorld.shard.components.shard_players:GetNumGhosts() local num_alive = TheWorld.shard.components.shard_players:GetNumAlive() local group_resist = num_alive > num_ghosts and 1 - num_ghosts / num_alive or 0 self.ghost_drain_mult = 0 else self.ghost_drain_mult = 0 end end Gives this crash "assign to undeclared variable 'RecalcGhostDrain'" I also tried this and it didn't crash, but nothing happened Spoiler local function RecalcGhostDrain(inst) if GetGhostSanityDrain(TheNet:GetServerGameMode()) then local num_ghosts = TheWorld.shard.components.shard_players:GetNumGhosts() local num_alive = TheWorld.shard.components.shard_players:GetNumAlive() local group_resist = num_alive > num_ghosts and 1 - num_ghosts / num_alive or 0 inst.ghost_drain_mult = 0 else inst.ghost_drain_mult = 0 end end and thanks again for help! Link to comment https://forums.kleientertainment.com/forums/topic/107147-solved-how-to-make-player-lose-no-sanity-from-dead-players/#findComment-1206061 Share on other sites More sharing options...
. . . Posted June 8, 2019 Author Share Posted June 8, 2019 bump Link to comment https://forums.kleientertainment.com/forums/topic/107147-solved-how-to-make-player-lose-no-sanity-from-dead-players/#findComment-1207256 Share on other sites More sharing options...
Hornete Posted June 9, 2019 Share Posted June 9, 2019 Try putting the functiong line like this function inst.components.sanity:RecalcGhostDrain() Link to comment https://forums.kleientertainment.com/forums/topic/107147-solved-how-to-make-player-lose-no-sanity-from-dead-players/#findComment-1207271 Share on other sites More sharing options...
. . . Posted June 10, 2019 Author Share Posted June 10, 2019 Thanks so much!! Code seems to works perfectly now !!! Link to comment https://forums.kleientertainment.com/forums/topic/107147-solved-how-to-make-player-lose-no-sanity-from-dead-players/#findComment-1207788 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