KAKAN

VCMP: Simple spree system

May 9th, 2016
751
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 2.07 KB | None | 0 0
  1. spree <- array( 100, null );
  2.  
  3. class SpreeSys
  4. {
  5.     player = null;
  6.     spree = 0;
  7.  
  8.     constructor( player )
  9.     {
  10.         if( typeof player != "instance" ) return;
  11.         this.player = player;
  12.         this.spree = 0;
  13.     }
  14.     function Get()
  15.     {
  16.         return [ this.spree, this.player ];
  17.     }
  18.     function Inc( amount = 1 )
  19.     {
  20.         this.spree += amount;
  21.         local s = this.spree;
  22.         if( s >= 5 && s%5 == 0 ) Start();
  23.     }
  24.     function Dec( amount )
  25.     {
  26.         this.spree -= amount;
  27.     }
  28.     function Start()
  29.     {
  30.         local s = this.spree, reward = s*100;
  31.         ::Message( format( "%s is on a killing spree of %i kills in a row. Reward: %i.", this.player.Name, s, reward ) );
  32.         this.player.Cash += reward;
  33.     }
  34.     function End( victim = null )
  35.     {
  36.         local spree = this.spree;
  37.         if( spree >= 5 )
  38.         {
  39.             if( victim != null ) ::Message( format("%s has ended %s killing spree of %i kills in a row.", victim.Name, this.player.Name, spree ) );
  40.             else ::Message( format("%s has ended their own killing spree of %i kills in a row.", this.player.Name, spree ) );
  41.             this.spree = 0;
  42.         }
  43.         else this.spree = 0;
  44.     }
  45.  
  46. }
  47.  
  48. function onPlayerJoin( player )
  49. {
  50.     spree[ player.ID ] = SpreeSys( player );
  51. }
  52.  
  53. function onPlayerKill( killer, player, reason, bodypart )
  54. {
  55.     spree[ killer.ID ].Inc();
  56.     spree[ player.ID ].End( killer );
  57. }
  58.  
  59. function onPlayerTeamKill( killer, player, reason, bodypart )
  60. {
  61.     onPlayerKill( killer, player, reason, bodypart );
  62. }
  63.  
  64. function onPlayerDeath( player )
  65. {
  66.     spree[ player.ID ].End();
  67. }
  68.  
  69. function onPlayerPart( player, reason )
  70. {
  71.     spree[ player.ID ].End();
  72.     spree[ player.ID ] = null;
  73. }
  74.  
  75. function onPlayerCommand( player, cmd, text )
  76. {
  77.     if( cmd == "spree" )
  78.     {
  79.         local spree = ::spree, Buffer = "", hue;
  80.         foreach( value in spree )
  81.         {
  82.             if( value == null ) continue;
  83.              hue = value.Get();
  84.             if( hue[0] >= 5 )
  85.             {
  86.                 if( Buffer == "" ) Buffer = hue[1].Name + "(" + hue[0] + ")";
  87.                 else Buffer += " , " + hue[1].Name + "(" + hue[0] + ")";
  88.             }
  89.         }
  90.         if( Buffer != "" ) MessagePlayer( "Players on spree: " + Buffer, player );
  91.         else MessagePlayer("No players are currently on spree.", player );
  92.     }
  93. }
Add Comment
Please, Sign In to add comment