Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=============================================================================
- // RPG_WeaponLottery.
- // This actor expands from class ZoneInfo, allowing this actor to use
- // ZoneInfo's code (unless overridden).
- //=============================================================================
- class RPG_WeaponLottery expands ZoneInfo;
- var playerpawn guy; // The playerpawn that walks into the zone.
- var int FailCount;
- var int CurTimer;
- //=============================================================================
- // > When the Zone ZoneInfo creates is entered by any Actor:
- // - If the Actor is a Player Pawn and the Player Pawn isn't in the Lottery
- // State, the Player Pawn is defined as "Guy".
- // - After labeling the Player Pawn, the Lottery state begins.
- // > While the Actor is still in the Zone, Super.ActorEntered(Other) function
- // is called from this class' parent class, ZoneInfo.
- event ActorEntered(Actor Other)
- // When an Actor enters the zone, this event begins
- {
- if ( Other.IsA('PlayerPawn') && !IsInState('Lottery') )
- // Typecasts from Actor into PlayerPawn
- {
- Guy = PlayerPawn(Other);
- // Defines PlayerPawn as Guy
- GotoState('Lottery');
- // Changes the State from '', or default (none), to 'Lottery'
- }
- Super.ActorEntered(Other);
- // Calls the function from this class' parent class, ZoneInfo
- }
- //=============================================================================
- // > Code flow is executed after activated by GoToState('Lottery'),
- // > If an actor leaves at any point during this state, the
- // state goes to default, or none.
- // > If Guy (PlayerPawn) = none, then the state ends.
- // > If PlayerPawn stays in the zone, then a value is assigned to var int
- // CurTimer:
- // - The value will later be read by LotteryPanel,
- //
- // ~~~~~MORE TO BE WRITTEN, need to study LotteryPanel more~~~~~
- //
- //=============================================================================
- state Lottery
- // A special code flow exectued during the Actor's native Tick.
- {
- event ActorLeaving( Actor Other)
- // When an Actor is leaving the zone, this event begins.
- {
- Global.ActorLeaving( Other);
- // Calls global ActorLeaving event from parent class.
- if ( Other == Guy )
- // Guy = PlayerPawn due to typecasting.
- GotoState('');
- // Default is none.
- }
- event EndState()
- // State-only script function, immediately called after this script's
- // GoToState() call changes the actor into a differnt (or none)
- // state, executed before the next line of code; consider the current
- // state's EndState() as an extension of GoToState().
- // In this case, Guy = none because he's either left the zone or
- // the lottery has finished.
- {
- Guy = none;
- // If guy = none, the state ends.
- }
- Begin:
- CurTimer = 3;
- // This value is passed on to RPG_LotteryPanel.
- // Ex: ( LotteryZone.CurTimer > 1 )
- // CurTimer is later changed into a String.
- Guy.PlaySound ( Sound'RPG_Test.RPG_HaloCount');
- // This sound is played from the player themselves.
- Sleep( 1 );
- // Latent function: can only be called within state code, not from
- // within functions.
- //=====================================================================
- // > Sleep( float Seconds ): Pauses the state execution for a certain
- // amount of time, and then continues.
- // > FinishAnim(): Waits until the current animation sequence you're
- // playing completes, and then continues.
- // > FinishInterpolation(): Waits for the current InterpolationPoint
- // movement to complete, and then continues.
- // > Stop;
- // > WaitForLanding(); (pawn only)
- // > MoveToward, MoveTo, StrafeFacing, etc (pawn only)
- // > Goto: Operator, paired with a label name (ex: Goto Begin;). 100%
- // safer than GotoState from within State.
- // You can customize flow control using While() loops paired with
- // Sleep(0.0); calls.
- //=====================================================================
- CurTimer = 2;
- Guy.PlaySound ( Sound'RPG_Test.RPG_HaloCount');
- Sleep( 1 );
- CurTimer = 1;
- Guy.PlaySound ( Sound'RPG_Test.RPG_HaloCount');
- Sleep( 1 );
- CurTimer = 0;
- DoLottery();
- // Executes function DoLottery().
- Sleep( 1.5 );
- // Added to preserve number 0 CurTimer for RPG_LotteryPanel.
- GotoState('');
- // Default is none.
- }
- //=============================================================================
- // > Function is called from Lottery after timer has ended.
- // > If "Guy" (PlayerPawn) leaves or is deleted while in RPG_WeaponLottery,
- // States returns to default.
- // > If the PlayerPawn remains, a roll is executed with there being three
- // possible roll results.
- // - For each failure, a count is added toward FailCount.
- // - If the random roll fails three times, an explosion sprite appears and
- // the player is killed.
- // - If the player succeeds before three rolls or fails all three rolls,
- // FailCount is reset to zero.
- //=============================================================================
- function DoLottery()
- {
- local float Selection;
- if ( Guy == none || Guy.bDeleteMe )
- // Player disconnected while in 'Lottery'.
- {
- GotoState('');
- return;
- }
- selection = FRand();
- // Returns a random number from 0.0 to 1.0
- if (Selection >= 0.8)
- {
- GiveWeapon(Guy, "UnrealI.FlakCannon", true);
- // QUESTION: How can this be changed so that rewards can be
- // edited within the editor's Actor Advanced Properties
- // window?
- GiveWeapon(Guy, "UnrealShare.Eightball", true);
- Guy.PlaySound (sound'RPG_Test.RPG_HaloReady');
- FailCount = 0;
- }
- else if (Selection >= 0.7)
- {
- GiveWeapon(Guy, "UnrealI.FlakCannon", true);
- Guy.PlaySound (sound'RPG_Test.RPG_HaloReady');
- FailCount = 0;
- }
- else
- {
- Guy.PlaySound (sound'RPG_Test.RPG_NoDamageHit');
- if ( ++FailCount > 2 )
- // QUESTION: How exactly is this working? The FailCount does
- // stack to three, but I'm not understanding how this works.
- // QUESTION: "++" means add 1 to a variable, correct?
- {
- //Make player explode or something
- Spawn(class'SpriteBallExplosion',,,Location);
- Guy.Died( none, 'Exploded', Location);
- FailCount = 0;
- }
- }
- }
- //=============================================================================
- // > QUESTION: Can you break this segment down for me and explain what this
- // code does and how it does it? I didn't write it, someone wrote it for me.
- //=============================================================================
- function Weapon GiveWeapon(Pawn PlayerPawn, string aClassName, optional bool bBringUp)
- {
- local class<Weapon> Weapon${1}< ${3} >
- local Weapon NewWeapon;
- WeaponClass = class<Weapon>(DynamicLoadObject(aClassName, class'Class'));
- if ( PlayerPawn.FindInventoryType(WeaponClass) != None )
- return None;
- newWeapon = Spawn(WeaponClass);
- if ( newWeapon != None ) {
- newWeapon.RespawnTime = 0.0;
- newWeapon.GiveTo(PlayerPawn);
- newWeapon.bHeldItem = true;
- newWeapon.GiveAmmo(PlayerPawn);
- newWeapon.SetSwitchPriority(PlayerPawn);
- newWeapon.WeaponSet(PlayerPawn);
- newWeapon.AmbientGlow = 0;
- if ( PlayerPawn.IsA('PlayerPawn') )
- newWeapon.SetHand(PlayerPawn(PlayerPawn).Handedness);
- else
- newWeapon.GotoState('Idle');
- if ( bBringUp ) {
- PlayerPawn.Weapon.GotoState('DownWeapon');
- PlayerPawn.PendingWeapon = None;
- PlayerPawn.Weapon = newWeapon;
- PlayerPawn.Weapon.BringUp();
- }
- }
- return newWeapon;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement