5150 Posted August 14, 2016 Share Posted August 14, 2016 how can i make this into a local chat? i know i use local chatRadius = 50 but where exactly does it go? function chatbox(text, msgtype) local root = getRootElement() local account = getAccountName(getPlayerAccount(source)) local name = getPlayerName(source) local color = string.format("#%02X%02X%02X", getPlayerNametagColor(source)) if (msgtype == 0) then cancelEvent() if isObjectInACLGroup("user." .. account, aclGetGroup("Owner")) then outputChatBox("#000000✪#FF7500OWNER#000000✪ "..color.."" .. name .. ":#f7fc00 " .. text, root, 255,255,255, true) outputServerLog("CHAT: #990000✪#000000OWNER#990000✪ " .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Founder")) then outputChatBox("#990000✬#000000FOUNDER#990000♫ "..color.."" .. name ..":#f7fc00 " .. text, root, 255,255,255, true) outputServerLog("CHAT: #00a2fc~founder~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("CoOwner")) then outputChatBox("#ff0000✪#00ff70CO-OWNER#ff0000✪ "..color.."" .. name ..":#f7fc00 " .. text, root, 255,255,255, true) outputServerLog("CHAT: #00a2fc~founder~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Administrator")) then outputChatBox("#ff0000ADMINISTRATOR|"..color.."" .. name ..":#FFFFFF " .. text, root, 255,255,255, true) outputServerLog("CHAT: #00a2fc~founder~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("SuperModerator")) then outputChatBox("#000000Trainee #00ff00Admin| "..color.."" .. name ..":#FFFFFF " .. text, root, 255,255,255, true) outputServerLog("CHAT: #00a2fc~SuperModerator~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("LeadMod")) then outputChatBox("#0000FFLead Mod| "..color.."" .. name .. ":#FFFFFF " .. text, root, 255,255,255, true) outputServerLog("CHAT: #00ff00~LeadModerator~ " .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Moderator")) then outputChatBox("#3366ffModerator| "..color.."" .. name .. ":#FFFFFF " .. text, root, 255,255,255, true) outputServerLog("CHAT: #00ff00~Moderator~ " .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Trainee")) then outputChatBox(" #FFFF00Trainee| "..color.."" .. name .. ":#FFFFFF " .. text, root, 255,255,255, true) outputServerLog("CHAT: #FFFF00~Vip~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Recruiter")) then outputChatBox(" #FF0000RECRUITER "..color.."" .. name .. ":#FFFFFF " .. text, root, 255,255,255, true) outputServerLog("CHAT: #FFFF00~recruiter~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Console")) then outputChatBox(" #00a2fc~|CREATOR|~ "..color.."" .. name .. ":#f7fc00 " .. text, root, 255,255,255, true) outputServerLog("CHAT: #00a2fc~|OWNER|~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Everyone")) then outputChatBox(""..color.."".. name .. ":#FFFFFF " .. text, root, 255, 255, 255, true) outputServerLog("CHAT: " .. name .. ": " .. text) end elseif (msgtype == 2) then end end addEventHandler("onPlayerChat", root, chatbox) Link to comment
xyz Posted August 14, 2016 Share Posted August 14, 2016 Loop through all the players and use getDistanceBetweenPoints3D to check if they're near enough. Link to comment
Bonus Posted August 14, 2016 Share Posted August 14, 2016 (edited) xyz solution will work good, if you use it for a low amount of player. If the amount is high the script can lag your server. A safer solution is a colshape. Create a colshape with radius 50, get all players in it with a colshape and getElementsWithinColshape and loop through them without asking the position. Edited August 14, 2016 by Guest Link to comment
Gravestone Posted August 14, 2016 Share Posted August 14, 2016 getElementsWithinColShape Link to comment
5150 Posted August 15, 2016 Author Share Posted August 15, 2016 im not the mot experienced scripter, haha. not sure how i would do that Link to comment
Gravestone Posted August 15, 2016 Share Posted August 15, 2016 Try this local chatRadius = 50 addEventHandler("onPlayerChat", root, function chatbox(text, msgtype) local posX, posY, posZ = getElementPosition( source ) local chatSphere = createColSphere( posX, posY, posZ, chatRadius ) local account = getAccountName(getPlayerAccount(source)) local name = getPlayerName(source) local color = string.format("#%02X%02X%02X", getPlayerNametagColor(source)) local nearbyPlayers = getElementsWithinColShape( chatSphere, "player" ) destroyElement( chatSphere ) if (msgtype == 0) then cancelEvent() end for index, nearbyPlayer in ipairs( nearbyPlayers ) do if isObjectInACLGroup("user." .. account, aclGetGroup("Owner")) then outputChatBox("#000000✪#FF7500OWNER#000000✪ "..color.."" .. name .. ":#f7fc00 " .. text, nearbyPlayer, 255,255,255, true) outputServerLog("CHAT: #990000✪#000000OWNER#990000✪ " .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Founder")) then outputChatBox("#990000✬#000000FOUNDER#990000♫ "..color.."" .. name ..":#f7fc00 " .. text, nearbyPlayer, 255,255,255, true) outputServerLog("CHAT: #00a2fc~founder~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("CoOwner")) then outputChatBox("#ff0000✪#00ff70CO-OWNER#ff0000✪ "..color.."" .. name ..":#f7fc00 " .. text, nearbyPlayer, 255,255,255, true) outputServerLog("CHAT: #00a2fc~founder~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Administrator")) then outputChatBox("#ff0000ADMINISTRATOR|"..color.."" .. name ..":#FFFFFF " .. text, nearbyPlayer, 255,255,255, true) outputServerLog("CHAT: #00a2fc~founder~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("SuperModerator")) then outputChatBox("#000000Trainee #00ff00Admin| "..color.."" .. name ..":#FFFFFF " .. text, nearbyPlayer, 255,255,255, true) outputServerLog("CHAT: #00a2fc~SuperModerator~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("LeadMod")) then outputChatBox("#0000FFLead Mod| "..color.."" .. name .. ":#FFFFFF " .. text, nearbyPlayer, 255,255,255, true) outputServerLog("CHAT: #00ff00~LeadModerator~ " .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Moderator")) then outputChatBox("#3366ffModerator| "..color.."" .. name .. ":#FFFFFF " .. text, nearbyPlayer, 255,255,255, true) outputServerLog("CHAT: #00ff00~Moderator~ " .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Trainee")) then outputChatBox(" #FFFF00Trainee| "..color.."" .. name .. ":#FFFFFF " .. text, nearbyPlayer, 255,255,255, true) outputServerLog("CHAT: #FFFF00~Vip~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Recruiter")) then outputChatBox(" #FF0000RECRUITER "..color.."" .. name .. ":#FFFFFF " .. text, nearbyPlayer, 255,255,255, true) outputServerLog("CHAT: #FFFF00~recruiter~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Console")) then outputChatBox(" #00a2fc~|CREATOR|~ "..color.."" .. name .. ":#f7fc00 " .. text, nearbyPlayer, 255,255,255, true) outputServerLog("CHAT: #00a2fc~|OWNER|~" .. name .. ": " .. text) elseif isObjectInACLGroup("user." .. account, aclGetGroup("Everyone")) then outputChatBox(""..color.."".. name .. ":#FFFFFF " .. text, nearbyPlayer, 255, 255, 255, true) outputServerLog("CHAT: " .. name .. ": " .. text) end end end ) Link to comment
kashtesov Posted August 15, 2016 Share Posted August 15, 2016 local chatRadius = 50 local groups = { {"CoOwner", "#ff0000✪#00ff70CO-OWNER#ff0000✪", "#f7fc00", chatRadius}, -- can change group chat raduis --can add here your groups settings } addEventHandler("onPlayerChat", root, function chatbox(text, msgtype) local tab local account = getPlayerAccount(source) and getAccountName(getPlayerAccount(source)) or "*" local name = getPlayerName(source) local color = string.format("#%02X%02X%02X", getPlayerNametagColor(source)) for k,i in ipairs(groups) do if isObjectInACLGroup("user."..account, aclGetGroup(i[1])) then tab = i break end end local x, y, z = getElementPosition(source); local chatSphere = createColSphere(x, y, z, tab[4] or chatRadius) local nearbyPlayers = getElementsWithinColShape(chatSphere, "player") destroyElement(chatSphere) if (msgtype == 0) then cancelEvent() end for index, nearbyPlayer in ipairs(nearbyPlayers) do outputChatBox((tab[2] or "")..color.."".. name .. ":"..(tab[3] or "").." "..text, nearbyPlayer, 255, 255, 255, true) outputServerLog("CHAT: "..(tab[2] or "").." "..name..": "..text) end end ) Link to comment
Bonsai Posted August 15, 2016 Share Posted August 15, 2016 A colshape every time someone sends a message? I'm not sure if "getElementsWithinColShape" even works if a player doesn't actually enter the colshape, but is already in it when it is created. And all of this is happening serverside. Just send the messages to all players and let the clients do the math if they are near enough. Link to comment
Bonus Posted August 15, 2016 Share Posted August 15, 2016 Don't worry, it's working good. Your way would use bandwith and the client CPU. That's not better, that's worse. 50 players on a spot? Means 50 triggerClientEvent at 1 chat. Link to comment
Bonsai Posted August 15, 2016 Share Posted August 15, 2016 Don't worry, it's working good.Your way would use bandwith and the client CPU. That's not better, that's worse. 50 players on a spot? Means 50 triggerClientEvent at 1 chat. There are 50 clients CPU's, but only 1 server. Link to comment
Gravestone Posted August 15, 2016 Share Posted August 15, 2016 50 is the radius... A colshape every time someone sends a message? @Bonsai, have a look at line 10: destroyElement( chatSphere ) Even if the chatsphere is created a billion times, that doesn't matter. Link to comment
Bonsai Posted August 15, 2016 Share Posted August 15, 2016 50 is the radius...A colshape every time someone sends a message? @Bonsai, have a look at line 10: destroyElement( chatSphere ) Even if the chatsphere is created a billion times, that doesn't matter. If it wasn't destroyed it would be 100 times worse. Just because MTA provides a function that lets you get all elements within a colshape, it doesn't mean its faster. How does it work internally? Maybe after all its just comparing positions aswell, so you could just compare them yourself without having to create and destroy elements, which might also have to be synced with the clients. Link to comment
Gravestone Posted August 15, 2016 Share Posted August 15, 2016 That doesn't really cause a problem. Feel free to try it yourself. Link to comment
5150 Posted August 15, 2016 Author Share Posted August 15, 2016 what would be the most efficient way of doing this, and how would i do it? seems colshape isnt too effective. my servers pretty loaded as of now, dont really need extra lag. ive seen most RP servers jut have a simple T = local, Y = team, and G,B, or U for global. i just wanted the local for T, but i wanted it to have the same characteristics as freeroam chat, in the sense where it contains player colors and staff tags Link to comment
Bonus Posted August 16, 2016 Share Posted August 16, 2016 Have to admit, Bonsai was right. It's faster to use getElementsByType and getDistanceBetweenPoints3D instead of using a colshape. Tested it on my server, the getDistanceBetweenPoints3D way was like 3-4x faster, needed 1ms to use it on 500 peds. But in my eyes it's still much better than to trigger it to every player. So you should better use getElementsByType and getDistanceBetweenPoints3D. local text = "Hi" local x, y, z = getElementPosition ( player ) local players = getElementsByType ( "player" ) for i=1, #players do -- fastest loop local xp, yp, zp = getElementPosition ( players[i] ) if getDistanceBetweenPoints3D ( x, y, z, xp, yp, zp ) <= 50 then outputChatBox ( players[i], text, 200, 200, 200 ) end end Link to comment
5150 Posted August 17, 2016 Author Share Posted August 17, 2016 Have to admit, Bonsai was right.It's faster to use getElementsByType and getDistanceBetweenPoints3D instead of using a colshape. Tested it on my server, the getDistanceBetweenPoints3D way was like 3-4x faster, needed 1ms to use it on 500 peds. But in my eyes it's still much better than to trigger it to every player. So you should better use getElementsByType and getDistanceBetweenPoints3D. local text = "Hi" local x, y, z = getElementPosition ( player ) local players = getElementsByType ( "player" ) for i=1, #players do -- fastest loop local xp, yp, zp = getElementPosition ( players[i] ) if getDistanceBetweenPoints3D ( x, y, z, xp, yp, zp ) <= 50 then outputChatBox ( players[i], text, 200, 200, 200 ) end end not sure i understand, this script you posted what is that? just whatever goes before my tag script? Link to comment
Bonus Posted August 17, 2016 Share Posted August 17, 2016 It's the local chat ... Loops through every player and outputs the chat to him, if he is max. 50 away Link to comment
5150 Posted August 18, 2016 Author Share Posted August 18, 2016 It's the local chat ...Loops through every player and outputs the chat to him, if he is max. 50 away i need it intertwined with my admin tags script, or else it wont work though 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