Jump to content

help. Nametag


Recommended Posts

--server 
iv = 0
function toggleInvis( source )
	if iv == 0 then
		iv = 1
		setElementAlpha(source, 0)
		triggerClientEvent(source, "invis", source)
	else
		iv = 0
		setElementAlpha(source, 255)
		triggerClientEvent(source, "invisoff", source)
	end
end
addCommandHandler ( "invisible", toggleInvis )
--client
local visiblename = true
local drawDistance = 15
g_StreamedInPlayers = {}

function onClientRender()
  local cx, cy, cz, lx, ly, lz = getCameraMatrix()
  for k, player in pairs(g_StreamedInPlayers) do
    if isElement(player) and isElementStreamedIn(player) then
      do
        local vx, vy, vz = getPedBonePosition(player, 8)
        local dist = getDistanceBetweenPoints3D(cx, cy, cz, vx, vy, vz)
        if dist < drawDistance and isLineOfSightClear(cx, cy, cz, vx, vy, vz, true, false, false) then
          local x, y = getScreenFromWorldPosition(vx, vy, vz + 0.3)
          if x and y then
            local name = getPlayerName(player)
			local id = getElementData ( player, "ID", s_id )
            local w = dxGetTextWidth(name, 1, "default-bold")
            local h = dxGetFontHeight(1, "default-bold")
			local fname = getElementData(player,"fname")
			local sname = getElementData(player,"sname")
			local hp = getElementData(player,"lastDamage")
			if visiblename == false then
			return
			end
			if visiblename == true then
			dxDrawText("#FFFFFF"..fname.." "..sname.."#1E90FF ["..id.."]", x - 2 - w / 4, y - 0 - h - 12, w, h, tocolor(255, 0, 0), 1, "default-bold","left","top",false,false,false,true)
           end
		   local health = getElementHealth(player)
            local armour = getPedArmor(player)
            if health > 0 then
              local rate = 500 / getPedStat(player, 24)
              drawHPBar(x, y - 6, health * rate, dist)
              if armour > 0 then
                drawArmourBar(x, y - 12, armour, dist)
              end		
			end
          end
        end
      end
    else
      table.remove(g_StreamedInPlayers, k)
    end
  end
  end
addEventHandler("onClientRender", root, onClientRender)
  
function invis()
visiblename = false
end
addEvent( "invis", true )
addEventHandler( "invis", localPlayer, invis )

function invisoff()
visiblename = true
end
addEvent( "invisoff", true )
addEventHandler( "invisoff", localPlayer, invis )
  
function onClientElementStreamIn()
  if getElementType(source) == "player" and source ~= getLocalPlayer() then
    setPlayerNametagShowing(source, false)
    table.insert(g_StreamedInPlayers, source)
  end
end
addEventHandler("onClientElementStreamIn", root, onClientElementStreamIn)
function onClientResourceStart(startedResource)
  visibleTick = getTickCount()
  counter = 0
  normalhealthbar = false
  local players = getElementsByType("player")
  for k, v in pairs(players) do
    if isElementStreamedIn(v) and v ~= getLocalPlayer() then
      setPlayerNametagShowing(v, false)
      table.insert(g_StreamedInPlayers, v)
    end
  end
end
addEventHandler("onClientResourceStart", resourceRoot, onClientResourceStart)

I'm trying to make a command for invisible.

For example, a player enters a command and becomes invisible. - Done

need to hide the nickname only this player(who type this command). but I can only hide the nicknames of all players

Can you help me for fix it?

I am the player who entered this command.I do not see the nicknames of players but they see

Link to comment

This should work.

 

-- client

local drawDistance = 15
g_StreamedInPlayers = {}

