Hey there! I just started with lua scripting so I'm a newbie. After an hour of "googling" I managed to make this what people call localchat. But I got one (if not more ;P) problem, when I type in localchat the text is in the same color as the players name and I don't want this. I want the text to be white but keep the players color. I added #ffffff at line 26 but when the player is not in team the chat get like this: Raffica: #ffffff Hello. Which is anoying. Please help me with this!
Script:
chat_range=75
addEventHandler("onPlayerJoin",getRootElement(),
function ()
bindKey(source,"u","down","chatbox","NearbyChat")
end)
addEventHandler("onResourceStart",getResourceRootElement(getThisResource()),
function ()
for index, player in pairs(getElementsByType("player")) do
bindKey(player,"u","down","chatbox","NearbyChat")
end
end)
function isPlayerInRangeOfPoint(player,x,y,z,range)
local px,py,pz=getElementPosition(player)
return ((x-px)^2+(y-py)^2+(z-pz)^2)^0.5<=range
end
function onChat(player,_,...)
local px,py,pz=getElementPosition(player)
local msg = table.concat({...}, " ")
local nick=getPlayerName(player)
local r,g,b = getTeamColor(getPlayerTeam(player))
for _,v in ipairs(getElementsByType("player")) do
if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then
outputChatBox("(Nearby)"..nick..": #ffffff"..msg,v,r,g,b,true)
end
end
end
addCommandHandler("NearbyChat",onChat)