Jump to content

/me command


uBiT

Recommended Posts

Posted

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.

Posted (edited)

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

If I helped you, please click the like button on the right ;) Thanks!

Posted
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 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

Could you just copy the code again, please.

It works just fine as I tested it.

If I helped you, please click the like button on the right ;) Thanks!

Posted

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

Posted

meta.xml and are you sure you've set that to the server-side?

No debug errors?

If I helped you, please click the like button on the right ;) Thanks!

Posted

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 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

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.

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

If I helped you, please click the like button on the right ;) Thanks!

Posted
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 

Business System viewtopic.php?f=108&t=35797

Notepad++ Syntax Highlighting & Auto Completion viewtopic.php?f=91&t=76726

SQLite Tutorial viewtopic.php?f=148&t=38203

Posted

Yes started, tried right now - same, no usage...

As i said, if i add /ME command, it works... Shows usage. But in built-in /me command doesn't work.

JR10,

With this script, /me command doen't work.

Posted

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 

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

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

Posted

Well, it's better without it than nothing, right?

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted
Solidsnake14 said:
Well, it's better without it than nothing, right?

Yeah, but i dont understand. For me, and my friend doesn't work. For myonlake his code works...

Posted

myonlake's code doesn't also output the "usage" message either.

San Andreas Utopia RPG (SAUR) Owner & Developer.

560x95_FFFFFF_FF9900_000000_000000.png

Education is the most powerful weapon which you can use to change the world.

Posted

I'm using latest mtasa, 1.2. Maybe it's an v1.2 issue? Maybe myonlake tried his code on 1.1 version, not 1.2.

Posted

I am using 1.2 aswell because you should always update when there's a chance.

1.1.1 or 1.2, doesn't make a lot of a difference.

If I helped you, please click the like button on the right ;) Thanks!

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