• ULX Anti Spammer based on group: Help
    8 replies, posted
[lua] -- add all usergroups here with cooldown times local groups = {} groups.admin = 5 groups.superadmin = 5 groups.owner = 3 groups.vip = 5 groups.vip+ = 5 groups.playervip+ = 5 groups.donator = 5 groups.user = 15 groups.player = 12 groups.regularplayer = 8 groups.ogplayer = 10 groups.MLGPRO = 5 -- groups who shouldnt be affected by a cooldown local blacklist = { nil } timer.Simple( 10, function() hook.Add( "ULibCommandCalled", "CheckCommands", function( ply, cmd, args ) if not ply:IsValid() then return end 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 ) [/lua] So i'm having some issues with the current code. If you can not get the idea from the code i'm trying to detect the users group that they are in and limit how often they can use ulx. Anyone got any ideas? The code does not put out any errors but does not run right. Thanks
Correct me if I'm wrong but WTF is [code] for k, v in next --Wrong for k,v in pairs( player.GetHumans() ) --Correct [/code] It would be easier to just put them into a table, check if they're in that table when they try to use a command, & make a timer that takes them out of the table after x number of seconds.
[QUOTE=MexicanR;50350426]Correct me if I'm wrong but WTF is [code] for k, v in next --Wrong for k,v in pairs( player.GetHumans() ) --Correct [/code] It would be easier to just put them into a table, check if they're in that table when they try to use a command, & make a timer that takes them out of the table after x number of seconds.[/QUOTE] next is a perfectly valid lua keyword and he's using it correctly
[QUOTE=Derek_SM;50350446]next is a perfectly valid lua keyword and he's using it correctly[/QUOTE] Thats what I thought i'm just not sure why the code is not working, the one issue i'm trying to avoid while fixing the code is that this is a recode of the another script, that script had an issue of when you put a console ulx command it would result with an error. if not ply:IsValid() then should fix this but I think that the Hook calling ply would cause errors because console is nil. I'm getting no errors when put in lua/autorun/server but i'm at the point I have tried different methods but no luck and wanted to get someone else's input.
[QUOTE=Derek_SM;50350446]correcting my stupidity[/QUOTE] Thanks for correcting me but imo I think he should make something like this. Sorry for bad code I'm on iPad. [code] ULXS = {} -- add all usergroups here with cooldown times local groups = {} groups.admin = 5 groups.superadmin = 5 groups.owner = 3 groups.vip = 5 groups.vip+ = 5 groups.playervip+ = 5 groups.donator = 5 groups.user = 15 groups.player = 12 groups.regularplayer = 8 groups.ogplayer = 10 groups.MLGPRO = 5 -- groups who shouldnt be affected by a cooldown local blacklist = { nil } Local yep = {} Loca nope = {} local meta = FindMetaTable( "Player" ) function ChatResetTimer( ply ) ply:EnableChatting( true ) end local function meta:CanChat() if !table.HasValue( ULXS.Chat, self:SteamID64 ) then Return false Else Return true end function ULXS.Ccommand If !ply:CanChat(ply, com, args) then Return false Elseif table.HasValue( blacklist, ply:SteamID64 ) Return true Else Return true end ply:EnableChatting( false ) timer.Simple( DElay, function() ULXS.ChatResetTimer( ply ) end) end hook.Add( "ULibCommandCalled", "CheckCommands", CCom) function meta:EnableChatting(bool) if bool then table.remove( yep, self:StamID64() ) else table.insert( yep, self:SteamID64() ) end end [/code]
[QUOTE=Ztiep;50350519]Thats what I thought i'm just not sure why the code is not working, the one issue i'm trying to avoid while fixing the code is that this is a recode of the another script, that script had an issue of when you put a console ulx command it would result with an error. if not ply:IsValid() then should fix this but I think that the Hook calling ply would cause errors because console is nil. I'm getting no errors when put in lua/autorun/server but i'm at the point I have tried different methods but no luck and wanted to get someone else's input.[/QUOTE] The way you wrote the code is a really dumb way of going about doing this though. There's no need to have a timer to decrease everyone's cooldown when we can do it ourselves: [lua] -- add all usergroups here with cooldown times local groups = {} groups.admin = 5 groups.superadmin = 5 groups.owner = 3 groups.vip = 5 groups.vip+ = 5 groups.playervip+ = 5 groups.donator = 5 groups.user = 15 groups.player = 12 groups.regularplayer = 8 groups.ogplayer = 10 groups.MLGPRO = 5 -- groups who shouldnt be affected by a cooldown local blacklist = {} hook.Add( "ULibCommandCalled", "CheckCommands", function( ply, cmd, args ) if not ply:IsValid() then return end if table.HasValue( blacklist, ply:GetUserGroup() ) then return false end if not ply.cooldown or ply.cooldown <= CurTime() then ply.cooldown = CurTime() + groups[ ply:GetUserGroup() ] else ply:ChatPrint( "Please wait " .. tostring( ply.cooldown ) .. " more seconds before you use a command again." ) return false end end ) [/lua] And if you want an even more efficient code, do this [lua] -- add all usergroups here with cooldown times local groups = {} groups.admin = 5 groups.superadmin = 5 groups.owner = 3 groups.vip = 5 groups.vip+ = 5 groups.playervip+ = 5 groups.donator = 5 groups.user = 15 groups.player = 12 groups.regularplayer = 8 groups.ogplayer = 10 groups.MLGPRO = 5 -- groups who shouldnt be affected by a cooldown local blacklist = {} --[[ examples blacklist[ "someblacklistedgroup" ] = true blacklist[ "anotherblacklisted" ] = true ]] hook.Add( "ULibCommandCalled", "CheckCommands", function( ply, cmd, args ) if not ply:IsValid() then return end if blacklist[ ply:GetUserGroup() ] then return false end if not ply.cooldown or ply.cooldown <= CurTime() then ply.cooldown = CurTime() + groups[ ply:GetUserGroup() ] else ply:ChatPrint( "Please wait " .. tostring( ply.cooldown ) .. " more seconds before you use a command again." ) return false end end ) [/lua] The latter doesn't use table.HasValue which loops through the entire table entry. This method has the benefit of direct lookup so it is a lot more efficient.
[QUOTE=Derek_SM;50350627]The way you wrote the code is a really dumb way of going about doing this though. There's no need to have a timer to decrease everyone's cooldown when we can do it ourselves: [lua] -- add all usergroups here with cooldown times local groups = {} groups.admin = 5 groups.superadmin = 5 groups.owner = 3 groups.vip = 5 groups.vip+ = 5 groups.playervip+ = 5 groups.donator = 5 groups.user = 15 groups.player = 12 groups.regularplayer = 8 groups.ogplayer = 10 groups.MLGPRO = 5 -- groups who shouldnt be affected by a cooldown local blacklist = {} hook.Add( "ULibCommandCalled", "CheckCommands", function( ply, cmd, args ) if not ply:IsValid() then return end if table.HasValue( blacklist, ply:GetUserGroup() ) then return false end if not ply.cooldown or ply.cooldown <= CurTime() then ply.cooldown = CurTime() + groups[ ply:GetUserGroup() ] else ply:ChatPrint( "Please wait " .. tostring( ply.cooldown ) .. " more seconds before you use a command again." ) return false end end ) [/lua] And if you want an even more efficient code, do this [lua] -- add all usergroups here with cooldown times local groups = {} groups.admin = 5 groups.superadmin = 5 groups.owner = 3 groups.vip = 5 groups.vip+ = 5 groups.playervip+ = 5 groups.donator = 5 groups.user = 15 groups.player = 12 groups.regularplayer = 8 groups.ogplayer = 10 groups.MLGPRO = 5 -- groups who shouldnt be affected by a cooldown local blacklist = {} --[[ examples blacklist[ "someblacklistedgroup" ] = true blacklist[ "anotherblacklisted" ] = true ]] hook.Add( "ULibCommandCalled", "CheckCommands", function( ply, cmd, args ) if not ply:IsValid() then return end if blacklist[ ply:GetUserGroup() ] then return false end if not ply.cooldown or ply.cooldown <= CurTime() then ply.cooldown = CurTime() + groups[ ply:GetUserGroup() ] else ply:ChatPrint( "Please wait " .. tostring( ply.cooldown ) .. " more seconds before you use a command again." ) return false end end ) [/lua] The latter doesn't use table.HasValue which loops through the entire table entry. This method has the benefit of direct lookup so it is a lot more efficient.[/QUOTE] I gave the Code a shot running it is lua/autorun/server and got no result. No errors in console, nothing.
[QUOTE=Ztiep;50353971]I gave the Code a shot running it is lua/autorun/server and got no result. No errors in console, nothing.[/QUOTE] Oops, try this: [lua] -- add all usergroups here with cooldown times local groups = {} groups.admin = 5 groups.superadmin = 5 groups.owner = 3 groups.vip = 5 groups.vip+ = 5 groups.playervip+ = 5 groups.donator = 5 groups.user = 15 groups.player = 12 groups.regularplayer = 8 groups.ogplayer = 10 groups.MLGPRO = 5 -- groups who shouldnt be affected by a cooldown local blacklist = {} --[[ examples blacklist[ "someblacklistedgroup" ] = true blacklist[ "anotherblacklisted" ] = true ]] hook.Add( "ULibCommandCalled", "CheckCommands", function( ply, cmd, args ) if not IsValid( ply ) then return end if blacklist[ ply:GetUserGroup() ] then return false end if not ply.cooldown or ply.cooldown <= CurTime() then ply.cooldown = CurTime() + groups[ ply:GetUserGroup() ] else ply:ChatPrint( "Please wait " .. tostring( ply.cooldown ) .. " more seconds before you use a command again." ) return false end return true end ) [/lua]
[QUOTE=Derek_SM;50354631]Oops, try this: [lua] -- add all usergroups here with cooldown times local groups = {} groups.admin = 5 groups.superadmin = 5 groups.owner = 3 groups.vip = 5 groups.vip+ = 5 groups.playervip+ = 5 groups.donator = 5 groups.user = 15 groups.player = 12 groups.regularplayer = 8 groups.ogplayer = 10 groups.MLGPRO = 5 -- groups who shouldnt be affected by a cooldown local blacklist = {} --[[ examples blacklist[ "someblacklistedgroup" ] = true blacklist[ "anotherblacklisted" ] = true ]] hook.Add( "ULibCommandCalled", "CheckCommands", function( ply, cmd, args ) if not IsValid( ply ) then return end if blacklist[ ply:GetUserGroup() ] then return false end if not ply.cooldown or ply.cooldown <= CurTime() then ply.cooldown = CurTime() + groups[ ply:GetUserGroup() ] else ply:ChatPrint( "Please wait " .. tostring( ply.cooldown ) .. " more seconds before you use a command again." ) return false end return true end ) [/lua][/QUOTE] Still got nothing, Going to take a look tomorrow and make a quick test server that is not one of my mains for testing.
Sorry, you need to Log In to post a reply to this thread.