Jump to content

[Help]onClientChatMessage


MrLoKi

Recommended Posts

Posted

Hello friends !

I want to create a spy mode for my server admin using onClientChatMessage

That the admin can spy on the whole chat player !

Please help me.....

Posted

Hello MrLoki,

I have found this topic inside of our forums that seems to ask a similar question.

Does it help you in any way? If not, could you explain what the solutions provided in said topic are missing based on your imagination?

Posted (edited)

Server side:

addCommandHandler("spy",
function (player, command, target)
	if target then
		local ppl = getPlayerFromName(target)
		if ppl then
			setElementData(ppl, "spy", thePlayer)
			outputChatBox("Enabled on: "..getPlayerName(ppl).."", player, 255, 255, 255)
		end
	else
		outputChatBox("USAGE: /"..command.." <Player-Name>", player, 255, 255, 255)
	end
end)

addEvent("spy:ShowChat", true)
addEventHandler("spy:ShowChat", root,
function (root, message)
	local spy = getElementData(root, "spy")
	if spy then
		outputChatBox("[SPY-Mode] "..getPlayerName(root)..": "..message, spy, 255, 255, 255)
	end
end)

Client side:

local lastMessage = nil

addEventHandler("onClientChatMessage", getRootElement(),
function (message)
	if not getElementData(getLocalPlayer(), "spy") then
		return false
	end
	if message == "" or message == " " then
		if lastMessage == message then
			return
		end
	end
	lastMessage = message
	triggerServerEvent("spy:ShowChat", getLocalPlayer(), getLocalPlayer(), message)
end)

 

 

I use this code but chats are not sent to the admin !

 

I wanted a code similar to this

Edited by MrLoKi
Posted (edited)
13 hours ago, MrLoKi said:

I wanted a code similar to this

I still cannot understand what kind of code you are looking for. The above script has some errors [EDIT]. Could you please help us understand what is missing from the script?

  • which "admin" should receive those messages? should all admins receive it or specific admins (issuer of command, admin group, etc)
  • what players should be spied on?

I recommend you to detect admins based on the player account. When a player has logged into an internal MTA server account, then that account can be given rights inside of the ACL.xml file. Inside of that file you can create a special permission called "spychat" as well as limit the accessibility to MTA commands (for example /spy). You could loop through all logged in players using a for-loop on getElementsByType("player") and create a list of only the players that meet the "spychat" permission/right.

Edited by The_GTA

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