Jump to content

Ignore all player's messages


Makaveli15

Recommended Posts

You will need to create your own chat handling, same for private messaging if you want to prevent that as well and then you can manage to do that type of stuff.

edit: actually never mind. There's a chat event on client as well. You can use that to detect whose message is who and then cancel it if it's one of blocked players. https://wiki.multitheftauto.com/wiki/OnClientChatMessage

This should do the trick

local blocked_players = {}

addEventHandler("onClientChatMessage",root,function()
	if (blocked_players[source]) then
		cancelEvent()
		outputChatBox(getPlayerName(source).." wrote something in chat, but you blocked him.")
	end
end)

addCommandHandler("block",function(cmd,plyname)
	local target = getPlayerFromName(plyname)
	if (plyname and target) then
		if (not blocked_players[target]) then
			blocked_players[target] = true;
			outputChatBox("player"..plyname.." blocked!")
		else
			blocked_players[target] = nil;
			outputChatBox("player"..plyname.." unblocked!")
		end
	else
		outputChatBox("player not found")
	end
end)

 

Edited by Fist
Link to comment
  On 14/11/2018 at 16:36, Fist said:

You will need to create your own chat handling, same for private messaging if you want to prevent that as well and then you can manage to do that type of stuff.

edit: actually never mind. There's a chat event on client as well. You can use that to detect whose message is who and then cancel it if it's one of blocked players. https://wiki.multitheftauto.com/wiki/OnClientChatMessage

This should do the trick


local blocked_players = {}

addEventHandler("onClientChatMessage",root,function()
	if (blocked_players[source]) then
		cancelEvent()
		outputChatBox(getPlayerName(source).." wrote something in chat, but you blocked him.")
	end
end)

addCommandHandler("block",function(cmd,plyname)
	local target = getPlayerFromName(plyname)
	if (plyname and target) then
		if (not blocked_players[target]) then
			blocked_players[target] = true;
			outputChatBox("player"..plyname.." blocked!")
		else
			blocked_players[target] = nil;
			outputChatBox("player"..plyname.." unblocked!")
		end
	else
		outputChatBox("player not found")
	end
end)

 

Expand  

what will be the command for it? 

Link to comment
  On 14/11/2018 at 16:55, OsO.cp said:

what will be the command for it? 

Expand  

/block playername also you can unblock someone by writing same command.

dude, if you can't understand what command that script is using then idk. There's no hope for you, just drop learning this, if you are trying to learn it. It certainly doesn't look like you are trying to learn anything if you can't understand what command under is that script.

Link to comment
  On 14/11/2018 at 17:08, Fist said:

/block playername also you can unblock someone by writing same command.

dude, if you can't understand what command that script is using then idk. There's no hope for you, just drop learning this, if you are trying to learn it. It certainly doesn't look like you are trying to learn anything if you can't understand what command under is that script.

Expand  

yea, im so bad..

 

  On 14/11/2018 at 17:08, Fist said:

/block playername also you can unblock someone by writing same command.

dude, if you can't understand what command that script is using then idk. There's no hope for you, just drop learning this, if you are trying to learn it. It certainly doesn't look like you are trying to learn anything if you can't understand what command under is that script.

Expand  

It doesn't work. shows unexpected symbol near '

Edited by OsO.cp
Link to comment
local blocked_players = {}

addEventHandler("onClientChatMessage",root,function()
	if (blocked_players[source]) then
		cancelEvent()
		outputChatBox(getPlayerName(source).." wrote something in chat, but you blocked him.")
	end
end)

function block(cmd,plyname)
	local target = getPlayerFromName(plyname)
	if (plyname and target) then
		if (not blocked_players[target]) then
			blocked_players[target] = true;
			outputChatBox("player"..plyname.." blocked!")
		else
			blocked_players[target] = nil;
			outputChatBox("player"..plyname.." unblocked!")
		end
	else
		outputChatBox("player not found")
	end
end
addCommandHandler("block", block)

 

Link to comment
  On 14/11/2018 at 22:14, mazarati21 said:

local blocked_players = {}

addEventHandler("onClientChatMessage",root,function()
	if (blocked_players[source]) then
		cancelEvent()
		outputChatBox(getPlayerName(source).." wrote something in chat, but you blocked him.")
	end
end)

