- It won't use the global scriptID.
- It's only called when the hunger level decreases, but not when it increases.
Here is a cvs diff of the fixes (or download it):
Code: Select all
Index: UOXJSPropertyFuncs.cpp
===================================================================
RCS file: /cvsroot/openuo/projects/uox3/source/UOXJSPropertyFuncs.cpp,v
retrieving revision 1.25
diff -u -r1.25 UOXJSPropertyFuncs.cpp
--- UOXJSPropertyFuncs.cpp 22 Jan 2006 09:47:44 -0000 1.25
+++ UOXJSPropertyFuncs.cpp 23 Jan 2006 23:36:15 -0000
@@ -667,6 +667,11 @@
CChar *gPriv = (CChar *)JS_GetPrivate( cx, obj );
if( !ValidateObject( gPriv ) )
return JS_FALSE;
+
+ //Prepare the onHungerChange Event
+ const UI16 HungerTrig = gPriv->GetScriptTrigger();
+ cScript *toHungerExecute = JSMapping->GetScript( HungerTrig );
+ cScript *globalExecute = JSMapping->GetScript( (UI16)0 );
JSEncapsulate encaps( cx, vp );
@@ -734,7 +739,18 @@
case CCP_CHARPACK: break;
case CCP_FAME: gPriv->SetFame( (SI16)encaps.toInt() ); break;
case CCP_KARMA: gPriv->SetKarma( (SI16)encaps.toInt() ); break;
- case CCP_HUNGER: gPriv->SetHunger( (SI08)encaps.toInt() ); break;
+ case CCP_HUNGER:
+ gPriv->SetHunger( (SI08)encaps.toInt() );
+ //Call the onHungerChange Event
+ if( toHungerExecute != NULL )
+ {
+ toHungerExecute->OnHungerChange( gPriv, gPriv->GetHunger() );
+ }
+ else
+ {
+ globalExecute->OnHungerChange( gPriv, gPriv->GetHunger() );
+ }
+ break;
case CCP_FROZEN: gPriv->SetFrozen( encaps.toBool() ); break;
case CCP_COMMANDLEVEL: gPriv->SetCommandLevel( (UI08)encaps.toInt() ); break;
case CCP_RACEID:
Index: cPlayerAction.cpp
===================================================================
RCS file: /cvsroot/openuo/projects/uox3/source/cPlayerAction.cpp,v
retrieving revision 1.30
diff -u -r1.30 cPlayerAction.cpp
--- cPlayerAction.cpp 13 Dec 2005 23:45:23 -0000 1.30
+++ cPlayerAction.cpp 23 Jan 2006 23:53:43 -0000
@@ -656,6 +656,17 @@
//Remove a food item
bool iDeleted = i->IncAmount( -1 );
targNPC->SetHunger( static_cast<SI08>(targNPC->GetHunger() + 1) );
+ const UI16 HungerTrig = targNPC->GetScriptTrigger();
+ cScript *toHungerExecute = JSMapping->GetScript( HungerTrig );
+ cScript *globalExecute = JSMapping->GetScript( (UI16)0 );
+ if( toHungerExecute != NULL )
+ {
+ toHungerExecute->OnHungerChange( targNPC, targNPC->GetHunger() );
+ }
+ else
+ {
+ globalExecute->OnHungerChange( targNPC, targNPC->GetHunger() );
+ }
if( iDeleted )
return true; //stackdeleted
}
Index: gumps.cpp
===================================================================
RCS file: /cvsroot/openuo/projects/uox3/source/gumps.cpp,v
retrieving revision 1.22
diff -u -r1.22 gumps.cpp
--- gumps.cpp 11 Dec 2005 09:18:56 -0000 1.22
+++ gumps.cpp 23 Jan 2006 23:50:18 -0000
@@ -1777,6 +1777,12 @@
return;
}
UI16 k;
+
+ //Prepare the onHungerChange Event
+ const UI16 HungerTrig = j->GetScriptTrigger();
+ cScript *toHungerExecute = JSMapping->GetScript( HungerTrig );
+ cScript *globalExecute = JSMapping->GetScript( (UI16)0 );
+
switch( index )
{
case 1: j->SetName( reply ); break; // Name
@@ -1837,7 +1843,17 @@
if( j->IsNpc() )
j->SetNpcWander( reply.toByte() );
break;
- case 24: j->SetHunger( reply.toByte() ); break; // Hunger
+ case 24:
+ j->SetHunger( reply.toByte() );
+ if( toHungerExecute != NULL )
+ {
+ toHungerExecute->OnHungerChange( j, j->GetHunger() );
+ }
+ else
+ {
+ globalExecute->OnHungerChange( j, j->GetHunger() );
+ }
+ break; // Hunger
case 25: j->SetPoisonStrength( reply.toUByte() ); break; // Poison
case 26: j->SetWeight( reply.toShort() ); break; // Weight
case 27: j->SetCarve( reply.toShort() ); break; // Carve
Index: targeting.cpp
===================================================================
RCS file: /cvsroot/openuo/projects/uox3/source/targeting.cpp,v
retrieving revision 1.23
diff -u -r1.23 targeting.cpp
--- targeting.cpp 21 Nov 2005 19:37:25 -0000 1.23
+++ targeting.cpp 23 Jan 2006 23:47:25 -0000
@@ -962,6 +962,17 @@
i->SetAttackFirst( false );
i->SetWar( false );
i->SetHunger( 6 );
+ const UI16 HungerTrig = i->GetScriptTrigger();
+ cScript *toHungerExecute = JSMapping->GetScript( HungerTrig );
+ cScript *globalExecute = JSMapping->GetScript( (UI16)0 );
+ if( toHungerExecute != NULL )
+ {
+ toHungerExecute->OnHungerChange( i, i->GetHunger() );
+ }
+ else
+ {
+ globalExecute->OnHungerChange( i, i->GetHunger() );
+ }
CItem *c = NULL;
for( CItem *j = i->FirstItem(); !i->FinishedItems(); j = i->NextItem() )
{
Index: uox3.cpp
===================================================================
RCS file: /cvsroot/openuo/projects/uox3/source/uox3.cpp,v
retrieving revision 1.37
diff -u -r1.37 uox3.cpp
--- uox3.cpp 16 Dec 2005 19:02:49 -0000 1.37
+++ uox3.cpp 23 Jan 2006 23:36:19 -0000
@@ -1342,7 +1342,7 @@
UI16 hungerRate = cwmWorldState->ServerData()->SystemTimer( tSERVER_HUNGERRATE );
if( mChar.WillHunger() && hungerRate > 0 )
{
- if( mChar.GetCommandLevel() > PLAYER_CMDLEVEL && !mChar.IsDead() && !mChar.IsInvulnerable() )
+ if( mChar.GetCommandLevel() == PLAYER_CMDLEVEL && !mChar.IsDead() && !mChar.IsInvulnerable() )
{
if( mChar.GetTimer( tCHAR_HUNGER ) <= cwmWorldState->GetUICurrentTime() || cwmWorldState->GetOverflow() )
{
@@ -1351,9 +1351,16 @@
mChar.DecHunger();
const UI16 HungerTrig = mChar.GetScriptTrigger();
cScript *toExecute = JSMapping->GetScript( HungerTrig );
+ cScript *globalExecute = JSMapping->GetScript( (UI16)0 );
bool doHunger = true;
if( toExecute != NULL )
+ {
doHunger = !toExecute->OnHungerChange( (&mChar), mChar.GetHunger() );
+ }
+ else
+ {
+ doHunger = !globalExecute->OnHungerChange( (&mChar), mChar.GetHunger() );
+ }
if( doHunger )
{
switch( mChar.GetHunger() )