Advertisement
LannFyre

RPG_WeaponLottery

Jan 15th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //=============================================================================
  2. // RPG_WeaponLottery.
  3. // This actor expands from class ZoneInfo, allowing this actor to use
  4. //   ZoneInfo's code (unless overridden).
  5. //=============================================================================
  6. class RPG_WeaponLottery expands ZoneInfo;
  7.  
  8. var playerpawn guy; // The playerpawn that walks into the zone.
  9. var int FailCount;
  10. var int CurTimer;
  11.  
  12. //=============================================================================
  13. // > When the Zone ZoneInfo creates is entered by any Actor:
  14. //  - If the Actor is a Player Pawn and the Player Pawn isn't in the Lottery
  15. //    State, the Player Pawn is defined as "Guy".
  16. //  - After labeling the Player Pawn, the Lottery state begins.
  17. // > While the Actor is still in the Zone, Super.ActorEntered(Other) function
  18. //   is called from this class' parent class, ZoneInfo.
  19. event ActorEntered(Actor Other)
  20. // When an Actor enters the zone, this event begins
  21. {
  22.    if ( Other.IsA('PlayerPawn') && !IsInState('Lottery') )
  23.    // Typecasts from Actor into PlayerPawn
  24.    {
  25.       Guy = PlayerPawn(Other);
  26.       // Defines PlayerPawn as Guy
  27.       GotoState('Lottery');
  28.       // Changes the State from '', or default (none), to 'Lottery'
  29.    }
  30.    Super.ActorEntered(Other);
  31.    // Calls the function from this class' parent class, ZoneInfo
  32. }
  33.  
  34. //=============================================================================
  35. // > Code flow is executed after activated by GoToState('Lottery'),
  36. // > If an actor leaves at any point during this state, the
  37. //    state goes to default, or none.
  38. // > If Guy (PlayerPawn) = none, then the state ends.
  39. // > If PlayerPawn stays in the zone, then a value is assigned to var int
  40. //    CurTimer:
  41. //  - The value will later be read by LotteryPanel,
  42. //
  43. // ~~~~~MORE TO BE WRITTEN, need to study LotteryPanel more~~~~~
  44. //
  45. //=============================================================================
  46. state Lottery
  47. // A special code flow exectued during the Actor's native Tick.
  48. {
  49.         event ActorLeaving( Actor Other)
  50.         // When an Actor is leaving the zone, this event begins.
  51.         {
  52.                 Global.ActorLeaving( Other);
  53.                 // Calls global ActorLeaving event from parent class.
  54.                 if ( Other == Guy )
  55.                 // Guy = PlayerPawn due to typecasting.
  56.                         GotoState('');
  57.                         // Default is none.
  58.         }
  59.         event EndState()
  60.         // State-only script function, immediately called after this script's
  61.         //  GoToState() call changes the actor into a differnt (or none)
  62.         //  state, executed before the next line of code; consider the current
  63.         //  state's EndState() as an extension of GoToState().
  64.         // In this case, Guy = none because he's either left the zone or
  65.         //  the lottery has finished.
  66.         {
  67.                 Guy = none;
  68.                 // If guy = none, the state ends.
  69.         }
  70. Begin:
  71.         CurTimer = 3;
  72.         // This value is passed on to RPG_LotteryPanel.  
  73.         //  Ex: ( LotteryZone.CurTimer > 1 )
  74.         //  CurTimer is later changed into a String.
  75.         Guy.PlaySound ( Sound'RPG_Test.RPG_HaloCount');
  76.         // This sound is played from the player themselves.
  77.         Sleep( 1 );
  78.         // Latent function: can only be called within state code, not from
  79.         //  within functions.
  80.         //=====================================================================
  81.         // > Sleep( float Seconds ): Pauses the state execution for a certain
  82.         //    amount of time, and then continues.
  83.         // > FinishAnim(): Waits until the current animation sequence you're
  84.         //    playing completes, and then continues.
  85.         // > FinishInterpolation(): Waits for the current InterpolationPoint
  86.         //    movement to complete, and then continues.
  87.         // > Stop;
  88.         // > WaitForLanding(); (pawn only)
  89.         // > MoveToward, MoveTo, StrafeFacing, etc (pawn only)
  90.         // > Goto: Operator, paired with a label name (ex: Goto Begin;).  100%
  91.         //    safer than GotoState from within State.
  92.         // You can customize flow control using While() loops paired with
  93.         //  Sleep(0.0); calls.
  94.         //=====================================================================
  95.         CurTimer = 2;
  96.         Guy.PlaySound ( Sound'RPG_Test.RPG_HaloCount');
  97.         Sleep( 1 );
  98.         CurTimer = 1;
  99.         Guy.PlaySound ( Sound'RPG_Test.RPG_HaloCount');
  100.         Sleep( 1 );
  101.         CurTimer = 0;
  102.         DoLottery();
  103.         // Executes function DoLottery().
  104.       Sleep( 1.5 );
  105.       // Added to preserve number 0 CurTimer for RPG_LotteryPanel.
  106.       GotoState('');
  107.       // Default is none.
  108. }
  109.  
  110. //=============================================================================
  111. // > Function is called from Lottery after timer has ended.
  112. // > If "Guy" (PlayerPawn) leaves or is deleted while in RPG_WeaponLottery,
  113. //    States returns to default.
  114. // > If the PlayerPawn remains, a roll is executed with there being three
  115. //    possible roll results.
  116. //  - For each failure, a count is added toward FailCount.
  117. //  - If the random roll fails three times, an explosion sprite appears and
  118. //     the player is killed.
  119. //  - If the player succeeds before three rolls or fails all three rolls,
  120. //     FailCount is reset to zero.
  121. //=============================================================================
  122. function DoLottery()
  123. {
  124.         local float Selection;
  125.  
  126.         if ( Guy == none || Guy.bDeleteMe )
  127.         // Player disconnected while in 'Lottery'.
  128.         {
  129.                 GotoState('');
  130.                 return;
  131.         }
  132.  
  133.         selection = FRand();
  134.         // Returns a random number from 0.0 to 1.0
  135.         if (Selection >= 0.8)
  136.         {
  137.                 GiveWeapon(Guy, "UnrealI.FlakCannon", true);
  138.                 // QUESTION: How can this be changed so that rewards can be
  139.                 //  edited within the editor's Actor Advanced Properties
  140.                 //  window?
  141.                 GiveWeapon(Guy, "UnrealShare.Eightball", true);
  142.                 Guy.PlaySound (sound'RPG_Test.RPG_HaloReady');
  143.                 FailCount = 0;
  144.         }
  145.         else if (Selection >= 0.7)
  146.         {
  147.                 GiveWeapon(Guy, "UnrealI.FlakCannon", true);
  148.                 Guy.PlaySound (sound'RPG_Test.RPG_HaloReady');
  149.                 FailCount = 0;
  150.         }
  151.         else
  152.         {
  153.                 Guy.PlaySound (sound'RPG_Test.RPG_NoDamageHit');
  154.                 if ( ++FailCount > 2 )
  155.                 // QUESTION: How exactly is this working?  The FailCount does
  156.                 //  stack to three, but I'm not understanding how this works.
  157.                 // QUESTION: "++" means add 1 to a variable, correct?
  158.                 {
  159.                         //Make player explode or something
  160.                         Spawn(class'SpriteBallExplosion',,,Location);
  161.                         Guy.Died( none, 'Exploded', Location);
  162.                         FailCount = 0;
  163.                 }
  164.         }
  165. }
  166.  
  167. //=============================================================================
  168. // > QUESTION: Can you break this segment down for me and explain what this
  169. //   code does and how it does it?  I didn't write it, someone wrote it for me.
  170. //=============================================================================
  171. function Weapon GiveWeapon(Pawn PlayerPawn, string aClassName, optional bool bBringUp)
  172. {
  173.     local class<Weapon> Weapon${1}< ${3} >
  174.     local Weapon NewWeapon;
  175.  
  176.     WeaponClass = class<Weapon>(DynamicLoadObject(aClassName, class'Class'));
  177.  
  178.     if ( PlayerPawn.FindInventoryType(WeaponClass) != None )
  179.         return None;
  180.     newWeapon = Spawn(WeaponClass);
  181.     if ( newWeapon != None ) {
  182.         newWeapon.RespawnTime = 0.0;
  183.         newWeapon.GiveTo(PlayerPawn);
  184.         newWeapon.bHeldItem = true;
  185.         newWeapon.GiveAmmo(PlayerPawn);
  186.         newWeapon.SetSwitchPriority(PlayerPawn);
  187.         newWeapon.WeaponSet(PlayerPawn);
  188.         newWeapon.AmbientGlow = 0;
  189.         if ( PlayerPawn.IsA('PlayerPawn') )
  190.             newWeapon.SetHand(PlayerPawn(PlayerPawn).Handedness);
  191.         else
  192.             newWeapon.GotoState('Idle');
  193.         if ( bBringUp ) {
  194.             PlayerPawn.Weapon.GotoState('DownWeapon');
  195.             PlayerPawn.PendingWeapon = None;
  196.             PlayerPawn.Weapon = newWeapon;
  197.             PlayerPawn.Weapon.BringUp();
  198.         }
  199.     }
  200.     return newWeapon;
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement