Jump to content

enable commands in customchat?


Bean666

Recommended Posts

im using a localchat system but commands does not seem to work.. how can i enable it in this custom chat system? i want to enable commands in this localchat system

chat_range=30 
  
addEventHandler("onPlayerJoin",getRootElement(), 
function () 
bindKey(source,"T","down","chatbox","Say") 
end) 
  
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), 
function () 
for index, player in pairs(getElementsByType("player")) do 
bindKey(player,"T","down","chatbox","Say") 
  end 
end) 
  
function isPlayerInRangeOfPoint(player,x,y,z,range) 
   local px,py,pz=getElementPosition(player) 
   return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range 
end 
  
function onChat(player,_,...) 
  local px,py,pz=getElementPosition(player) 
  local msg = table.concat({...}, " ") 
  local nick=getPlayerName(player) 
  for _,v in ipairs(getElementsByType("player")) do 
    if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then 
      outputChatBox("[Local]"..nick..": #ffffff"..msg,v,150,150,150,true) 
    end 
  end 
end 
addCommandHandler("Say",onChat) 

Edited by Guest
Link to comment

like this?:

local msg = table.concat({...}, " ") 
if msg:find("/") == 1 and msg:len() > 1 then 
    -- Command 
    local cmd, params = msg:match("/(%S+)%s*(.*)") 
    return executeCommandHandler(cmd, player, params) 
else 
    -- Message 
    -- ... 
end 
  

Link to comment
  
local checkString = split( message, "" ) 
  
if checkString[ 1 ] == "/" and checkString[ 2 ] then 
    local cmd = "" 
  
    local args = {} 
    local spaceDetected = false 
  
    for i, v in ipairs( checkString ) do 
        if i ~= 1 then 
            if v ~= "" and spaceDetected ~= true then 
                cmd = cmd..v 
            end 
        end 
    end 
    -- to make arugments do one more split with " " 
  
    return executeCommandHandler( cmd, playerWhoWroteCommand, unpack ( args ) ) 
end 
  

you do the args.

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