Don't like ads? PRO users don't see any ads ;-)
Guest

Troll

By: a guest on Jan 3rd, 2012  |  syntax: UnrealScript  |  size: 4.33 KB  |  hits: 96  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Troll extends Pawn;
  2.  
  3. #exec TEXTURE IMPORT NAME=Face0 FILE=Textures\Face0.bmp GROUP=Skins FLAGS=2
  4. #exec TEXTURE IMPORT NAME=Face1 FILE=Textures\Face1.bmp GROUP=Skins FLAGS=2
  5. #exec TEXTURE IMPORT NAME=Face2 FILE=Textures\Face2.bmp GROUP=Skins FLAGS=2
  6.  
  7. var() Texture WanderingFace;
  8. var() Texture AttackFace;
  9. var() Texture PainFace;
  10. var() float MaxWallTime;
  11. var() float WanderRadius;
  12. var() float TrollRadius;
  13. var() float AttackRadius;
  14. var() bool bRedeemerResistant;
  15. var() int Step;
  16.  
  17. var vector SpawnLoc;
  18. var Pawn Enemy;
  19. var Pawn NearestPawn;
  20. var bool bCanHurt;
  21.  
  22. function PreSetMovement()
  23. {
  24.         bCanJump = false;
  25.         bCanWalk = false;
  26.         bCanSwim = false;
  27.         bCanFly = true;
  28.         MinHitWall = -0.6;
  29.         bCanOpenDoors = false;
  30.         bCanDoSpecial = false;
  31. }
  32.  
  33. function SetMovementPhysics()
  34. {
  35.         SetPhysics(PHYS_Flying);
  36. }
  37.  
  38. function Spawned()
  39. {
  40.         SpawnLoc = Location;
  41.         PreSetMovement();
  42.         SetMovementPhysics();
  43.         Log(self$" spawned");
  44. }
  45.  
  46. function ChooseDest()
  47. {
  48.         local float homeDist;
  49.         local vector direction;
  50.         homeDist = VSize(SpawnLoc - Location);
  51.         if ( Enemy == None && ( NearestPawn == None || homeDist > WanderRadius || (homeDist > WanderRadius / 2 && FRand() > 0.8) ) )
  52.         {
  53.                 Destination = SpawnLoc;
  54.                 return;
  55.         }
  56.         direction = normal((NearestPawn.Location + VRand() * 700) - Location);
  57.         Destination = Location + direction * Step;
  58. }
  59. function FindNearestPawn()
  60. {
  61.         local Pawn P, M;
  62.         local float mdist, dist;
  63.         mdist = 99999;
  64.         for (P = Level.PawnList; P != None; P = P.NextPawn)
  65.         {
  66.                 if (P.IsA('PlayerPawn') || P.IsA('ScriptedPawn') || P.IsA('Bot') || P.IsA('Bots')) // remove this line for more madness
  67.                 {
  68.                         dist = VSize(Location - P.Location);
  69.                         if (dist < mdist)
  70.                         {
  71.                                 mdist = dist;
  72.                                 M = P;
  73.                         }
  74.                 }
  75.         }
  76.         NearestPawn = M;
  77. }
  78.  
  79. auto state Wandering
  80. {
  81.         function TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation,
  82.                                                                 Vector momentum, name damageType)
  83.         {
  84.                 if (Damage < 60 || (bRedeemerResistant && damageType == 'RedeemerDeath'))
  85.                         return;
  86.                 Global.TakeDamage(Damage, instigatedBy, hitlocation, momentum, damageType);
  87.                 if (Health <= 0)
  88.                         GoToState('Dying');
  89.                 Texture = PainFace;
  90.                 SetTimer(0.5, false);
  91.         }
  92.         function Timer()
  93.         {
  94.                 Texture = WanderingFace;
  95.         }
  96.         function Tick(float deltaTime)
  97.         {
  98.                 FindNearestPawn();
  99.                 if (NearestPawn != None && VSize(Location - NearestPawn.Location) <= TrollRadius)
  100.                         GoToState('Trolling');
  101.         }
  102. Begin:
  103.         //Log("Wandering");
  104.         Texture = WanderingFace;
  105.         Enemy = None;
  106. Move:
  107.         ChooseDest();
  108.         TurnTo(Destination);
  109.         MoveTo(Destination, airspeed);
  110.         Goto('Move');
  111. }
  112. state Trolling
  113. {
  114.         function TakeDamage( int Damage, Pawn instigatedBy, Vector hitlocation,
  115.                                                                 Vector momentum, name damageType)
  116.         {
  117.                 if (Damage < 60 || (bRedeemerResistant && damageType == 'RedeemerDeath'))
  118.                         return;
  119.                 Global.TakeDamage(Damage, instigatedBy, hitlocation, momentum, damageType);
  120.                 if (Health <= 0)
  121.                         GoToState('Dying');
  122.         }
  123.         function Tick(float deltaTime)
  124.         {
  125.                 local float dist;
  126.                 dist = VSize(Location - Enemy.Location);
  127.                 if (Enemy == None || dist > TrollRadius)
  128.                         GoToState('Wandering');
  129.                 if (dist <= AttackRadius && bCanHurt)
  130.                         Hurt();
  131.         }
  132.         function Hurt()
  133.         {
  134.                 HurtRadius(50 + 20 * frand(), AttackRadius, 'butthurt', 200000, Location);
  135.                 SetTimer(frand(), false);
  136.                 bCanHurt = false;
  137.         }
  138.         function Timer()
  139.         {
  140.                 bCanHurt = true;
  141.         }
  142. Begin:
  143.         bCanHurt = true;
  144.         if (NearestPawn != None)
  145.                 Enemy = NearestPawn;
  146.         else
  147.                 GoToState('Wandering');
  148.         //Log(self$" hates "$Enemy);
  149.         Texture = AttackFace;
  150. Move:
  151.         if (Enemy != None)
  152.         {
  153.                 TurnToward(Enemy);
  154.                 MoveToward(Enemy, airspeed * 1.5);
  155.         }
  156.         else
  157.                 GoToState('Wandering');
  158.         Goto('Move');
  159. }
  160. state Dying
  161. {
  162.  
  163. Begin:
  164.         Acceleration = vect(0,0,0);
  165.         SetPhysics(PHYS_None);
  166.         Texture = AttackFace;
  167.         DrawScale *= 2;
  168.         Sleep(0.2);
  169.         spawn(class'ShockWave');
  170.         Sleep(1);
  171.         spawn(class'WarExplosion');
  172.         Destroy();
  173. }
  174.  
  175. defaultproperties
  176. {
  177.         WanderingFace=Texture'Troll.Skins.Face0'
  178.         AttackFace=Texture'Troll.Skins.Face1'
  179.         PainFace=Texture'Troll.Skins.Face2'
  180.         DrawType=DT_Sprite
  181.     Style=STY_Masked
  182.         DrawScale=0.400000
  183.         CollisionRadius=50.000000
  184.     CollisionHeight=50.000000
  185.         Texture=Texture'Troll.Skins.Face0'
  186.         Health=1000
  187.         Step=300
  188.         AirSpeed=300.000000
  189.     AccelRate=1000.000000
  190.         bCollideWorld=false
  191.         WanderRadius=10000.000000
  192.         TrollRadius=1000.000000
  193.         AttackRadius=200.000000
  194.         bRedeemerResistant=true
  195. }