diff --git a/source/Changelog.txt b/source/Changelog.txt index d74acdc74..ad7a3d7a4 100644 --- a/source/Changelog.txt +++ b/source/Changelog.txt @@ -1,3 +1,6 @@ +21/03/2024 - Dragon Slayer/Xuri + Fixed an issue with onHunger and onThirst event crashing if the npc was not loaded yet. + 18/02/2024 - Dragon Slayer/Xuri Updated set and get commands (set.js, get.js) with additional ways to set/get resistance types on objects using the syntax 'set/set [type] #. Available resistance types: resistarmor, resistlight, resistwater, resistcold, resistfire, resistenergy, resistpoison diff --git a/source/cChar.cpp b/source/cChar.cpp index 3cf42c9c2..7aa03f6fa 100644 --- a/source/cChar.cpp +++ b/source/cChar.cpp @@ -474,17 +474,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 ) + cScript *toExecute = JSMapping->GetScript( i ); + if( toExecute != nullptr ) { - return false; + // 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; + } } } } @@ -649,17 +652,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; + } } } }