function onClientRender()
  local cx, cy, cz, lx, ly, lz = getCameraMatrix()
  for k, player in pairs(g_StreamedInPlayers) do
    if isElement(player) and isElementStreamedIn(player) then
      do
        local vx, vy, vz = getPedBonePosition(player, 8)
        local dist = getDistanceBetweenPoints3D(cx, cy, cz, vx, vy, vz)
        if dist < drawDistance and isLineOfSightClear(cx, cy, cz, vx, vy, vz, true, false, false) then
          local x, y = getScreenFromWorldPosition(vx, vy, vz + 0.3)
          if x and y then
            local name = getPlayerName(player)
			local id = getElementData ( player, "ID", s_id )
            local w = dxGetTextWidth(name, 1, "default-bold")
            local h = dxGetFontHeight(1, "default-bold")
			local fname = getElementData(player,"fname")
			local sname = getElementData(player,"sname")
			local hp = getElementData(player,"lastDamage")
			dxDrawText("#FFFFFF"..fname.." "..sname.."#1E90FF ["..id.."]", x - 2 - w / 4, y - 0 - h - 12, w, h, tocolor(255, 0, 0), 1, "default-bold","left","top",false,false,false,true)
			local health = getElementHealth(player)
            local armour = getPedArmor(player)
            if health > 0 then
              local rate = 500 / getPedStat(player, 24)
              drawHPBar(x, y - 6, health * rate, dist)
              if armour > 0 then
                drawArmourBar(x, y - 12, armour, dist)
              end		
			end
          end
        end
      end
    else
      table.remove(g_StreamedInPlayers, k)
    end
  end
  end
addEventHandler("onClientRender", root, onClientRender)
  
function invis()
	for k, player in pairs(g_StreamedInPlayers) do
		if player == source then
			table.remove(g_StreamedInPlayers, k)
		end
	end
end
addEvent( "invis", true )
addEventHandler( "invis", root, invis )

function invisoff()
	table.insert(g_StreamedInPlayers, source)
end
addEvent( "invisoff", true )
addEventHandler( "invisoff", root, invisoff)
  
function onClientElementStreamIn()
  if getElementType(source) == "player" and source ~= getLocalPlayer() then
    setPlayerNametagShowing(source, false)
    table.insert(g_StreamedInPlayers, source)
  end
end
addEventHandler("onClientElementStreamIn", root, onClientElementStreamIn)

function onClientResourceStart(startedResource)
  visibleTick = getTickCount()
  counter = 0
  normalhealthbar = false
  local players = getElementsByType("player")
  for k, v in pairs(players) do
    if isElementStreamedIn(v) and v ~= getLocalPlayer() then
      setPlayerNametagShowing(v, false)
      table.insert(g_StreamedInPlayers, v)
    end
  end
end
addEventHandler("onClientResourceStart", resourceRoot, onClientResourceStart)

-- server 

iv = 0
function toggleInvis( source )
	if iv == 0 then
		iv = 1
		setElementAlpha(source, 0)
		triggerClientEvent(source, "invis", source)
	else
		iv = 0
		setElementAlpha(source, 255)
		triggerClientEvent(source, "invisoff", source)
	end
end
addCommandHandler ( "invisible", toggleInvis )

 

  • Like 1
Link to comment
3 hours ago, HassoN said:

This should work.

 


-- client

local drawDistance = 15
g_StreamedInPlayers = {}

function onClientRender()
  local cx, cy, cz, lx, ly, lz = getCameraMatrix()
  for k, player in pairs(g_StreamedInPlayers) do
    if isElement(player) and isElementStreamedIn(player) then
      do
        local vx, vy, vz = getPedBonePosition(player, 8)
        local dist = getDistanceBetweenPoints3D(cx, cy, cz, vx, vy, vz)
        if dist < drawDistance and isLineOfSightClear(cx, cy, cz, vx, vy, vz, true, false, false) then
          local x, y = getScreenFromWorldPosition(vx, vy, vz + 0.3)
          if x and y then
            local name = getPlayerName(player)
			local id = getElementData ( player, "ID", s_id )
            local w = dxGetTextWidth(name, 1, "default-bold")
            local h = dxGetFontHeight(1, "default-bold")
			local fname = getElementData(player,"fname")
			local sname = getElementData(player,"sname")
			local hp = getElementData(player,"lastDamage")
			dxDrawText("#FFFFFF"..fname.." "..sname.."#1E90FF ["..id.."]", x - 2 - w / 4, y - 0 - h - 12, w, h, tocolor(255, 0, 0), 1, "default-bold","left","top",false,false,false,true)
			local health = getElementHealth(player)
            local armour = getPedArmor(player)
            if health > 0 then
              local rate = 500 / getPedStat(player, 24)
              drawHPBar(x, y - 6, health * rate, dist)
              if armour > 0 then
                drawArmourBar(x, y - 12, armour, dist)
              end		
			end
          end
        end
      end
    else
      table.remove(g_StreamedInPlayers, k)
    end
  end
  end
