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

  1. -- guitar state machine
  2.  
  3. beginStateMachine()
  4.  
  5.     onMsg("buildMenu", function(msg)
  6.     
  7.         if (repairMenu()) then return end
  8.     
  9.         -- build the pie menu
  10.         clearPieMenu();
  11.         local button;
  12.         button = addPieMenuButton("pm_playGuitar", "play");
  13.         button.addDescription(ACTIVITY, "playGuitar");
  14.     end )
  15.  
  16.     -- 
  17.     onMsg("play", function(msg)
  18.         -- get the game object server
  19.         local gameObjectServer = getGameObjectServer();
  20.         -- get character who initiated this action
  21.         local character = getStateObjectFromID(msg.sender);
  22.         
  23.         -- check if activity if possible
  24.         local possible, result, activity = activityPossible(character, msg.name, this);
  25.         
  26.         -- don't care if timeslot is not fulfilled
  27.         if (possible or enumCompare(result, TIMESLOT)) then
  28.             -- walk to the closest action point
  29.             local actionPoint = character.getFreeActionPoint(this, "take");
  30.             if (actionPoint) then
  31.                 -- get the walk state object
  32.                 local wso = character.walkSO;
  33.                 local wsoContext = StateMachineContext();
  34.                 wsoContext.storeData("actionPointName", actionPoint.getName());
  35.                 if (wso.walkToActionPoint(actionPoint)) then
  36.                     wso.queueStateMachine("guitarChar.takeGuitar", this, wsoContext);
  37.                 else
  38.                     print("no path found");
  39.                     instantAbort(character, EMOTICON_NOPATH, "emoThink")
  40.                 end
  41.             else
  42.                 print("no action point found");
  43.                 instantAbort(character, EMOTICON_CANNOT, "emoThink")
  44.             end
  45.         else
  46.             -- activity not possible
  47.             print(msg.name .. " not possible");
  48.             
  49.             local emoticon;
  50.             if (enumCompare(result, NO_CONDITION)) then
  51.                 emoticon = conditionToEmoticon(activity.getUnfulfilledCondition());
  52.             else
  53.                 emoticon = EMOTICON_CANNOT;
  54.             end
  55.             instantAbort(character, emoticon, "emoThink");
  56.         end
  57.     end )
  58.             
  59.             
  60. endStateMachine()
  61.