MrLoKi Posted September 12, 2021 Share Posted September 12, 2021 Hi..... I wanted a code that would send all player chats (Warren chat boxes, etc.) to server administrators. Link to comment
Artur_Sagitov Posted September 19, 2021 Share Posted September 19, 2021 не по форме, тебе не ответят Link to comment
MTA Team 0xCiBeR Posted September 20, 2021 MTA Team Share Posted September 20, 2021 @Artur_Sagitovplease only use english in this section. @MrLoKiyou should post your code here and then ask for help. https://wiki.multitheftauto.com/wiki/GetOnlineAdmins this can be of use. Link to comment
WiBox Posted September 20, 2021 Share Posted September 20, 2021 (edited) First, get all online administrators using getOnlineAdmins then use event handler onPlayerChat function getOnlineAdmins() local temp = {} --Temp table to insert all online admins in for index, players in ipairs (getElementsByType("player")) do --Loop over all players to check who's admin local account = getPlayerAccount(players) --Get player account if (account and not isGuestAccount(account)) then --Checking for any errors and whether the account is an guest account local accountName = getAccountName(account) --Get account name using the account local isAdmin = isObjectInACLGroup("user."..accountName, aclGetGroup("Admin")) --checking if user.accountName is added in Admin ACL group. if isAdmin then -- If he is.. table.insert(temp, players) --add him in table end end end return temp -- return it to get the table end function sendChatsToAdmins(message, messageType) local onlineAdmins = getOnlineAdmins() local playerName = getPlayerName(source) --source is the one who sent a message. for index, admins in ipairs (onlineAdmins) do outputChatBox(playerName..": "..message, 255, 255, 255) --PlayerName: message end end addEventHandler("onPlayerChat", root, sendChatsToAdmins) Haven't tested it but it should work Edited September 20, 2021 by WiBox Link to comment
MrLoKi Posted September 20, 2021 Author Share Posted September 20, 2021 Thank you very much, but I want the code to send all the chats that are sent to that player to my administrators as well. All Chats !! This means that chats sent from the server are also sent to that administrator Link to comment
Spakye Posted September 20, 2021 Share Posted September 20, 2021 (edited) Hello, do you mean messages from scripts with outputChatBox ? If yes i dont think there is an event for it and you probably have to trigger a custom event each time you use outputChatBox. I might be wrong though edit: nvm its is possible with : https://wiki.multitheftauto.com/wiki/OnChatMessage Edited September 20, 2021 by Spakye Link to comment
MrLoKi Posted September 20, 2021 Author Share Posted September 20, 2021 No , I want all the chats that On behalf of the server and other players For that player will be sent to watch the managers I want all the chats that Link to comment
WiBox Posted September 20, 2021 Share Posted September 20, 2021 Whoever uses /say /teamsay or /me will trigger onChatMessage, you can't know if a player is writing the message to another player. If you made another chat system, add a trigger using triggerEvent Link to comment
MrLoKi Posted September 20, 2021 Author Share Posted September 20, 2021 it's true So if I want to see other chats Define for each of them onChatMessage ?! it's true Link to comment
WiBox Posted September 20, 2021 Share Posted September 20, 2021 No, of course not. When you use addEventHandler with onChatMessage event, each time someone use /say /teamsay or /me it will automatically trigger onChatMessage event handler, means you have to use it only once. Just like the code I've send above. function getOnlineAdmins() local temp = {} --Temp table to insert all online admins in for index, players in ipairs (getElementsByType("player")) do --Loop over all players to check who's admin local account = getPlayerAccount(players) --Get player account if (account and not isGuestAccount(account)) then --Checking for any errors and whether the account is an guest account local accountName = getAccountName(account) --Get account name using the account local isAdmin = isObjectInACLGroup("user."..accountName, aclGetGroup("Admin")) --checking if user.accountName is added in Admin ACL group. if isAdmin then -- If he is.. table.insert(temp, players) --add him in table end end end return temp -- return it to get the table end function sendChatsToAdmins(message, by) local name local onlineAdmins = getOnlineAdmins() if (by and isElement(by) and getElementType(by) == "player") then name = getPlayerName(by).."(player)" elseif (by) then for index, resources in ipairs (getResources()) do if (by == resources) then name = getResourceName(by).."(resource)" end end else name = "Unknown: " end for index, admins in ipairs (onlineAdmins()) do outputChatBox(name..": "..message, admins, 255, 255, 255) --PlayerName(player): message or ResourceName(resource): message end end addEventHandler("onChatMessage", root, sendChatsToAdmins) Should be something like this? It isn't written perfectly but it should do the job Link to comment
MrLoKi Posted September 21, 2021 Author Share Posted September 21, 2021 (edited) No No , You did not understand what I meant I want a code that looks like this ( Spec Camera Player ) => ( Spec Chats Player ) To show all the chats sent to the player => And Sent To Admins It is as if we are playing on that system Edited September 21, 2021 by MrLoKi Link to comment
WiBox Posted September 21, 2021 Share Posted September 21, 2021 (edited) I've no time left to explain to code, hope you got the logic behind it --Server side! local chats = {} local chatRange = 20 --Range to check who's near by the player local saveTimer, saveInterval = false, 50*1000 --Each 50 seconds, save chat to .txt local adminSpectating = {} function getPlayerAccountName(plr) return getAccountName(getPlayerAccount(plr)) end function getOnlineAdmins() local temp = {} --Temp table to insert all online admins in for index, players in ipairs (getElementsByType("player")) do --Loop over all players to check who's admin local account = getPlayerAccount(players) --Get player account if (account and not isGuestAccount(account)) then --Checking for any errors and whether the account is an guest account local accountName = getAccountName(account) --Get account name using the account local isAdmin = isObjectInACLGroup("user."..accountName, aclGetGroup("Admin")) --checking if user.accountName is added in Admin ACL group. if isAdmin then -- If he is.. table.insert(temp, players) --add him in table end end end return temp -- return it to get the table end function getPlayersInRange (plr, range) local x, y, z = getElementPosition(plr) local players = {} for index, value in ipairs(getElementsByType("player")) do if(plr and value)then --Usually we would check if plr ~= value so we don't add him to the list, although we want to save the 'plr' chat as well! local Sx, Sy, Sz = getElementPosition(value) local distance = getDistanceBetweenPoints3D(x, y, z, Sx, Sy, Sz) if(distance <= range)then table.insert(players, value) end end end return players end function onPlayerChat(msg, msgType) local type = "("..getPlayerName(source)..") " if (msgType == 0) then type = "/say: " elseif (msgType == 1) then type = "/me: " elseif (msgType == 2) then type = "/teamsay: " elseif (msgType == 3) then type = "private: " elseif (msgType == 4) then type = "internal: " else type = "unknown :" end for index, value in ipairs(getOnlineAdmins()) do if (adminSpectating[value] == source) then triggerClientEvent(value, "addToMemo", value, type.." "..msg) end end local accountName local playersInRange = getPlayersInRange(source, chatRange) for index, value in ipairs (playersInRange) do accountName = getPlayerAccountName(value) if (not chats[accountName]) then --We must make sure that the table chats[accountName] exists! chats[accountName] = {} end table.insert(chats[accountName], type.." "..msg) --Now all messages that the player(source) said are saved for everyone and himself! end --In the same sense, if you know want to check what the player said and whatever was said next him, are saved in that table end --But like that your server RAM will cry xD. So we'll save the chats in a TXT file! addEventHandler("onPlayerChat", root, onPlayerChat) --Once any player chats function loadChatsToMemo(admin, player) if (not admin or not player) then --If admin or player were not given return false --End the function end local accountName = getPlayerAccountName(player) if (not fileExists("chats/"..accountName..".txt")) then return triggerClientEvent(admin, "loadChatToMemo", admin, false) --If file doesn't exists, let the admin know! end local file = fileOpen("chats/"..accountName..".txt") local fileSize = fileGetSize(file) local fileContent = fileRead(file, fileSize) triggerClientEvent(admin, "loadChatsToMemo", admin, fileContent) end function saveChats() for index, value in ipairs (getElementsByType("player")) do local accountName = getPlayerAccountName(value) local file if (fileExists("chats/"..accountName..".txt")) then file = fileOpen("chats/"..accountName..".txt") else file = fileCreate("chats/"..accountName..".txt") end if (file) then for index2, messages in ipairs (chats[accountName]) do fileWrite(file, messages) end fileClose(file) chats[accountName] = {} --re empty the table once you save its data, so it doesn't duplicate. end end end saveTimer = setTimer(saveChats, saveInterval, 0) function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end return false end function spectatePlr(admin, cmd, playerName) if (not isObjectInACLGroup("user."..getPlayerAccountName(admin), aclGetGroup("Admin")) then -- if the one who used the command isn't an Admin return false -- End the function end local player = getPlayerFromPartialName(playerName) --helps to find a player using a part of his name! if (not player) then return outputChatBox("ERROR: Please re-enter the player's nickname!", admin, 255, 150, 0) end setCameraTarget(admin, player) loadChatsToMemo(admin, player) adminSpectating[admin] = player end addCommandHandler("spectate", spectatePlr) function stopSpectate(admin) if (not isObjectInACLGroup("user."..getPlayerAccountName(admin), aclGetGroup("Admin") and adminSpectating[admin]) then return false -- if the one who used the command isn't an Admin, End the function end setCameraTarget(admin) --Retarget it to the admin triggerClientEvent(admin, "closeMemo", admin) adminSpectating[admin] = false end addCommandHandler("stopspectate", stopSpectate) --Client Side! local chatWindow function loadChatsToMemo(chats) if (not chatWindow) then local screenX, screenY = guiGetScreenSize() chatWindow = guiCreateWindow(screenX-300, 0, 300, 300, "Chats Record", false) chatMemo = guiCreateMemo(0, 0, 300, 300, "Loading...", false, chatWindow) guiWindowSetSizable(chatWindow, false) guiSetAlpha(chatWindow, 1) end showCursor(true) if (not chats) then return guiSetText(chatMemo, "This player has no chat record!") end guiSetText(chatMemo, chats) end addEvent("loadChatsToMemo", true) addEventHandler("loadChatsToMemo", localPlayer, loadChatsToMemo) function addToMemo(message) guiSetText(chatMemo, guiGetText(chatMemo).."\n"..addToMemo) end addEvent("addToMemo", true) addEventHandler("addToMemo", localPlayer, addToMemo) function closeMemo() guiSetVisible(chatWindow, false) showCursor(false) end addEvent("closeMemo", true) addEventHandler("closeMemo", localPlayer, closeMemo) I didn't test it, but that should do the job? Edited September 21, 2021 by WiBox editing description Link to comment
MrLoKi Posted September 21, 2021 Author Share Posted September 21, 2021 That was not the code I was looking for yet But the code you gave me was great , Thank you Link to comment
WiBox Posted September 21, 2021 Share Posted September 21, 2021 (edited) I understood that you want to send to the admin whatever the player IS saying, and whatever is being said TO the player right? You can't tell if something is chatting to him directly, so I saved whatever is being said next him Chat with me private in your own native language and explain precisely what you need~ Edited September 21, 2021 by WiBox Link to comment
MrLoKi Posted September 21, 2021 Author Share Posted September 21, 2021 So far so good See I want something that every chat sends to the player ( From the side Server , Player , Alllll Chats ) The Admins also watches I even want to see the errors that the server gives her Link to comment
WiBox Posted September 21, 2021 Share Posted September 21, 2021 Uh that's well too much If you want, you can make a log panel, insert inside it whatever you want? Something like ( exports.log:logSomething(player, "message") ) message can be whatever u want to log inside it error, message, chat, whatever Link to comment
MrLoKi Posted September 21, 2021 Author Share Posted September 21, 2021 Thanks so much for the tips 1 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