home *** CD-ROM | disk | FTP | other *** search
/ Maximum CD 2002 January / maximum-cd-2002-01.iso / Files / Mechwarrior 4 Mapping / MW4Editor.exe / content / ABLScripts / GenericScripts / Sample_FriendlyFireWarn.abl < prev    next >
Encoding:
Text File  |  2001-07-16  |  7.1 KB  |  245 lines

  1.  
  2. //------------------------------------------------------------------
  3. // NOTE: The fsm name below MUST be changed in order for the
  4. // script to be considered a unique entity!
  5.  
  6. fsm Sample_FriendlyFireWarn : integer;
  7.  
  8.  
  9. //------------------------------------------------------------------
  10.  
  11. // Sample_FriendlyFireWarn:
  12. //   This script encapsulates the code you need to copy into a
  13. //   script to get it to do a friendly fire warning -- and
  14. //   eventually attack -- when the player shoots it.
  15.  
  16. //     INSTRUCTIONS FOR USE:
  17.  
  18. //   1. Copy the static integers in the "var" section of this script
  19. //        into your existing script.
  20.  
  21. //     2. Copy the variable initialization stuff from the Init function
  22. //        of this script into your existing script.  You will need to
  23. //        specify the correct sound IDs, and you may need to set custom
  24. //        timer IDs as well to avoid timer ID conflicts (see below).
  25.  
  26. //   3. Copy the CheckIfPlayerShotMe function to your existing script.
  27.  
  28. //   4. Add a call to CheckIfPlayerShotMe to the beginning of each
  29. //      state in your existing script.
  30.  
  31. //   5. Copy the KillPlayerState into your existing script.
  32.  
  33. //   Be sure to also  ...
  34.  
  35. //        -Add the sound files to Content\Audio, and check them in!
  36. //        -Add the sound file names to the mission's .table & .audio files!
  37.  
  38. //------------------------------------------------------------------
  39.  
  40.  
  41.  
  42. //------------------------------------------------------------------
  43. //     Constants
  44. //------------------------------------------------------------------
  45.  
  46.     const
  47.         #include_ <content\ABLScripts\mwconst.abi>
  48.  
  49. //------------------------------------------------------------------
  50. //     Types
  51. //------------------------------------------------------------------
  52.  
  53.     type
  54.         #include_ <content\ABLScripts\mwtype.abi>
  55.     
  56.  
  57. //------------------------------------------------------------------
  58. //     Variables
  59. //------------------------------------------------------------------
  60.  
  61.     var
  62.         static integer            friendlyFireFrustrationLevel;    // An integer indicating how frustrated I am with the player
  63.         static integer            frustration_timer;                // A timer I use to wait after I'm hit by friendly fire before calling IsShot() again
  64.         static integer            attack_player_timer;            // A timer I use when I'm really pissed off to give the "OK, you die now" sound enough time to play before I attack
  65.  
  66.         static integer            warn_sound_1;                    // Sound ID: "Hey, watch the friendly fire."
  67.         static integer            warn_sound_2;                    // Sound ID: "I warned you, now knock it off."
  68.         static integer            warn_sound_3;                    // Sound ID: "One more friendly fire incident and you're toast."
  69.         static integer            warn_sound_4;                    // Sound ID: "OK, that's it, I'm taking you out, traitor."
  70.  
  71. //------------------------------------------------------------------
  72. //     Init: my initialization function
  73. //------------------------------------------------------------------
  74.  
  75. function Init;
  76.     code
  77.         friendlyFireFrustrationLevel = 0;
  78.  
  79.         // NOTE: replace the following with the warning sound IDs  ...
  80.         // such as "eso_FFWarn1" or "eso_FFWarn2".
  81.  
  82.         warn_sound_1 = -1;
  83.         warn_sound_2 = -1;
  84.         warn_sound_3 = -1;
  85.         warn_sound_4 = -1;
  86.  
  87.         // NOTE: try to give each friendly unit its own timer IDs; if you can't,
  88.         // it's no problem, but then try to make sure each friendly unit script
  89.         // is using a unique pair of timers.
  90.     
  91.         // These timers MUST be different from any timers you are using
  92.         // elsewhere in your scripts for a given mission!!
  93.  
  94.         frustration_timer = gti_Timer_25;
  95.         attack_player_timer = gti_Timer_26;
  96.  
  97.         StartTimer(frustration_timer);
  98.         SetTimer(frustration_timer,100);
  99.  
  100. endfunction;
  101.  
  102. //------------------------------------------------------------------
  103. //    CheckIfPlayerShotMe: this function checks to see if I took
  104. //  friendly fire from the player and responds appropriately.
  105.  
  106. //  You should call this function at the beginning of every state in
  107. //  your script.
  108.  
  109. //------------------------------------------------------------------
  110.  
  111. function CheckIfPlayerShotMe : integer;
  112.     var
  113.         ObjectID who_shot;
  114.  
  115.     code
  116.                                                             // cool down for at least 8 seconds after I'm shot to give IsShot() a chance to reset
  117.         if (Not TimeGreater(frustration_timer,8)) then
  118.             return (0);
  119.         endif;
  120.  
  121.                                                             // Have I been shot?        
  122.         if (Not IsShot(ME)) then
  123.             return (0);
  124.         endif;
  125.  
  126.         who_shot = WhoShot(me);
  127.  
  128.                                                             // OK, I was shot -- was it the player that did it?
  129.         if (who_shot <> getplayervehicle(epl_player0)) then
  130.             return (0);
  131.         endif;
  132.  
  133.         ResetTimer(frustration_timer);
  134.  
  135.                                                             // Level 1: "Knock off the friendly fire."
  136.         if (friendlyFireFrustrationLevel == 0) then
  137.             if (warn_sound_1 <> -1) then
  138.                 PlaySound(warn_sound_1);
  139.             endif;
  140.  
  141.             friendlyFireFrustrationLevel = 1;
  142.             return (1);
  143.         endif;
  144.  
  145.                                                             // Level 2: "Hey!  I warned you, knock it off."
  146.         if (friendlyFireFrustrationLevel == 1) then
  147.             if (warn_sound_2 <> -1) then
  148.                 PlaySound(warn_sound_2);
  149.             endif;
  150.  
  151.             friendlyFireFrustrationLevel = 2;
  152.             return (1);
  153.         endif;
  154.  
  155.                                                             // Level 3: "What we've got here is a failure to communicate."
  156.         if (friendlyFireFrustrationLevel == 2) then
  157.             if (warn_sound_3 <> -1) then
  158.                 PlaySound(warn_sound_3);
  159.             endif;
  160.  
  161.             friendlyFireFrustrationLevel = 3;
  162.             return (1);
  163.         endif;
  164.  
  165.                                                             // Level 4: "OK, you're gonna die now."
  166.         if (warn_sound_4 <> -1) then
  167.             PlaySound(warn_sound_4);
  168.         endif;
  169.  
  170.         StartTimer(attack_player_timer);
  171.         ResetTimer(attack_player_timer);
  172.         trans KillPlayerState;
  173.  
  174.         return (1);
  175.  
  176. endfunction;
  177.  
  178. //------------------------------------------------------------------
  179. //    StartState: my initial state
  180. //------------------------------------------------------------------
  181.  
  182. state StartState;
  183.  
  184.     code
  185.         // IMPORTANT!!! -- You must turn off friendly-fire-ignoring
  186.         // for this to work!
  187.         SetIgnoreFriendlyFire(me,FALSE);
  188.  
  189.         CheckIfPlayerShotMe;
  190.  
  191. endstate;            
  192.  
  193. //------------------------------------------------------------------
  194. //    StartState: my initial state
  195. //------------------------------------------------------------------
  196.  
  197. state SitState;
  198.     code
  199.         CheckIfPlayerShotMe;
  200.         // other state stuff here ...
  201. endstate;
  202.  
  203. state AttackState;
  204.     code
  205.         CheckIfPlayerShotMe;
  206.         // other state stuff here ...
  207. endstate;
  208.  
  209. state EveryOtherStateInTheWholeGoddamnScript;
  210.     code
  211.         CheckIfPlayerShotMe;
  212.         // other state stuff here ...
  213. endstate;
  214.  
  215. //------------------------------------------------------------------
  216. //    KillPlayerState: too much friendly fire -- get pissed, turn into
  217. //  an UberBot, and attack the player
  218. //------------------------------------------------------------------
  219.  
  220. state KillPlayerState;
  221.     code
  222.         if (TimeGreater(attack_player_timer,6)) then
  223.             SetFiringDelay            (ME,0.0,0.0);
  224.             SetSkillLevel            (ME,100,999,100);
  225.  
  226.             SetAutoTargeting(ME,FALSE);
  227.             SetTarget(ME,getplayervehicle(epl_player0));
  228.             OrderAttack(TRUE);
  229.         endif;
  230. endstate;
  231.  
  232. //------------------------------------------------------------------
  233. //    DeadState: OK, I kicked the bucket.
  234. //------------------------------------------------------------------
  235.  
  236. state DeadState;
  237.     code
  238.         orderDie;
  239.  
  240. endstate;
  241.  
  242.  
  243. endfsm.
  244.  
  245.