Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.94 KB | None | 0 0
  1. antiAdvertSpam = {}
  2.  
  3. addCommandHandler( "advert",
  4.     function( thePlayer, _, ... )
  5.         --Few if checks before we begin.
  6.         if ( thePlayer.account.guest  ) then return end
  7.         if ( thePlayer.muted ) then return thePlayer:outputChat( "( ADVERT ) You're muted.", 255, 0, 0 ) end
  8.         if ( antiAdvertSpam[thePlayer] ) and ( getTickCount(  ) - antiAdvertSpam[thePlayer] < 60000 ) then
  9.             thePlayer:outputChat( "( ADVERT ) You can't send another message for another "..math.floor( ( antiAdvertSpam[thePlayer] - ( getTickCount(  ) - 60000 )  ) / 1000 ).." seconds.", 255, 0, 0 )
  10.             return
  11.         else
  12.             antiAdvertSpam[thePlayer] = nil
  13.         end
  14.        
  15.         --Advert content checks
  16.         local advert = table.concat( {...},  " " )
  17.         if not ( #advert >= 1 ) then return thePlayer:outputChat( "( ADVERT ) You need to enter in an advert.", 255, 0, 0 ) end
  18.        
  19.         --Color checks
  20.         if ( thePlayer.team ) then
  21.             r, g, b = thePlayer.team:getColor(  )
  22.         else
  23.             r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 )
  24.         end
  25.        
  26.         local hexCode = ( "#%02X%02X%02X" ):format( r, g, b )
  27.         if not hexCode then return end
  28.        
  29.         --Insert online players in a table
  30.         local onlinePlayers = {}
  31.         for i, player in ipairs( Element.getAllByType("player") ) do
  32.             if ( not player.account.guest ) then
  33.                 table.insert( onlinePlayers, player )
  34.             end
  35.         end
  36.         outputChatBox( #onlinePlayers )
  37.         --Calculate cost and do shit
  38.         local cost = 100 * #onlinePlayers
  39.         if ( ( thePlayer.money - cost ) < 0 ) then
  40.             return thePlayer:outputChat( "( ADVERT ) You require $"..math.floor( cost - thePlayer.money ).." to post an advert.", 255, 0, 0 )
  41.         else
  42.             thePlayer.money = thePlayer.money - cost
  43.         end
  44.        
  45.         --Output to online players
  46.         for i, players in ipairs( onlinePlayers ) do
  47.             players:outputChat( hexCode.."( ADVERT ) "..thePlayer.name.." : #FFFFFF"..advert, 255, 255, 255, true )
  48.         end
  49.        
  50.         --Anti spam
  51.         antiAdvertSpam[thePlayer] = getTickCount(  )
  52.        
  53.         return true
  54.     end
  55.  )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement