SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- add all usergroups here with cooldown times |
| 1 | + | --[[---------------------------------- |
| 2 | - | local groups = {}
|
| 2 | + | ULX Command Cooldown |
| 3 | - | groups.admin = 10 |
| 3 | + | Originally coded by: Cobalt |
| 4 | - | groups.superadmin = 5 |
| 4 | + | Updated by: lynx |
| 5 | - | groups.owner = 3 |
| 5 | + | Updated: March 3, 2014 |
| 6 | ----------------------------------]]-- | |
| 7 | - | -- groups who shouldnt be affected by a cooldown |
| 7 | + | ulx.groupcooldown = {}
|
| 8 | - | local blacklist = { "owner", "superadmin" }
|
| 8 | + | |
| 9 | --[[ Begin Configuration Section ]]-- | |
| 10 | - | timer.Simple( 10, function() |
| 10 | + | |
| 11 | - | hook.Add( "ULibCommandCalled", "CheckCommands", function( ply, cmd, args ) |
| 11 | + | -- ulx.groupcooldown.default |
| 12 | - | if table.HasValue( blacklist, ply:GetUserGroup() ) then |
| 12 | + | -- This sets the default cooldown for groups not listed in the grouplist. |
| 13 | - | return |
| 13 | + | ulx.groupcooldown.default = 15 |
| 14 | - | end |
| 14 | + | |
| 15 | - | if not ply.cooldown or ply.cooldown <= 0 then |
| 15 | + | -- ulx.groupcooldown.grouplist |
| 16 | - | ply.cooldown = groups[ ply:GetUserGroup() ] |
| 16 | + | -- This list defines the cooldown times for the groups. If a group is unlisted and not on the whitelist, it will default to default above. |
| 17 | - | else |
| 17 | + | -- This is a table. Please follow the example when adding groups. |
| 18 | - | ply:ChatPrint( "Please wait " .. tostring( ply.cooldown ) .. " more seconds before you use a command again." ) |
| 18 | + | ulx.groupcooldown.grouplist = {
|
| 19 | - | return false |
| 19 | + | -- All groups must be formatted as followed: |
| 20 | - | end |
| 20 | + | -- "superadmin" = 5, |
| 21 | - | end ) |
| 21 | + | "superadmin" = 3, |
| 22 | - | end ) |
| 22 | + | "admin" = 5, |
| 23 | "operator" = 10, | |
| 24 | - | timer.Create( "Cooldown", 1, 0, function() |
| 24 | + | } |
| 25 | - | for k, v in next, player.GetAll() do |
| 25 | + | |
| 26 | - | if v.cooldown then |
| 26 | + | -- ulx.groupcooldown.whitelist |
| 27 | - | if v.cooldown > 0 then |
| 27 | + | -- Groups and Steam ID's defined in this list are exempt from the command cooldown regardless if their group is listed above. |
| 28 | - | v.cooldown = v.cooldown - 1 |
| 28 | + | ulx.groupcooldown.whitelist = { "owner", "developer", "superadmin", "STEAM_0:0:0", "STEAM_0:0:29798183" }
|
| 29 | - | if v.cooldown == 0 then |
| 29 | + | |
| 30 | - | v.cooldown = nil |
| 30 | + | -- ulx.groupcooldown.message |
| 31 | - | end |
| 31 | + | -- This is the message dispalyed to the user. A second message will inform them of the time they have remaining to wait. |
| 32 | - | elseif v.cooldown <= 0 then |
| 32 | + | ulx.groupcooldown.message = "You are not allowed to do that right now." |
| 33 | - | v.cooldown = nil |
| 33 | + | |
| 34 | - | end |
| 34 | + | --[[ End Configuration. Please do not modify anything below this line otherwise stuff will break. ]]-- |
| 35 | - | end |
| 35 | + | |
| 36 | function ulx.CmdCooldown(ply, cmd, args) | |
| 37 | if table.HasValue( ulx.groupcooldown.whitelist, ply:SteamID() ) or table.HasValue( ulx.groupcooldown.whitelist, ply:GetUserGroup() ) then | |
| 38 | return | |
| 39 | end | |
| 40 | ||
| 41 | if not ply.NextCommand or ply.NextCommand <= CurTime() then | |
| 42 | ply.NextCommand = CurTime() + ( ulx.groupcooldown.grouplist[ply:GetUserGroup()] or ulx.groupcooldown.default ) | |
| 43 | end | |
| 44 | ||
| 45 | if ply.NextCommand > CurTime() then | |
| 46 | local nextCmd = ply.NextCommand - CurTime() | |
| 47 | ULib.tsay( ply, ulx.groupcooldown.message ) | |
| 48 | ULib.tsay( ply, string.format( "You have %s seconds to wait before you can use a command again.", math.floor(nextCmd) ) ) | |
| 49 | return false | |
| 50 | end | |
| 51 | end | |
| 52 | ||
| 53 | timer.Simple( 3, function() | |
| 54 | hook.Add( "ULibCommandCalled", "CheckCommands", ulx.CmdCooldown ) | |
| 55 | end ) |