addEventHandler("onClientRender", root, onClientRender)
  
function invis()
	for k, player in pairs(g_StreamedInPlayers) do
		if player == source then
			table.remove(g_StreamedInPlayers, k)
		end
	end
end
addEvent( "invis", true )
addEventHandler( "invis", root, invis )

function invisoff()
	table.insert(g_StreamedInPlayers, source)
end
addEvent( "invisoff", true )
addEventHandler( "invisoff", root, invisoff)
  
function onClientElementStreamIn()
  if getElementType(source) == "player" and source ~= getLocalPlayer() then
    setPlayerNametagShowing(source, false)
    table.insert(g_StreamedInPlayers, source)
  end
end
addEventHandler("onClientElementStreamIn", root, onClientElementStreamIn)

function onClientResourceStart(startedResource)
  visibleTick = getTickCount()
  counter = 0
  normalhealthbar = false
  local players = getElementsByType("player")
  for k, v in pairs(players) do
    if isElementStreamedIn(v) and v ~= getLocalPlayer() then
      setPlayerNametagShowing(v, false)
      table.insert(g_StreamedInPlayers, v)
    end
  end
end
addEventHandler("onClientResourceStart", resourceRoot, onClientResourceStart)

-- server 

iv = 0
function toggleInvis( source )
	if iv == 0 then
		iv = 1
		setElementAlpha(source, 0)
		triggerClientEvent(source, "invis", source)
	else
		iv = 0
		setElementAlpha(source, 255)
		triggerClientEvent(source, "invisoff", source)
	end
end
addCommandHandler ( "invisible", toggleInvis )

 

@HassoN 

nickname player(who type this command) is not hiding but now he sees the nicknames of other players (before they disappeared)

Link to comment

Try this

 

local drawDistance = 15
g_StreamedInPlayers = {}
local blockedPlayers = {}

function onClientRender()
  local cx, cy, cz, lx, ly, lz = getCameraMatrix()
  for k, player in ipairs(g_StreamedInPlayers) do
    if isElement(player) and isElementStreamedIn(player) then
      do
        local vx, vy, vz = getPedBonePosition(player, 8)
        local dist = getDistanceBetweenPoints3D(cx, cy, cz, vx, vy, vz)
		if blockedPlayers[player] then return false end
        if dist < drawDistance and isLineOfSightClear(cx, cy, cz, vx, vy, vz, true, false, false) then
          local x, y = getScreenFromWorldPosition(vx, vy, vz + 0.3)
          if x and y then
            local name = getPlayerName(player)
			local id = getElementData ( player, "ID", s_id )
            local w = dxGetTextWidth(name, 1, "default-bold")
            local h = dxGetFontHeight(1, "default-bold")
			local fname = getElementData(player,"fname")
			local sname = getElementData(player,"sname")
			local hp = getElementData(player,"lastDamage")
			dxDrawText("#FFFFFF"..fname.." "..sname.."#1E90FF ["..id.."]", x - 2 - w / 4, y - 0 - h - 12, w, h, tocolor(255, 0, 0), 1, "default-bold","left","top",false,false,false,true)
			local health = getElementHealth(player)
            local armour = getPedArmor(player)
            if health > 0 then
              local rate = 500 / getPedStat(player, 24)
              drawHPBar(x, y - 6, health * rate, dist)
              if armour > 0 then
                drawArmourBar(x, y - 12, armour, dist)
              end		
			end
          end
        end
      end
    else
      table.remove(g_StreamedInPlayers, k)
    end
  end
  end
addEventHandler("onClientRender", root, onClientRender)
  
function invis()
	blockedPlayers[source] = true
end
addEvent( "invis", true )
addEventHandler( "invis", root, invis )

function invisoff()
	blockedPlayers[source] = nil
end
addEvent( "invisoff", true )
addEventHandler( "invisoff", root, invisoff)
  
function onClientElementStreamIn()
  if getElementType(source) == "player" and source ~= getLocalPlayer() then
    setPlayerNametagShowing(source, false)
    table.insert(g_StreamedInPlayers, source)
  end
