Jump to content

Convert commands to !


Recommended Posts

you can use onPlayerChat event to check for commands and execute those you already have added.

somthing like this:

function retroCommands(text)  
  if text:find("!", 1, 1) then -- check if text starts with ! 
    local command = gettok(text, 1, 32):sub(2) -- get command name without ! 
    if #command > 0 then  
      local arguments = text:sub(#command+3) -- separate command from arguments (if any) 
      -- you can do it other way:  = text:gsub("!"..command, "") 
      executeCommandHandler(command, source, arguments) -- your resource needs access to executeCommandHandler 
    end 
  end   
end 
addEventHandler("onPlayerChat", getRootElement(), retroCommands) 

and you may want to cancelEvent() to hide the command input.

just note that if you don't cancel, chat output will show after the command is executed.

Link to comment
you can use onPlayerChat event to check for commands and execute those you already have added.

somthing like this:

function retroCommands(text)  
  if text:find("!", 1, 1) then -- check if text starts with ! 
    local command = gettok(text, 1, 32):sub(2) -- get command name without ! 
    if #command > 0 then  
      local arguments = text:sub(#command+3) -- separate command from arguments (if any) 
      -- you can do it other way:  = text:gsub("!"..command, "") 
      executeCommandHandler(command, source, arguments) -- your resource needs access to executeCommandHandler 
    end 
  end   
end 
addEventHandler("onPlayerChat", getRootElement(), retroCommands) 

and you may want to cancelEvent() to hide the command input.

just note that if you don't cancel, chat output will show after the command is executed.

Thanks!!

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...