function block(cmd,plyname)
	local target = getPlayerFromName(plyname)
	if (plyname and target) then
		if (not blocked_players[target]) then
			blocked_players[target] = true;
			outputChatBox("player"..plyname.." blocked!")
		else
			blocked_players[target] = nil;
			outputChatBox("player"..plyname.." unblocked!")
		end
	else
		outputChatBox("player not found")
	end
end
addCommandHandler("block", block)

 

Expand  

still writes the same: unexpected symbol near '

Link to comment
local blockedPlayers = {}

function getPlayerFromPatrialName(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
end

addEventHandler("onClientMessage", root, 
   function()
    if blockedPlayers[source] then
       cancelEvent()
       outputChatBox(getPlayerName(source).." wrote something in chat, but you block him!")
     end
    end
)

function block(cmd, target)
  local targetPlayer = getPlayerFromPatrialName(target)
  if target and targetPlayer then
       if not blockedPlayers[targetPlayer] then
          blockedPlayer[targetPlayer] = true
          outputChatBox("player "..getPlayerName(targetPlayer).. "blocked")
      else
         blockedPlayers[targetPlayer] = nil
         outputChatBox("player ".. getPlayerName(targetPlayer).." unblocked")
      end
  else
    outputChatBox("Player not found!")
  end
end
addCommandHandler("block", block)

 

Edited by Dimos7
Link to comment
  On 15/11/2018 at 17:00, Dimos7 said:

local blockedPlayers = {}

function getPlayerFromPatrialName(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
end

addEventHandler("onClientMessage", root, 
   function()
    if blockedPlayers[source] then
       cancelEvent()
       outputChatBox(getPlayerName(source).." wrote something in chat, but you block him!")
     end
    end
)

function block(cmd, target)
  local targetPlayer = getPlayerFromPatrialName(target)
  if target and targetPlayer then
       if not blockedPlayers[targetPlayer] then
          blockedPlayer[targetPlayer] = true
          outputChatBox("player "..getPlayerName(targetPlayer).. "blocked")
      else
         blockedPlayers[targetPlayer] = nil
         outputChatBox("player ".. getPlayerName(targetPlayer).." unblocked")
      end
  else
    outputChatBox("Player not found!")
  end
end
addCommandHandler("block", block)

 

Expand  

'=' expected near '

Link to comment
local blockedPlayers = {}

function getPlayerFromPatrialName(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
end

addEventHandler("onClientMessage", root, 
   function()
    if blockedPlayers[source] then
       cancelEvent()
       outputChatBox(getPlayerName(source).." wrote something in chat, but you block him!")
     end
    end
)

function block(cmd, target)
  local targetPlayer = getPlayerFromPatrialName(target)
  if target and targetPlayer then
       if not blockedPlayers[targetPlayer] then
          blockedPlayers[targetPlayer] = true
          outputChatBox("player "..getPlayerName(targetPlayer).. " blocked")
      else
         blockedPlayers[targetPlayer] = nil
         outputChatBox("player ".. getPlayerName(targetPlayer).." unblocked")
      end
  else
    outputChatBox("Player not found!")
  end
end
addCommandHandler("block", block)
<meta>
     <script src="namefile.lua" type="client"/>
</meta>

 

Link to comment
  On 15/11/2018 at 19:19, Dimos7 said:

local blockedPlayers = {}

function getPlayerFromPatrialName(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
end

addEventHandler("onClientMessage", root, 
   function()
    if blockedPlayers[source] then
       cancelEvent()
       outputChatBox(getPlayerName(source).." wrote something in chat, but you block him!")
     end
    end
)

function block(cmd, target)
  local targetPlayer = getPlayerFromPatrialName(target)
  if target and targetPlayer then
       if not blockedPlayers[targetPlayer] then
          blockedPlayers[targetPlayer] = true
          outputChatBox("player "..getPlayerName(targetPlayer).. " blocked")
      else
         blockedPlayers[targetPlayer] = nil
         outputChatBox("player ".. getPlayerName(targetPlayer).." unblocked")
      end
  else
    outputChatBox("Player not found!")
  end
end
addCommandHandler("block", block)

<meta>
     <script src="namefile.lua" type="client"/>
</meta>

 

Expand  

Works, but still getting messages. pm/msg as well.

Link to comment

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