end
addEventHandler("onClientElementStreamIn", root, onClientElementStreamIn)

function onClientResourceStart(startedResource)
  visibleTick = getTickCount()
  counter = 0
  normalhealthbar = false
  local players = getElementsByType("player")
  for k, v in ipairs(players) do
    if isElementStreamedIn(v) and v ~= getLocalPlayer() then
      setPlayerNametagShowing(v, false)
      table.insert(g_StreamedInPlayers, v)
    end
  end
end
addEventHandler("onClientResourceStart", resourceRoot, onClientResourceStart)

-- server 

iv = 0
function toggleInvis( source )
	if iv == 0 then
		iv = 1
		setElementAlpha(source, 0)
		triggerClientEvent(source, "invis", source)
	else
		iv = 0
		setElementAlpha(source, 255)
		triggerClientEvent(source, "invisoff", source)
	end
end
addCommandHandler ( "invisible", toggleInvis )

 

btw you should use ipairs with tables that have numbers as index. (I modified it for you)

Edited by HassoN
  • Like 1
Link to comment

I tried this by myself and it's working.

 

-- client

local drawDistance = 15
g_StreamedInPlayers = {}

function onClientRender()
  local cx, cy, cz, lx, ly, lz = getCameraMatrix()
  for k, player in ipairs(g_StreamedInPlayers) do
    if isElement(player) and isElementStreamedIn(player) then
      do
        local vx, vy, vz = getPedBonePosition(player, 8)
        local dist = getDistanceBetweenPoints3D(cx, cy, cz, vx, vy, vz)
		if getElementData(player, "invisiblePlayer") then return false end
        if dist < drawDistance and isLineOfSightClear(cx, cy, cz, vx, vy, vz, true, false, false) then
          local x, y = getScreenFromWorldPosition(vx, vy, vz + 0.3)
          if x and y then
            local name = getPlayerName(player)
			local id = getElementData ( player, "ID", s_id ) or "0"
            local w = dxGetTextWidth(name, 1, "default-bold")
            local h = dxGetFontHeight(1, "default-bold")
			local fname = getElementData(player,"fname") or getPlayerName(player)
			local sname = getElementData(player,"sname") or "S"
			local hp = getElementData(player,"lastDamage") or "100"
			dxDrawText("#FFFFFF"..fname.." "..sname.."#1E90FF ["..id.."]", x - 2 - w / 4, y - 0 - h - 12, w, h, tocolor(255, 0, 0), 1, "default-bold","left","top",false,false,false,true)
			local health = getElementHealth(player)
            local armour = getPedArmor(player)
            if health > 0 then
              local rate = 500 / getPedStat(player, 24)
              drawHPBar(x, y - 6, health * rate, dist)
              if armour > 0 then
                drawArmourBar(x, y - 12, armour, dist)
              end		
			end
          end
        end
      end
    else
      table.remove(g_StreamedInPlayers, k)
    end
  end
  end
addEventHandler("onClientRender", root, onClientRender)
  
  
function onClientElementStreamIn()
  if getElementType(source) == "player" and source ~= getLocalPlayer() then
    setPlayerNametagShowing(source, false)
    table.insert(g_StreamedInPlayers, source)
  end
end
addEventHandler("onClientElementStreamIn", root, onClientElementStreamIn)

function onClientResourceStart(startedResource)
  visibleTick = getTickCount()
  counter = 0
  normalhealthbar = false
  local players = getElementsByType("player")
  for k, v in ipairs(players) do
    if isElementStreamedIn(v) and v ~= getLocalPlayer() then
      setPlayerNametagShowing(v, false)
      table.insert(g_StreamedInPlayers, v)
    end
  end
end
addEventHandler("onClientResourceStart", resourceRoot, onClientResourceStart)


-- server

function toggleInvis( source )
	if getElementAlpha(source) == 255 then
		setElementAlpha(source, 0)
		setElementData(source, "invisiblePlayer", true)
	else
		setElementAlpha(source, 255)
		setElementData(source, "invisiblePlayer", nil)
	end
end
addCommandHandler ( "invisible", toggleInvis )

The code is a huge mess tho, you could order it a little bit more.

  • Like 1
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...