Jump to content

OnCommand?


.:HyPeX:.

Recommended Posts

Guys is there a function to detect or trigger when player does a command? i'm searching to avoid comand flooding.

and also, can i detect if a player uses the say with "/command" ? (like if i can make mta or a script recognize read if on player chat it outputs the "/command" or it wont read nothing.

Link to comment

'onPlayerCommand'.

local commandSpam = {} 
  
function preventCommandSpam() 
    if (not commandSpam[source]) then 
        commandSpam[source] = 1 
        -- New person so add to table 
    elseif (commandSpam[source] == 5) then 
        cancelEvent() 
        outputChatBox("Please refrain from command spamming!", source, 255, 0, 0) 
        -- This person is command spamming! 
    else 
        commandSpam[source] = commandSpam[source] + 1 
        -- Add one to the table 
    end 
end 
addEventHandler("onPlayerCommand", root, preventCommandSpam) 
setTimer(function() commandSpam = {} end, 1000, 0) -- Clear the table every second 

Link to comment
  • 2 weeks later...

Can i get Wich the command was? would this work?

  
function StopCommands(commandname) 
local CommandNotSay = string.match(commandname, say)  
Player = getPlayerFromName( source ) 
if isPlayerMuted( source ) and if CommandNotSay = nil then 
outputchatbox ( "[AntiSpam]:"..Player.."was kicked for trying to use commands while muted!", 0, 175 ,255 ) 
kickPlayer( source, AntiSpam, Dont try to use commands while muted! )  
addEventHandler("onPlayerCommand", getRootElement(), StopCommands) 

Link to comment

i've further worked it out a bit, but i might stop here, i'm trying to get the command itself and check if its one i want to be blocked in a muted guy.

local Checktable =  
CommandTable = {} 
function StopCommands(commandname) 
local thecommand = string.match(commandname) 
local Player = getPlayerFromName( source ) 
table.insert( CommandTable[ thecommand ] ) 
if isPlayerMuted( source ) and if Checktable = true then 
outputchatbox ( "[AntiSpam]:"..Player.."was kicked for trying to change his nick while muted!", 0, 175 ,255 ) 
kickPlayer( source, AntiSpam, Dont try to use commands while muted! ) 
end 
end  
addEventHandler("onPlayerCommand", getRootElement(), StopCommands) 
  
  
function(g_CheckTable) 
if string.match( CommandTable, me) or string.match( CommandTable, pm ) then 
Checktable = true 
end 
end 
addEventHandler("onPlayerCommand", getRootElement(), g_CheckTable) 

Link to comment
local disabledCmds = 
    { 
        [ "me" ] = true, 
        [ "pm" ] = true 
    } 
  
addEventHandler ( "onPlayerCommand", root, 
    function ( cmd ) 
        if disabledCmds [ cmd ] then 
            if isPlayerMuted ( source ) then 
                outputChatBox ( "[AntiSpam]: ".. getPlayerName ( source ) .." was kicked for trying to change his nick while muted!", root, 0, 175 ,255 ) 
                kickPlayer ( source, "AntiSpam: Dont try to use commands while muted!" ) 
            end 
        end 
    end 
) 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...