Jump to content

/me BUG


Norby127

Recommended Posts

Hello! Why the /me not working properly? I tried to solve but i can't :/. The problem is when the player type just /me the script doesn't react to that. And if i type after the /me many spaces the msg is sent.

Here's the code: 

function sendMessage( message,messageType)
  if messageType == 1 then -- /me
        cancelEvent()
        sendMe(source,message)
   end
end
addEventHandler ( "onPlayerChat", root,sendMessage)

 

 
 
function sendMe(source,...)
    local check = ...
    local msg = table.concat({...}, " ")

    if not check then
        outputChatBox("#77ba50Usage:#FFFFFF /me [text]",source,255,0,0,true)
    else    
        local name = string.gsub(getPlayerName(source),"_"," ")
        pX,pY,pZ = getElementPosition(source)
        local zone = createColSphere(pX,pY,pZ,range)
        for _, thePlayer in ipairs(getElementsWithinColShape(zone,"player")) do          
            outputChatBox(colorME.."*** "..name.." "..msg,thePlayer,255,0,0,true)        
        end
        destroyElement(zone)
    end
    outputChatBox(string.len(msg),source)
end


 
Edited by Norby127
Link to comment
4 hours ago, Norby127 said:

Hello! Why the /me not working properly? I tried to solve but i can't :/. The problem is when the player type just /me the script doesn't react to that. And if i type after the /me many spaces the msg is sent.

Here's the code: 

function sendMessage( message,messageType)
  if messageType == 1 then -- /me
        cancelEvent()
        sendMe(source,message)
   end
end
addEventHandler ( "onPlayerChat", root,sendMessage)

 

 
 
function sendMe(source,...)
    local check = ...
    local msg = table.concat({...}, " ")

    if not check then
        outputChatBox("#77ba50Usage:#FFFFFF /me [text]",source,255,0,0,true)
    else    
        local name = string.gsub(getPlayerName(source),"_"," ")
        pX,pY,pZ = getElementPosition(source)
        local zone = createColSphere(pX,pY,pZ,range)
        for _, thePlayer in ipairs(getElementsWithinColShape(zone,"player")) do          
            outputChatBox(colorME.."*** "..name.." "..msg,thePlayer,255,0,0,true)        
        end
        destroyElement(zone)
    end
    outputChatBox(string.len(msg),source)
end


 
addCommandHandler ("me", function(pl, _, ...)
	local message = table.concat({...}, " ")
    if message:gsub(" ", "") == "" then
		outputChatBox ("#77ba50Usage:#FFFFFF /me [text]", pl, 255, 0, 0, true)
      	return
    end
    
    local pos1 = Vector3 (getElementPosition(pl))
	for i, v in ipairs (getElementsByType("player")) do
    	local pos2 = Vector3 (getElementPosition(v))
      	if getDistanceBetweenPoints3D (pos1, pos2) <= 20 then -- 20 - this range
      		outputChatBox ("*** "..getPlayerName(pl).." "..message, v, 255, 200, 0, true)  
      	end
    end
end)

Try this code

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