Jump to content

/me command


uBiT

Recommended Posts

Hello,

i want to make /me command. But how i can output /me command usage?

Here's my code:

addEventHandler('onPlayerChat', getRootElement(), function(message, messageType) 
    if(messageType == 1) then 
        cancelEvent() 
        meCommand(source, 'me', message) 
    end 
end) 
  
function meCommand(thePlayer, commandName, ...) 
    if(...) then 
        local posX, posY, posZ = getElementPosition(thePlayer) 
        local chatSphere = createColSphere(posX, posY, posZ, 20) 
        local nearbyPlayers = getElementsWithinColShape(chatSphere, 'player') 
        destroyElement(chatSphere) 
        for index, nearbyPlayer in ipairs(nearbyPlayers) do 
            outputChatBox('* '..getPlayerName(thePlayer)..' '..table.concat({...}, ' '), nearbyPlayer, 194, 162, 218) 
        end 
    else 
        outputChatBox(' NAUDOJIMAS: /me [tekstas]', thePlayer, 255, 255, 255) 
    end 
end 
addCommandHandler('Me', meCommand) 

With /Me command everything works, shows usage. But /me doesn't. When i type /me nothing happens.

Link to comment
  • MTA Team

What a mess.

Commands are case sensitive. If you wrote /me, it doesn't output anything because it should be /Me. Now I changed it to /me.

Your colShape was destroyed after it was created, that has no sense.

'...' is not pretty simple thing, read what I did there.

Tested and working 100%.

addEventHandler('onPlayerChat', getRootElement(), 
function(message, messageType) 
    if (messageType == 1) then 
        cancelEvent() 
        meCommand(source, 'me', message) 
    end 
end) 
  
function meCommand(player, cmd, ...) 
    local wrds = {...} 
    local msg = table.concat(wrds, " ") 
    if msg then 
        local posX, posY, posZ = getElementPosition(player) 
        local chatSphere = createColSphere(posX, posY, posZ, 20) 
        local nearbyPlayers = getElementsWithinColShape(chatSphere, 'player') 
        for i,v in ipairs(nearbyPlayers) do 
            outputChatBox('* ' .. getPlayerName(player) .. ' ' .. msg, v, 194, 162, 218) 
        end 
        destroyElement(chatSphere) 
    else 
        outputChatBox('NAUDOJIMAS: /me [tekstas]', player, 255, 255, 255) 
    end 
end 
addCommandHandler('me', meCommand) 

Edited by Guest
Link to comment
addEventHandler('onPlayerChat', getRootElement(), 
function(message, messageType) 
    if (messageType == 1) then 
        cancelEvent() 
    end 
end) 
  
function meCommand(player, cmd, ...) 
    local msg = table.concat({...}, " ") 
    if msg then 
        local posX, posY, posZ = getElementPosition(player) 
        for index , _player in pairs ( getElementsByType ( "player" ) ) do 
            if isPlayerInRangeOfPoint ( _player , posX , posY , posZ , 20 ) then 
                outputChatBox('* ' .. getPlayerName(player) .. ' ' .. msg, _player, 194, 162, 218) 
            end 
        end 
    else 
        outputChatBox('NAUDOJIMAS: /me [tekstas]', player, 255, 255, 255) 
    end 
end 
addCommandHandler('me', meCommand) 
  
function isPlayerInRangeOfPoint ( player , posX , posY , posZ , range ) 
    local _posX , _posY , _posZ = getElementPosition ( player ) 
    return ( ( posX - _posX ) ^ 2 + ( posY - _posY ) ^ 2 + ( posZ - _posZ ) ^ 2 ) ^ 0.5 <= range 
end 

Link to comment

Hmm, i dont understand. For me it doesn't work, tried windows and linux servers.

For my friend either, in his local windows server.

Strange...

JR10,

Tried your code, same.

I'm saying again: /me command is working, but i need print this command usage. Example: if i type /me

it prints something like: USAGE: /me [text]. I just need to show usage...

Link to comment

Try this:

addEventHandler('onPlayerChat', getRootElement(), 
function(message, messageType) 
    if (messageType == 1) then 
        cancelEvent() 
    end 
end) 
  
