home *** CD-ROM | disk | FTP | other *** search
/ Singles (French) / Singles-FrenchVersion-Win95.iso / data1.cab / Statemachine / ovenDamaged.lua < prev    next >
Text File  |  2004-03-05  |  3KB  |  89 lines

  1. -- oven state machine
  2.  
  3. beginStateMachine()
  4.  
  5.  
  6.     onEnter(function(msg)
  7.         local damp = findChildGO("damp");
  8.         damp.setEmitRate(0.0);
  9.     end )
  10.  
  11.  
  12.     onMsg("buildMenu", function(msg)    
  13.         -- here we need a repairMenu that always works
  14.         if (repairMenu()) then return end
  15.         
  16.  
  17.         -- rebuild the pie menu
  18.         clearPieMenu()
  19.  
  20.         --if (retrieveData("online")) then
  21.         --    addPieMenuButton("pm_switchOff", "switchoff");
  22.         --else
  23.             addPieMenuButton("pm_switchOn", "switchon");
  24.         --end
  25.     end )
  26.  
  27.     -- 
  28.     onMsg("switchon", function(msg)
  29.         storeData("online", true);
  30.         
  31.         -- get the game object server
  32.         local gameObjectServer = getGameObjectServer();
  33.         -- get character who initiated this action
  34.         local character = getStateObjectFromID(msg.sender);
  35.         -- if this is broken: abort characters action
  36.         if abortIfBroken(character) then return end;        
  37.         -- walk to the closest action point
  38.         local actionPoint = character.getFreeActionPoint(this, "cook");
  39.         if (actionPoint) then    
  40.             -- get the walk state object
  41.             local wso = character.walkSO;
  42.             -- create state machine contexts
  43.             local wsoContext = StateMachineContext();
  44.             -- store the action point
  45.             wsoContext.storeData("actionPointName", actionPoint.getName());
  46.             if (wso.walkToActionPoint(actionPoint)) then
  47.                 -- enque action
  48.                 wso.queueStateMachine("ovenDamagedChar.switchon", this, wsoContext);
  49.             else
  50.                 print("no path found");
  51.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  52.             end
  53.         else
  54.             print("no action point found");
  55.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  56.         end
  57.     end )
  58.     
  59.  
  60.     -- repair
  61.     onMsg("repair", function(msg)
  62.     
  63.         print("onMsg repair");
  64.         -- get character who initiated this action
  65.         local character = getStateObjectFromID(msg.sender);
  66.         -- walk to the closest action point
  67.         local actionPoint = character.getFreeActionPoint(this, "repair");
  68.         -- get the walk state object
  69.         local wso = character.walkSO;
  70.         if (actionPoint) then
  71.             -- create state machine contexts
  72.             local wsoContext = StateMachineContext();
  73.             -- store the action point
  74.             wsoContext.storeData("actionPointName", actionPoint.getName());
  75.             if (wso.walkToActionPoint(actionPoint)) then
  76.                 wso.queueStateMachine("repairChar.repairStart", this, wsoContext);
  77.             else
  78.                 print("no path found");
  79.                 instantAbort(character, EMOTICON_NOPATH, "emoThink")
  80.             end
  81.         else
  82.             print("no action point found");
  83.             instantAbort(character, EMOTICON_CANNOT, "emoThink")
  84.         end
  85.     end )
  86.     
  87.     
  88. endStateMachine()
  89.