Jump to content

[Help] onResourceStop


ÆBKV

Recommended Posts

Posted (edited)
local ghostmode = false

addCommandHandler("ghostmode",
function(player)
  if not hasObjectPermissionTo(player,"general.adminpanel") then
    outputChatBox("You don't have permission to use this command.",player,255,0,0)
    return
  end
  local blip = getBlipAttachedTo(player)
  local r,g,b = getPlayerNametagColor(player)
  for index,players in ipairs(getElementsByType("player")) do
    if ghostmode == false then
      ghostmode = true
      setElementVisibleTo(player,players,false)
      setPlayerNametagShowing(player,false)
      setElementAlpha(player,200)
      destroyElement(blip)
      outputChatBox("Ghost Mode: #00FF00enabled",player,255,255,255,true)
    else
      ghostmode = false
      setElementVisibleTo(player,players,true)
      setPlayerNametagShowing(player,true)
      setElementAlpha(player,255)
      createBlipAttachedTo(player,0,2,r,g,b,255)
      outputChatBox("Ghost Mode: #FF0000disabled",player,255,255,255,true)
    end
  end
end
)

function getBlipAttachedTo(player)
	for index,blips in ipairs(getElementsByType("blip")) do
		if getElementAttachedTo(blips) == player then
			return blips
    end
  end
	return false
end

How can I restore everything when the resource stops?

I've tried everything but it does not work.

Edited by ÆBKV
Posted
local ghostmode = false

addCommandHandler("ghostmode",
function(player)
	if not hasObjectPermissionTo(player,"general.adminpanel") then
		outputChatBox("You don't have permission to use this command.",player,255,0,0)
		return
	end
	local blip = getBlipAttachedTo(player)
	local r,g,b = getPlayerNametagColor(player)
	for index,players in ipairs(getElementsByType("player")) do
		if ghostmode == false then
			ghostmode = true
			setElementVisibleTo(player,players,false)
			setPlayerNametagShowing(player,false)
			setElementAlpha(player,200)
			destroyElement(blip)
			outputChatBox("Ghost Mode: #00FF00enabled",player,255,255,255,true)
		else
			ghostmode = false
			setElementVisibleTo(player,players,true)
			setPlayerNametagShowing(player,true)
			setElementAlpha(player,255)
			createBlipAttachedTo(player,0,2,r,g,b,255)
			outputChatBox("Ghost Mode: #FF0000disabled",player,255,255,255,true)
		end
	end
end)

function getBlipAttachedTo(player)
	for index,blips in ipairs(getElementsByType("blip")) do
		if getElementAttachedTo(blips) == player then
			return blips
		end
	end
	return false
end

addEventHandler("onResourceStop", resourceRoot,
function()
	for index, players in pairs(getElementsByType("player")) do
		setElementVisibleTo(player, players, true)
		setPlayerNametagShowing(player, true)
		setElementAlpha(player, 255)
		local blip = getBlipAttachedTo(player)
		if blip then
			destroyElement(blip)
		end
	end
end)

Didn't tested it but should work..

Posted

Is it the same if I use root instead of players. Do you know that maybe?  

like this

setElementVisibleTo(player,root,false)

 

Posted
4 minutes ago, ÆBKV said:

Is it the same if I use root instead of players. Do you know that maybe?  

like this


setElementVisibleTo(player,root,false)

 

It will work, the player elements that are children of the root element will be affected. So yes.

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