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 1/3] 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; + } } } } From 2c1226db002db77f5b56c92608227f754e4a9dfa Mon Sep 17 00:00:00 2001 From: Dragon Slayer <85514184+DragonSlayer62@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:19:31 -0500 Subject: [PATCH 2/3] Update Changelog.txt --- source/Changelog.txt | 3 +++ 1 file changed, 3 insertions(+) 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 From 1bbd155c8155d4a99fa2bda03d3ccf8f2353608b Mon Sep 17 00:00:00 2001 From: Dragon Slayer <85514184+DragonSlayer62@users.noreply.github.com> Date: Thu, 21 Mar 2024 09:25:46 -0500 Subject: [PATCH 3/3] Update cChar.cpp --- source/cChar.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/cChar.cpp b/source/cChar.cpp index 3bd47d2d2..7aa03f6fa 100644 --- a/source/cChar.cpp +++ b/source/cChar.cpp @@ -481,7 +481,7 @@ bool CChar::SetHunger( SI08 newValue ) { 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 )