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

rsilex.png.0e6ad382b3fdc3cbe6390e3e847572c9.png
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.

tJ5zeFm.gif

Proud owner and developer of ZNEXT: Aftermath.

Enter a post-apocalyptic San Andreas and fight over 30 types of enemies and bosses with varying difficulties and skills, improve and customize your character by leveling up, completing challenges and a solid lootbox system with no Pay-to-Win mechanics that will break your experience.

Meet new characters, creatures and weapon metas, experience an innovative combo-based melee system, or join our solid PvP modes to show other survivors who’s boss. 

Español, Pусский, Türk, عربى, Polski, Português

IP: mtasa://104.36.110.227:22003 - Discord: https://discord.gg/CxMxjvC5pB

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