Jump to content

Issue with a "say" script


TheCapn

Recommended Posts

Hello guys,

I've taken this following script from the wiki and I've changed it for my purpose.

It seems to work correctly in fact, but :

For exemple, when I say on the chat box : Hello guys how are you ...

I have this -> Franklin_Walker dit : Hello guys, how are you 0

I don't know where this "0" comes from, but maybe you could explain me :D

Here's my code :

  
function sayHandler(...) 
        message = table.concat({...}, " ") 
        local sender = getPlayerName(source) 
        local posX, posY, posZ = getElementPosition(source) 
  
        local saySphere = createColSphere( posX, posY, posZ, sayRadius ) 
        local nearbyPlayers = getElementsWithinColShape( saySphere, "player" ) 
        destroyElement( saySphere ) 
        for index, nearbyPlayer in ipairs( nearbyPlayers ) do 
            outputChatBox(""..sender.." dit : "..message.."", nearbyPlayer, 255, 255, 255, true) 
        end 
end 
addEventHandler( "onPlayerChat", getRootElement(), sayHandler ) 
  
  
function basicChatMessage() 
    cancelEvent() 
end 
addEventHandler( "onPlayerChat", getRootElement(), basicChatMessage ) 
  

Regards,

Link to comment
function sayHandler(...) 
        message = table.concat({...}, " ") 
        local sender = getPlayerName(source) 
        local posX, posY, posZ = getElementPosition(source) 
  
        local saySphere = createColSphere( posX, posY, posZ, sayRadius ) 
        local nearbyPlayers = getElementsWithinColShape( saySphere, "player" ) 
        destroyElement( saySphere ) 
        for index, nearbyPlayer in ipairs( nearbyPlayers ) do 
            outputChatBox(sender.." dit : "..message, nearbyPlayer, 255, 255, 255, true) 
        end 
end 
addEventHandler( "onPlayerChat", getRootElement(), sayHandler ) 

Try this.

Link to comment
sayRadius = 50 
function sayHandler(message, msgType) 
        local sender = getPlayerName(source) 
        local posX, posY, posZ = getElementPosition(source) 
  
        saySphere = createColSphere( posX, posY, posZ, sayRadius ) 
        nearbyPlayers = getElementsWithinColShape( saySphere, "player" ) 
        destroyElement( saySphere ) 
        for index, nearbyPlayer in ipairs( nearbyPlayers ) do 
            outputChatBox(""..sender.." dit : "..message.."", nearbyPlayer, 255, 255, 255, true) 
        end 
end 
addEventHandler( "onPlayerChat", getRootElement(), sayHandler ) 

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