Skip to content

Commit

Permalink
Merge pull request #261 from DragonSlayer62/onEvent-Fixes
Browse files Browse the repository at this point in the history
Event Fixes
  • Loading branch information
Xoduz authored Mar 21, 2024
2 parents 40d65be + 1bbd155 commit ca50ff0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
3 changes: 3 additions & 0 deletions source/Changelog.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
38 changes: 22 additions & 16 deletions source/cChar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -474,17 +474,20 @@ SI08 CChar::GetHunger( void ) const
}
bool CChar::SetHunger( SI08 newValue )
{
std::vector<UI16> scriptTriggers = GetScriptTriggers();
for( auto i : scriptTriggers )
if( IsValidNPC() )
{
cScript *toExecute = JSMapping->GetScript( i );
if( toExecute != nullptr )
std::vector<UI16> 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;
}
}
}
}
Expand Down Expand Up @@ -649,17 +652,20 @@ SI08 CChar::GetThirst( void ) const

bool CChar::SetThirst( SI08 newValue )
{
std::vector<UI16> scriptTriggers = GetScriptTriggers();
for( auto i : scriptTriggers )
if( IsValidNPC() )
{
cScript* toExecute = JSMapping->GetScript( i );
if( toExecute != nullptr )
std::vector<UI16> 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;
}
}
}
}
Expand Down

0 comments on commit ca50ff0

Please sign in to comment.