function meCommand(player, cmd, ...) 
    local msg = table.concat({...}, " ") 
    if msg and #{...} > 0 then 
        local posX, posY, posZ = getElementPosition(player) 
        for index , _player in pairs ( getElementsByType ( "player" ) ) do 
            if isPlayerInRangeOfPoint ( _player , posX , posY , posZ , 20 ) then 
                outputChatBox('* ' .. getPlayerName(player) .. ' ' .. msg, _player, 194, 162, 218) 
            end 
        end 
    else 
        outputChatBox('NAUDOJIMAS: /me [tekstas]', player, 255, 255, 255) 
    end 
end 
addCommandHandler('me', meCommand) 
  
function isPlayerInRangeOfPoint ( player , posX , posY , posZ , range ) 
    local _posX , _posY , _posZ = getElementPosition ( player ) 
    return ( ( posX - _posX ) ^ 2 + ( posY - _posY ) ^ 2 + ( posZ - _posZ ) ^ 2 ) ^ 0.5 <= range 
end 

Link to comment
  • MTA Team
uBiT said:
myonlake,

yes everything is ok, no errors.

JR10,

with your script, /me command doesn't work anymore. Whenever i type something: /me testing

nothing happens, no debugscript errors.

Script started?

Are you sure you tested my script on server side? I tested it on server side and worked just fine, I have modified the script many times so try again.

Link to comment
addEventHandler('onPlayerChat', getRootElement(), 
function(message, messageType) 
    if (messageType == 1) then 
        cancelEvent() 
    end 
end) 
  
function meCommand(player, cmd, ...) 
    local wordsTable = {...} 
    local msg = table.concat(wordsTable, " ") 
    if msg and #wordsTable > 0 then 
        local posX, posY, posZ = getElementPosition(player) 
        for index , _player in pairs ( getElementsByType ( "player" ) ) do 
            if isPlayerInRangeOfPoint ( _player , posX , posY , posZ , 20 ) then 
                outputChatBox('* ' .. getPlayerName(player) .. ' ' .. msg, _player, 194, 162, 218) 
            end 
        end 
    else 
        outputChatBox('NAUDOJIMAS: /me [tekstas]', player, 255, 255, 255) 
    end 
end 
addCommandHandler('me', meCommand) 
  
function isPlayerInRangeOfPoint ( player , posX , posY , posZ , range ) 
    local _posX , _posY , _posZ = getElementPosition ( player ) 
    return ( ( posX - _posX ) ^ 2 + ( posY - _posY ) ^ 2 + ( posZ - _posZ ) ^ 2 ) ^ 0.5 <= range 
end 

Link to comment

I don't know why you need to add a new command, you can replace the "/me" command.

addEventHandler('onPlayerChat', getRootElement(), 
function(message, messageType) 
    if (messageType == 1) then 
        local posX, posY, posZ = getElementPosition(source) 
        for index , _player in pairs ( getElementsByType ( "player" ) ) do 
            if isPlayerInRangeOfPoint ( _player , posX , posY , posZ , 20 ) then 
                outputChatBox('* ' .. getPlayerName(source) .. ' ' .. message, _player, 194, 162, 218) 
            end 
        end 
        cancelEvent() 
    end 
end) 
   
function isPlayerInRangeOfPoint ( player , posX , posY , posZ , range ) 
    local _posX , _posY , _posZ = getElementPosition ( player ) 
    return ( ( posX - _posX ) ^ 2 + ( posY - _posY ) ^ 2 + ( posZ - _posZ ) ^ 2 ) ^ 0.5 <= range 
end 

Link to comment
I don't know why you need to add a new command, you can replace the "/me" command.
addEventHandler('onPlayerChat', getRootElement(), 
function(message, messageType) 
    if (messageType == 1) then 
        local posX, posY, posZ = getElementPosition(source) 
        for index , _player in pairs ( getElementsByType ( "player" ) ) do 
            if isPlayerInRangeOfPoint ( _player , posX , posY , posZ , 20 ) then 
                outputChatBox('* ' .. getPlayerName(source) .. ' ' .. message, _player, 194, 162, 218) 
            end 
        end 
        cancelEvent() 
    end 
end) 
   
function isPlayerInRangeOfPoint ( player , posX , posY , posZ , range ) 
    local _posX , _posY , _posZ = getElementPosition ( player ) 
    return ( ( posX - _posX ) ^ 2 + ( posY - _posY ) ^ 2 + ( posZ - _posZ ) ^ 2 ) ^ 0.5 <= range 
end 

I need to show usage, if user types /me without any text...

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