//:://///////////////////////////////////////////// //:: Custom User Defined Event //:: gz_c2_woodcutter //:: Copyright (c) 2001 Bioware Corp. //::////////////////////////////////////////////// /* */ //::////////////////////////////////////////////// //:: Created By: Dom Queron //::////////////////////////////////////////////// int WOODCUTTER_INIT = 0; int WOODCUTTER_CUTTING = 1; int WOODCUTTER_HOMING = 2; int WOODCUTTER_RESTING = 4; int WOODCUTTER_NIGHT = 8; int WOODCUTTER_OUTOFTREES = 16; int WOODCUTTER_DISABLED = 255; void WCSetState(int iState) { SetLocalInt(OBJECT_SELF,"T1_NPC_STATE",iState); } void WCSetIHaveWood() { SetLocalInt(OBJECT_SELF,"T1_NPC_HASWOOD",TRUE); } int WCGetHasWood() { int iRet; iRet = (GetLocalInt(OBJECT_SELF,"T1_NPC_HASWOOD") == TRUE); return iRet; } /* Here we handle if we run out of basheable trees */ void WCOutOfTrees() { if (GetIsNight()) { WCSetState(WOODCUTTER_HOMING); } else { int iRoll = d20(); if (iRoll<10) if (iRoll == 1 || iRoll == 2) //presumably If is faster than switch, but this may vary { ActionSpeakString("*sigh*, no more suitable trees around"); ActionPlayAnimation(ANIMATION_FIREFORGET_PAUSE_BORED); } else if (iRoll == 3 || iRoll == 4) { ActionSpeakString("No good trees, no work, no food. This aint good"); ActionPlayAnimation(ANIMATION_FIREFORGET_PAUSE_SCRATCH_HEAD); } else if (iRoll == 5 || iRoll == 6) { ActionSpeakString("Tis a shame, no work to do"); ActionPlayAnimation(ANIMATION_FIREFORGET_PAUSE_SCRATCH_HEAD); } else if (iRoll > 6 || iRoll <10) { ActionRandomWalk(); //actionRandomWalk seems to stop never DelayCommand(15.0f,ClearAllActions()); } } } /* Here we cut down trees */ void WCWork() { // get the next tree marked for cutting object oTarget = GetNearestObjectByTag(GetTag(OBJECT_SELF)+"_TREE"); // do we have a tree? if ((oTarget != OBJECT_INVALID) && !GetLocalInt(OBJECT_SELF,"T1_NPC_KILLEDLASTREE")) { if (GetDistanceToObject(oTarget)>5.0f) ActionMoveToObject(oTarget); else { if (d6() <3) { ActionSpeakString ("*sings* I'm a Lumberjack and I'm ok ..."); ActionWait(2.0f); ActionSpeakString ("..I sleep all night and work all day"); } DoPlaceableObjectAction(oTarget,PLACEABLE_ACTION_BASH); WCSetIHaveWood(); } } else if (WCGetHasWood()) WCSetState(WOODCUTTER_HOMING);// Enter out of trees mode else WCSetState(WOODCUTTER_OUTOFTREES);// Enter out of trees mode } void WCHome() { // here we reset the tree kill timer DeleteLocalInt(OBJECT_SELF,"T1_NPC_KILLEDLASTREE"); DeleteLocalInt(OBJECT_SELF,"T1_NPC_HASWOOD"); location lTarget= GetLocalLocation(OBJECT_SELF,"T1_NPC_SPAWNLOC"); if (GetDistanceBetweenLocations(GetLocation(OBJECT_SELF),lTarget)>0.5f) { ActionSpeakString("Ahh, time for a rest!"); ActionMoveToLocation(lTarget); } else { // do we have a chair nearby? object oChair = GetNearestObjectByTag(GetTag(OBJECT_SELF)+"_CHAIR"); // any chair here? if (oChair != OBJECT_INVALID) { if (d4()<2) ActionSpeakString("Where is my chair? ... ah there!"); ActionSpeakString("Ahh, nothing better than a fresh bread and some cold ale!"); ActionPlayAnimation(ANIMATION_FIREFORGET_DRINK); ActionSit(oChair); ActionPlayAnimation(ANIMATION_FIREFORGET_DRINK); WCSetState(WOODCUTTER_RESTING);// Enter out of trees mode } else { ActionSpeakString("Ahh, nothing better than a fresh bread and some cold ale!"); ActionPlayAnimation(ANIMATION_FIREFORGET_DRINK); WCSetState(WOODCUTTER_RESTING);// Enter out of trees mode } } } void WCRest() { effect eSleep = EffectSleep(); ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSleep, OBJECT_SELF,60.0f); ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_SLEEP), OBJECT_SELF); WCSetState(WOODCUTTER_NIGHT); } void WCWake() { effect eSleep = EffectSleep(); RemoveEffect(OBJECT_SELF,eSleep); WCSetState(WOODCUTTER_CUTTING); } void WCSleep() { if (GetIsDay()) WCWake(); else { effect eSleep = EffectSleep(); ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eSleep, OBJECT_SELF,60.0f); } } void main() { int nUser = GetUserDefinedEventNumber(); if(nUser == 1001) //HEARTBEAT { int iState = GetLocalInt(OBJECT_SELF,"T1_NPC_STATE"); if (iState != WOODCUTTER_DISABLED) switch (iState) { case 0 : // Store our Start Location SetLocalLocation(OBJECT_SELF,"T1_NPC_SPAWNLOC",GetLocation(OBJECT_SELF)); WCSetState(WOODCUTTER_CUTTING); break; //first heartbeat case 1 : WCWork();break; case 2 : WCHome();break; case 4 : WCRest();break; case 8 : WCSleep();break; case 16 : WCOutOfTrees();break; } } else if(nUser == 1002) // PERCEIVE { } else if(nUser == 1003) // END OF COMBAT { } else if(nUser == 1004) // ON DIALOGUE { } else if(nUser == 1005) // ATTACKED { } else if(nUser == 1006) // DAMAGED { } else if(nUser == 1007) // DEATH { } else if(nUser == 1008) // DISTURBED { } }