Bean666 Posted June 10, 2016 Share Posted June 10, 2016 (edited) 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 June 10, 2016 by Guest Link to comment
Castillo Posted June 10, 2016 Share Posted June 10, 2016 What is the problem? /Global does nothing? Link to comment
Bean666 Posted June 10, 2016 Author Share Posted June 10, 2016 i changed , now i want it to work in a localchat system. see above this local chat system is made by you fyi. Link to comment
Anubhav Posted June 11, 2016 Share Posted June 11, 2016 you mean? executeCommandHandler split the string, get the first letter in that split, check if it is "/" then after that loop through the table (also if indexValue ~= 1) and use executeCommandHandler Link to comment
Bean666 Posted June 11, 2016 Author Share Posted June 11, 2016 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
Anubhav Posted June 11, 2016 Share Posted June 11, 2016 yes but I do not have knowledge of patterns. it should go good I would use split as it would be easier for me.. Link to comment
Bean666 Posted June 11, 2016 Author Share Posted June 11, 2016 can you show me what you would do as it sounds easier??. Link to comment
Anubhav Posted June 11, 2016 Share Posted June 11, 2016 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now