uBiT Posted January 7, 2012 Share Posted January 7, 2012 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
myonlake Posted January 7, 2012 Share Posted January 7, 2012 (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 January 7, 2012 by Guest Link to comment
uBiT Posted January 7, 2012 Author Share Posted January 7, 2012 Same, i type /me nothing happens. Link to comment
Sharingan Posted January 7, 2012 Share Posted January 7, 2012 Commands are case sensitive. Link to comment
JR10 Posted January 7, 2012 Share Posted January 7, 2012 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
myonlake Posted January 7, 2012 Share Posted January 7, 2012 Could you just copy the code again, please. It works just fine as I tested it. Link to comment
uBiT Posted January 7, 2012 Author Share Posted January 7, 2012 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
myonlake Posted January 7, 2012 Share Posted January 7, 2012 meta.xml and are you sure you've set that to the server-side? No debug errors? Link to comment
JR10 Posted January 7, 2012 Share Posted January 7, 2012 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
uBiT Posted January 7, 2012 Author Share Posted January 7, 2012 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. Link to comment
myonlake Posted January 7, 2012 Share Posted January 7, 2012 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
JR10 Posted January 7, 2012 Share Posted January 7, 2012 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
uBiT Posted January 7, 2012 Author Share Posted January 7, 2012 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. Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 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
uBiT Posted January 7, 2012 Author Share Posted January 7, 2012 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
Castillo Posted January 7, 2012 Share Posted January 7, 2012 Well, it's better without it than nothing, right? Link to comment
uBiT Posted January 7, 2012 Author Share Posted January 7, 2012 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... Link to comment
Castillo Posted January 7, 2012 Share Posted January 7, 2012 myonlake's code doesn't also output the "usage" message either. Link to comment
uBiT Posted January 7, 2012 Author Share Posted January 7, 2012 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. Link to comment
myonlake Posted January 7, 2012 Share Posted January 7, 2012 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. 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