Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- antiAdvertSpam = {}
- addCommandHandler( "advert",
- function( thePlayer, _, ... )
- --Few if checks before we begin.
- if ( thePlayer.account.guest ) then return end
- if ( thePlayer.muted ) then return thePlayer:outputChat( "( ADVERT ) You're muted.", 255, 0, 0 ) end
- if ( antiAdvertSpam[thePlayer] ) and ( getTickCount( ) - antiAdvertSpam[thePlayer] < 60000 ) then
- thePlayer:outputChat( "( ADVERT ) You can't send another message for another "..math.floor( ( antiAdvertSpam[thePlayer] - ( getTickCount( ) - 60000 ) ) / 1000 ).." seconds.", 255, 0, 0 )
- return
- else
- antiAdvertSpam[thePlayer] = nil
- end
- --Advert content checks
- local advert = table.concat( {...}, " " )
- if not ( #advert >= 1 ) then return thePlayer:outputChat( "( ADVERT ) You need to enter in an advert.", 255, 0, 0 ) end
- --Color checks
- if ( thePlayer.team ) then
- r, g, b = thePlayer.team:getColor( )
- else
- r, g, b = math.random( 255 ), math.random( 255 ), math.random( 255 )
- end
- local hexCode = ( "#%02X%02X%02X" ):format( r, g, b )
- if not hexCode then return end
- --Insert online players in a table
- local onlinePlayers = {}
- for i, player in ipairs( Element.getAllByType("player") ) do
- if ( not player.account.guest ) then
- table.insert( onlinePlayers, player )
- end
- end
- outputChatBox( #onlinePlayers )
- --Calculate cost and do shit
- local cost = 100 * #onlinePlayers
- if ( ( thePlayer.money - cost ) < 0 ) then
- return thePlayer:outputChat( "( ADVERT ) You require $"..math.floor( cost - thePlayer.money ).." to post an advert.", 255, 0, 0 )
- else
- thePlayer.money = thePlayer.money - cost
- end
- --Output to online players
- for i, players in ipairs( onlinePlayers ) do
- players:outputChat( hexCode.."( ADVERT ) "..thePlayer.name.." : #FFFFFF"..advert, 255, 255, 255, true )
- end
- --Anti spam
- antiAdvertSpam[thePlayer] = getTickCount( )
- return true
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement