ULX

Author Topic: command time restrictions  (Read 5892 times)

0 Members and 1 Guest are viewing this topic.

Offline pants

  • Newbie
  • *
  • Posts: 33
  • Karma: 4
command time restrictions
« on: February 22, 2014, 11:56:54 AM »
I'd really like to see an addon where I could set it by rank to where say
moderators - must wait 10 seconds between using commands
admins - must wait 5 seconds between using commands

etc. to help with my command spam problems.

those times aren't my final choice just an example

Offline pants

  • Newbie
  • *
  • Posts: 33
  • Karma: 4
Re: command time restrictions
« Reply #1 on: February 23, 2014, 01:21:16 AM »
And cobalt delivers! http://pastebin.com/9q9ev2rW


Code: [Select]
-- add all usergroups here with cooldown times
local groups = {}
groups.admin = 10
groups.superadmin = 5
groups.owner = 3

-- groups who shouldnt be affected by a cooldown
local blacklist = { "owner", "superadmin" }

timer.Simple( 10, function()
hook.Add( "ULibCommandCalled", "CheckCommands", function( ply, cmd, args )
if table.HasValue( blacklist, ply:GetUserGroup() ) then
return
end
if not ply.cooldown or ply.cooldown <= 0 then
ply.cooldown = groups[ ply:GetUserGroup() ]
else
ply:ChatPrint( "Please wait " .. tostring( ply.cooldown ) .. " more seconds before you use a command again." )
return false
end
end )
end )

timer.Create( "Cooldown", 1, 0, function()
for k, v in next, player.GetAll() do
if v.cooldown then
if v.cooldown > 0 then
v.cooldown = v.cooldown - 1
if v.cooldown == 0 then
v.cooldown = nil
end
elseif v.cooldown <= 0 then
v.cooldown = nil
end
end
end
end )

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: command time restrictions
« Reply #2 on: February 23, 2014, 05:10:17 PM »
Excellent use of ULibCommandCalled. :D
Experiencing God's grace one day at a time.

Offline pants

  • Newbie
  • *
  • Posts: 33
  • Karma: 4
Re: command time restrictions
« Reply #3 on: February 24, 2014, 12:47:40 AM »
I actually wasn't able to get it working, but I have really weird group names like "adept3+"
but cobalt said it worked for him, so it probably works.

An Error Has Occurred!

array_keys(): Argument #1 ($array) must be of type array, null given