Raffica Posted January 14, 2012 Share Posted January 14, 2012 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) Link to comment
codeluaeveryday Posted January 14, 2012 Share Posted January 14, 2012 Your script has a lot of unnecessary stuff. Use https://community.multitheftauto.com/index.php?p= ... ls&id=2801. Link to comment
Xeno Posted January 14, 2012 Share Posted January 14, 2012 The hex must be in capitals, so: #FFFFFF Use the MTA Wiki for functions: https://wiki.multitheftauto.com/wiki/OutputChatBox And dude before me, he's learning LUA, not downloading resources off the community. Link to comment
Raffica Posted January 14, 2012 Author Share Posted January 14, 2012 The hex must be in capitals, so: #FFFFFF Thanks, But I still get this in the chat when the player that is typing got no team.. Link to comment
Blaawee Posted January 14, 2012 Share Posted January 14, 2012 try this : EDIT chat_range = 100 addEventHandler("onPlayerJoin",getRootElement(), function () bindKey(source,"u","down","chatbox","Local") end) addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function () for index, player in pairs(getElementsByType("player")) do bindKey(player,"u","down","chatbox","Local") 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 = getPlayerNametagColor ( player ) for _,v in ipairs(getElementsByType("player")) do if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then outputChatBox("(Local)"..nick..": #ffffff"..msg,v,r,g,b,true) end end end addCommandHandler("Local",onChat) Link to comment
codeluaeveryday Posted January 14, 2012 Share Posted January 14, 2012 Usually when it outputs like that its because the element is incorrect! 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 I think it should be for _,v in ipairs(getElementsByType("player")) do if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then outputChatBox("(Nearby)"..nick..": #ffffff"..msg,getPlayerName(v),r,g,b,true) end end Link to comment
Raffica Posted January 14, 2012 Author Share Posted January 14, 2012 try this :EDIT chat_range = 100 addEventHandler("onPlayerJoin",getRootElement(), function () bindKey(source,"u","down","chatbox","Local") end) addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function () for index, player in pairs(getElementsByType("player")) do bindKey(player,"u","down","chatbox","Local") 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 = getPlayerNametagColor ( player ) for _,v in ipairs(getElementsByType("player")) do if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then outputChatBox("(Local)"..nick..": #ffffff"..msg,v,r,g,b,true) end end end addCommandHandler("Local",onChat) But now it's the same color all the time.. I want the player name to be same color as their team and if no team players name should be white. Link to comment
Raffica Posted January 14, 2012 Author Share Posted January 14, 2012 Usually when it outputs like that its because the element is incorrect! 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 I think it should be for _,v in ipairs(getElementsByType("player")) do if isPlayerInRangeOfPoint(v,px,py,pz,chat_range) then outputChatBox("(Nearby)"..nick..": #ffffff"..msg,getPlayerName(v),r,g,b,true) end end Sorry didn't solve the problem Link to comment
codeluaeveryday Posted January 14, 2012 Share Posted January 14, 2012 @Raffica, Please do not double post. You must wait until someone else has replied! On topic: Sorry that that didn't help. Link to comment
Blaawee Posted January 14, 2012 Share Posted January 14, 2012 you can set it with random color Link to comment
GanJaRuleZ Posted January 14, 2012 Share Posted January 14, 2012 Btw , why nobody saw that the resource is stolen ? After an hour of "googling" I managed to make this what people call localchat This line means that he made it.. but the script is aleardy posted here : https://community.multitheftauto.com/index.php?p= ... ls&id=2801 That script chat_range=100 addEventHandler("onPlayerJoin",getRootElement(), function () bindKey(source,"u","down","chatbox","LocalChat") end) addEventHandler("onResourceStart",getResourceRootElement(getThisResource()), function () for index, player in pairs(getElementsByType("player")) do bindKey(player,"u","down","chatbox","LocalChat") 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("(LocalChat)"..nick..": #ffffff"..msg,v,r,g,b,true) end end end addCommandHandler("LocalChat",onChat) His 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) Not many differences , huh ? Link to comment
codeluaeveryday Posted January 14, 2012 Share Posted January 14, 2012 (edited) I cannot help with this topic any further sorry Edited January 14, 2012 by Guest Link to comment
Xeno Posted January 14, 2012 Share Posted January 14, 2012 Ganja, this is not place for accusing people of stealing. IF you looked PROPERLY, Will posted that on the tutorial section for ANYONE to use, now if your not going to say anything useful, don't reply.] Idiots. Link to comment
Raffica Posted January 14, 2012 Author Share Posted January 14, 2012 Did I say that I CREATED this? No.. I told you I am just trying to learn lua. I am not a scripter.. Please if you are going to accuse me for "stealing" scripts to learn, then don't post here because I made this topic to get an answer that will help me to the next step in my learning. And if you noticed this now you must be blind because I clearly wrote that I "googled" to find this. And btw I am not making a server so why would I want to steal stuff? Now please go on topic and help me or just leave me alone.. EDIT: Sorry for using the word "make" >.> 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