Advertisement
KingOfVC

Lottery system for VC:MP

Oct 16th, 2015
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.58 KB | None | 0 0
  1. /*
  2.  
  3. Lottery function by KingOfVC
  4.  
  5. */
  6.  
  7. IsLotteryStarted <- false;
  8. LotteryPrize <- 0;
  9. LotteryNumber <- 0;
  10.  
  11.  
  12. function onScriptLoad()
  13. {
  14.  
  15.  Lot <- array( GetMaxPlayers(), null );
  16.  NewTimer("StartLottery",60000,0);
  17.  print( "\nLottery: lottery script by KingOfVC was loaded." );
  18.  
  19. }
  20.  
  21.  
  22. function onPlayerJoin( player )
  23. {
  24.     Lot[ player.ID ] = LotteryArray;
  25. }
  26.  
  27. function onPlayerPart( player, reason )
  28. {  
  29.     Lot[ player.ID ] = LotteryArray;
  30. }  
  31.  
  32.  
  33. function StartLottery()
  34. {
  35.   if ( IsInLottery == false )
  36.   {
  37.     Message("Lottery: The lottery has started, type /lotto <1-60> for your chance to win $" + LotteryPrize );
  38.     IsLotteryStarted = true;
  39.     NewTimer( "EndLottery", 15000, 1 );
  40.   }
  41. }  
  42.  
  43. function EndLottery()
  44. {
  45.   local
  46.   kek           =  rand()%60,
  47.   LotteryNumber =  kek;
  48.  
  49.   Message("Lottery: The lottery is over, the lucky number was " + LotteryNumber );
  50.  
  51.   local plr, b;
  52.   for( local i = 0; i < GetMaxPlayers(); i++ )
  53. {
  54.   local plr = FindPlayer( i );  
  55.   if ( plr && Lot[ plr.ID ].IsInLottery == true )
  56.    {
  57.       if ( Lot[ plr.ID ].Number == LotteryNumber )
  58.     {
  59.       Message( "Lottery: The winner is..." );
  60.       Message( "Lottery: " + plr.Name + ". ( won " + LotteryNumber + " )" );
  61.       IsLotteryStarted = false;
  62.     }
  63.      else
  64.      {
  65.      local
  66.      kes           = LotteryNumber + 100000,
  67.      LotteryNumber = kes;
  68.      Message( "Lottery: No winners this time, the prize is now " + LotteryPrize )
  69.      IsLotteryStarted = false;
  70.      }
  71.    }
  72.     Lot[ player.ID ] = LotteryArray;
  73.  }  
  74. }
  75.  
  76. class LotteryArray
  77. {  
  78.    IsInLottery = false;
  79.    Number      = 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement