From 5fcb9c7780b55151d6fc4680b7fe62165a0c178f Mon Sep 17 00:00:00 2001 From: Dragon Slayer <85514184+DragonSlayer62@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:03:16 -0500 Subject: [PATCH] Event Fixes onHunger and onthirst Crash fix on startup. --- source/cChar.cpp | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/source/cChar.cpp b/source/cChar.cpp index 650f5f4d6..2429e8da6 100644 --- a/source/cChar.cpp +++ b/source/cChar.cpp @@ -464,17 +464,20 @@ SI08 CChar::GetHunger( void ) const } bool CChar::SetHunger( SI08 newValue ) { - std::vector scriptTriggers = GetScriptTriggers(); - for( auto i : scriptTriggers ) + if( IsValidNPC() ) { - cScript *toExecute = JSMapping->GetScript( i ); - if( toExecute != nullptr ) + std::vector scriptTriggers = GetScriptTriggers(); + for( auto i : scriptTriggers ) { - // If script returns false/0/nothing, prevent hunger from changing, and prevent - // other scripts with event from running - if( toExecute->OnHungerChange(( this ), hunger ) == 0 ) - { - return false; + cScript *toExecute = JSMapping->GetScript( i ); + if( toExecute != nullptr ) + { + // If script returns false/0/nothing, prevent hunger from changing, and prevent + // other scripts with event from running + if( toExecute->OnHungerChange(( this ), hunger ) == 0 ) + { + return false; + } } } } @@ -639,17 +642,20 @@ SI08 CChar::GetThirst( void ) const bool CChar::SetThirst( SI08 newValue ) { - std::vector scriptTriggers = GetScriptTriggers(); - for( auto i : scriptTriggers ) + if( IsValidNPC() ) { - cScript* toExecute = JSMapping->GetScript( i ); - if( toExecute != nullptr ) + std::vector scriptTriggers = GetScriptTriggers(); + for( auto i : scriptTriggers ) { - // If script returns false/0/nothing, prevent thirst from changing, and prevent - // other scripts with event from running - if( toExecute->OnThirstChange(( this ), thirst ) == 0 ) + cScript* toExecute = JSMapping->GetScript( i ); + if( toExecute != nullptr ) { - return false; + // If script returns false/0/nothing, prevent thirst from changing, and prevent + // other scripts with event from running + if( toExecute->OnThirstChange(( this ), thirst ) == 0 ) + { + return false; + } } } }