Jump to content

Area verde bug


Recommended Posts

Opa e que tipo eu uso um mod de area verde deboas so q nele os veiculos levam dano da pra dar tiro fora da area verde e explodir o carro q ta dentro dela e tbm o carro leva dano batendo dentro da area verde se alguem poder ajudar

 

 

client.Lua

-- Protect greenzone'd players from getting attacked etcetera
function onDamage()
	if getElementData(source, "greenzone") then
		cancelEvent()
	end
end
addEventHandler("onClientPlayerDamage", localPlayer, onDamage)

-- Prevent people from being knifed while in greenzone
function onStealthKill(target)
	if getElementData(target, "greenzone") then
		cancelEvent()
	end
end
addEventHandler("onClientPlayerStealthKill", localPlayer, onStealthKill)

-- Render the "Greenzone protected" text above their heads
function renderGreenzoneTag()
	local streamedPlayers = getElementsByType("player", root, true)
	if streamedPlayers and #streamedPlayers ~= 0 then
		local lpos = {getElementPosition(localPlayer)}
		for _, p in ipairs(streamedPlayers) do
			if p and isElement(p) then
				if getElementData(p, "greenzone") then
					local ppos = {getElementPosition(p)}
					if getDistanceBetweenPoints3D(lpos[1], lpos[2], lpos[3], ppos[1], ppos[2], ppos[3]) <= 20 then
						local x, y = getScreenFromWorldPosition(ppos[1], ppos[2], ppos[3] + 1.2)
						if x and y then
							dxDrawText("Voce esta protegido", x + 1, y + 1, x, y, tocolor(0, 0, 0), 0.5, "bankgothic", "center")
							dxDrawText("Voce esta protegido", x, y, x, y, tocolor(0, 220, 0), 0.5, "bankgothic", "center")
						end
					end
				end
			end
		end
	end
end
addEventHandler("onClientRender", root, renderGreenzoneTag)

-- The next 4 functions are for ghostmode (vehicles ramming greenzone'd players on foot, lifting them off, etcetera)
-- This protection is important; they usually try to forklift you out of greenzone, spawn a vehicle on you and catch you inside/annoy-ram you, then TP off to a clear zone to kill you, etcetera.
function onStreamIn()
	if not getElementData(localPlayer, "greenzone") then
		return
	end
	if getElementType(source) == "vehicle" then
		setElementCollidableWith(localPlayer, source, false)
	end
end
addEventHandler("onClientElementStreamIn", root, onStreamIn)

function cleanUp()
	if not getElementData(source, "greenzoneveh") then
		return
	end
	if getElementType(source) == "vehicle" and isElementCollidableWith(localPlayer, source) == false then
		setElementCollidableWith(localPlayer, source, true)
	end
end
addEventHandler("onClientElementStreamOut", resourceRoot, cleanUp)

function enterGreenzone()
	local x, y, z = getElementPosition(localPlayer)
	local nearbyVehicles = getElementsWithinRange(x, y, z, 300, "vehicle")

	for i, v in ipairs(nearbyVehicles) do
		setElementCollidableWith(localPlayer, v, false)
	end
end
addEvent("onEnterGreenzone", true)
addEventHandler("onEnterGreenzone", localPlayer, enterGreenzone)

function leaveGreenzone(p)
	local x, y, z = getElementPosition(localPlayer)
	local nearbyVehicles = getElementsWithinRange(x, y, z, 300, "vehicle")

	for i, v in ipairs(nearbyVehicles) do
		setElementCollidableWith(localPlayer, v, true)
	end
end
addEvent("onLeaveGreenzone", true)
addEventHandler("onLeaveGreenzone", localPlayer, leaveGreenzone)

-- This 'bug' is not expected to happen without some sort of interference, but is a generic safeguard.
-- If player exits the greenzone after incidentally having the bugfix applied to them, all controls will be automatically re-enabled anyways (that mechanism is in serverside).
function antiGreenzoneBug()
	if getElementData(localPlayer, "greenzone") then
		toggleControl("fire", false)
		toggleControl("action", false)
		toggleControl("aim_weapon", false)
		toggleControl("vehicle_fire", false)
		toggleControl("vehicle_secondary_fire", false)
	end
end
addEventHandler("onClientPlayerWeaponFire", localPlayer, antiGreenzoneBug)



Server.Lua

 

-- Format is: {x = 0, y = 0, z = 0, width = 0, depth = 0, height = 0},
local greenzones = {
	{x = 2441.173, y = -1721.99, z = 1 , width = 130, depth = 120, height = 100}, -- Grove Street
	{x = 304.336, y = -1836.197, z = 1 , width = 130, depth = 120, height = 100}, -- Praia Los Santos
	{x = 1154.833, y = -1385.175, z = 1 , width = 70, depth = 100, height = 115}, -- Los Santos Hospital
}

-- Initialize all zones on resource start
local z = {}
function initGreenzones()
	if greenzones and #greenzones ~= 0 then
		for _, v in ipairs(greenzones) do
			if v then
				if v.x and v.y and v.z and v.width and v.depth and v.height then
					local c = createColCuboid(v.x, v.y, v.z, v.width, v.depth, v.height)
					local rarea = createRadarArea(v.x, v.y, v.width, v.depth, 0, 255, 0, 150)
					setElementParent(rarea, c)
					if c then
						z[c] = true

						for _, p in ipairs(getElementsWithinColShape(c, "player")) do
							setElementData(p, "greenzone", true)
						end

						for _, v in ipairs(getElementsWithinColShape(c, "vehicle")) do
							setElementData(v, "greenzoneveh", true)
						end

						addEventHandler("onElementDestroy", c,
							function()
								if z[source] then
									z[source] = nil
								end
							end
						)

						addEventHandler("onColShapeHit", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "player" then
									if getElementData(h, "colShapeFix_OUT") then
										setElementData(h, "colShapeFix_OUT", false)
										return
									end

									-- Hack to prevent shooting bug: if player teleports from one greenzone directly to another and fails to clean up (on time)
									if getElementData(h, "greenzone") then
										setElementData(h, "colShapeFix_IN", true)
										triggerClientEvent(h, "onEnterGreenzone", h)
									else
										setElementData(h, "greenzone", true)
										toggleControl(h, "fire", false)
										toggleControl(h, "aim_weapon", false)
										toggleControl(h, "vehicle_fire", false)
										toggleControl(h, "vehicle_secondary_fire", false)
										outputChatBox("Você esta na area verde", h, 0, 220, 0)
										triggerClientEvent(h, "onEnterGreenzone", h)
									end
								end
							end
						)

						addEventHandler("onColShapeHit", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "vehicle" then
									setElementData(h, "greenzoneveh", true)
								end
							end
						)

						addEventHandler("onColShapeLeave", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "player" then
									if getElementData(h, "colShapeFix_IN") then
										setElementData(h, "colShapeFix_IN", false)
										return
									end

									if getElementData(h, "greenzone") then
										setElementData(h, "greenzone", false)
										toggleControl(h, "fire", true)
										toggleControl(h, "aim_weapon", true)
										toggleControl(h, "vehicle_fire", true)
										toggleControl(h, "vehicle_secondary_fire", true)
										outputChatBox("[AREA] Você saiu da area verde", h, 220, 220, 0)
										triggerClientEvent(h, "onLeaveGreenzone", h)
									else
										setElementData(h, "colShapeFix_OUT", true)
									end
								end
							end
						)

						addEventHandler("onColShapeLeave", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "vehicle" then
									setTimer(setElementData, 350, 1, h, "greenzoneveh", false)
								end
							end
						)

					end
				end
			end
		end
	end
end
addEventHandler("onResourceStart", resourceRoot, initGreenzones)

function resetGreenzoneData()
	for _, p in ipairs(getElementsByType("player")) do
		if isElement(p) then
			removeElementData(p, "greenzone")
		end
	end
end
addEventHandler("onResourceStop", resourceRoot, resetGreenzoneData)



Ajuda aew ❤️

Link to comment

amigo agente não costuma fazer isso.. mais eu estava com o meu editor aberto aqui e resolvi adiciona-lo para você

e aproveitando a função que o @Lord Henry deixou aqui resolvi fazer, veja se resolve o seu problema.
só não esquece de clicar ali, e deixar um THANKS.

Server.Lua

Spoiler

-- Format is: {x = 0, y = 0, z = 0, width = 0, depth = 0, height = 0},
local greenzones = {
	{x = 2441.173, y = -1721.99, z = 1 , width = 130, depth = 120, height = 100}, -- Grove Street
	{x = 304.336, y = -1836.197, z = 1 , width = 130, depth = 120, height = 100}, -- Praia Los Santos
	{x = 1154.833, y = -1385.175, z = 1 , width = 70, depth = 100, height = 115}, -- Los Santos Hospital
}

-- Initialize all zones on resource start
local z = {}
function initGreenzones()
	if greenzones and #greenzones ~= 0 then
		for _, v in ipairs(greenzones) do
			if v then
				if v.x and v.y and v.z and v.width and v.depth and v.height then
					local c = createColCuboid(v.x, v.y, v.z, v.width, v.depth, v.height)
					local rarea = createRadarArea(v.x, v.y, v.width, v.depth, 0, 255, 0, 150)
					setElementParent(rarea, c)
					if c then
						z[c] = true

						for _, p in ipairs(getElementsWithinColShape(c, "player")) do
							setElementData(p, "greenzone", true)
						end

						for _, v in ipairs(getElementsWithinColShape(c, "vehicle")) do
							setElementData(v, "greenzoneveh", true)
						end

						addEventHandler("onElementDestroy", c,
							function()
								if z[source] then
									z[source] = nil
								end
							end
						)

						addEventHandler("onColShapeHit", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "player" then
									if getElementData(h, "colShapeFix_OUT") then
										setElementData(h, "colShapeFix_OUT", false)
										return
									end

									-- Hack to prevent shooting bug: if player teleports from one greenzone directly to another and fails to clean up (on time)
									if getElementData(h, "greenzone") then
										setElementData(h, "colShapeFix_IN", true)
										triggerClientEvent(h, "onEnterGreenzone", h)
									else
										setElementData(h, "greenzone", true)
										toggleControl(h, "fire", false)
										toggleControl(h, "aim_weapon", false)
										toggleControl(h, "vehicle_fire", false)
										toggleControl(h, "vehicle_secondary_fire", false)
										setVehicleDamageProof(h, false)
										outputChatBox("Você esta na area verde", h, 0, 220, 0)
										triggerClientEvent(h, "onEnterGreenzone", h)
																				
									end
								end
							end
						)

						addEventHandler("onColShapeHit", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "vehicle" then
									setElementData(h, "greenzoneveh", true)
								end
							end
						)

						addEventHandler("onColShapeLeave", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "player" then
									if getElementData(h, "colShapeFix_IN") then
										setElementData(h, "colShapeFix_IN", false)
										return
									end

									if getElementData(h, "greenzone") then
										setElementData(h, "greenzone", false)
										toggleControl(h, "fire", true)
										toggleControl(h, "aim_weapon", true)
										toggleControl(h, "vehicle_fire", true)
										toggleControl(h, "vehicle_secondary_fire", true)
										setVehicleDamageProof(h, true)
										outputChatBox("[AREA] Você saiu da area verde", h, 220, 220, 0)
										triggerClientEvent(h, "onLeaveGreenzone", h)
									else
										setElementData(h, "colShapeFix_OUT", true)
									end
								end
							end
						)

						addEventHandler("onColShapeLeave", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "vehicle" then
									setTimer(setElementData, 350, 1, h, "greenzoneveh", false)
								end
							end
						)

					end
				end
			end
		end
	end
end
addEventHandler("onResourceStart", resourceRoot, initGreenzones)

function resetGreenzoneData()
	for _, p in ipairs(getElementsByType("player")) do
		if isElement(p) then
			removeElementData(p, "greenzone")
		end
	end
end
addEventHandler("onResourceStop", resourceRoot, resetGreenzoneData)

 

 

Edited by #RooTs
  • Sad 1
Link to comment
13 minutes ago, #RooTs said:

amigo agente não costuma fazer isso.. mais eu estava com o meu editor aberto aqui e resolvi adiciona-lo para você

e aproveitando a função que o @Lord Henry deixou aqui resolvi fazer, veja se resolve o seu problema.
só não esquece de clicar ali, e deixar um THANKS.

Server.Lua

  Hide contents


 -- Format is: {x = 0, y = 0, z = 0, width = 0, depth = 0, height = 0},local greenzones = {	{x = 2441.173, y = -1721.99, z = 1 , width = 130, depth = 120, height = 100}, -- Grove Street	{x = 304.336, y = -1836.197, z = 1 , width = 130, depth = 120, height = 100}, -- Praia Los Santos	{x = 1154.833, y = -1385.175, z = 1 , width = 70, depth = 100, height = 115}, -- Los Santos Hospital}-- Initialize all zones on resource startlocal z = {}function initGreenzones()	if greenzones and #greenzones ~= 0 then		for _, v in ipairs(greenzones) do			if v then				if v.x and v.y and v.z and v.width and v.depth and v.height then					local c = createColCuboid(v.x, v.y, v.z, v.width, v.depth, v.height)					local rarea = createRadarArea(v.x, v.y, v.width, v.depth, 0, 255, 0, 150)					setElementParent(rarea, c)					if c then						z[c] = true						for _, p in ipairs(getElementsWithinColShape(c, "player")) do							setElementData(p, "greenzone", true)						end						for _, v in ipairs(getElementsWithinColShape(c, "vehicle")) do							setElementData(v, "greenzoneveh", true)						end						addEventHandler("onElementDestroy", c,							function()								if z[source] then									z[source] = nil								end							end						)						addEventHandler("onColShapeHit", c,							function(h)								if h and isElement(h) and getElementType(h) == "player" then									if getElementData(h, "colShapeFix_OUT") then										setElementData(h, "colShapeFix_OUT", false)										return									end									-- Hack to prevent shooting bug: if player teleports from one greenzone directly to another and fails to clean up (on time)									if getElementData(h, "greenzone") then										setElementData(h, "colShapeFix_IN", true)										triggerClientEvent(h, "onEnterGreenzone", h)									else										setElementData(h, "greenzone", true)										toggleControl(h, "fire", false)										toggleControl(h, "aim_weapon", false)										toggleControl(h, "vehicle_fire", false)										toggleControl(h, "vehicle_secondary_fire", false)										setVehicleDamageProof(h, false)										outputChatBox("Você esta na area verde", h, 0, 220, 0)										triggerClientEvent(h, "onEnterGreenzone", h)																													end								end							end						)						addEventHandler("onColShapeHit", c,							function(h)								if h and isElement(h) and getElementType(h) == "vehicle" then									setElementData(h, "greenzoneveh", true)								end							end						)						addEventHandler("onColShapeLeave", c,							function(h)								if h and isElement(h) and getElementType(h) == "player" then									if getElementData(h, "colShapeFix_IN") then										setElementData(h, "colShapeFix_IN", false)										return									end									if getElementData(h, "greenzone") then										setElementData(h, "greenzone", false)										toggleControl(h, "fire", true)										toggleControl(h, "aim_weapon", true)										toggleControl(h, "vehicle_fire", true)										toggleControl(h, "vehicle_secondary_fire", true)										setVehicleDamageProof(h, true)										outputChatBox("[AREA] Você saiu da area verde", h, 220, 220, 0)										triggerClientEvent(h, "onLeaveGreenzone", h)									else										setElementData(h, "colShapeFix_OUT", true)									end								end							end						)						addEventHandler("onColShapeLeave", c,							function(h)								if h and isElement(h) and getElementType(h) == "vehicle" then									setTimer(setElementData, 350, 1, h, "greenzoneveh", false)								end							end						)					end				end			end		end	endendaddEventHandler("onResourceStart", resourceRoot, initGreenzones)function resetGreenzoneData()	for _, p in ipairs(getElementsByType("player")) do		if isElement(p) then			removeElementData(p, "greenzone")		end	endendaddEventHandler("onResourceStop", resourceRoot, resetGreenzoneData)

 

 

Os jogadores ainda conseguem explodir o veiculo dentro da area verde :( atirando por fora dela tristin mais obrigado por tentar me ajudar

Edited by SkillZNT
Link to comment
Just now, SkillZNT said:

Os jogadores ainda conseguem explodir o veiculo dentro da area verde :( atirando por fora dela tristin mais obrigado por tentar me ajudar

testa de novo

Server.Lua

Spoiler

-- Format is: {x = 0, y = 0, z = 0, width = 0, depth = 0, height = 0},
local greenzones = {
	{x = 2441.173, y = -1721.99, z = 1 , width = 130, depth = 120, height = 100}, -- Grove Street
	{x = 304.336, y = -1836.197, z = 1 , width = 130, depth = 120, height = 100}, -- Praia Los Santos
	{x = 1154.833, y = -1385.175, z = 1 , width = 70, depth = 100, height = 115}, -- Los Santos Hospital
}

-- Initialize all zones on resource start
local z = {}
function initGreenzones()
	if greenzones and #greenzones ~= 0 then
		for _, v in ipairs(greenzones) do
			if v then
				if v.x and v.y and v.z and v.width and v.depth and v.height then
					local c = createColCuboid(v.x, v.y, v.z, v.width, v.depth, v.height)
					local rarea = createRadarArea(v.x, v.y, v.width, v.depth, 0, 255, 0, 150)
					setElementParent(rarea, c)
					if c then
						z[c] = true

						for _, p in ipairs(getElementsWithinColShape(c, "player")) do
							setElementData(p, "greenzone", true)
						end

						for _, v in ipairs(getElementsWithinColShape(c, "vehicle")) do
							setElementData(v, "greenzoneveh", true)
						end

						addEventHandler("onElementDestroy", c,
							function()
								if z[source] then
									z[source] = nil
								end
							end
						)

						addEventHandler("onColShapeHit", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "player" then
									if getElementData(h, "colShapeFix_OUT") then
										setElementData(h, "colShapeFix_OUT", false)
										return
									end

									-- Hack to prevent shooting bug: if player teleports from one greenzone directly to another and fails to clean up (on time)
									if getElementData(h, "greenzone") then
										setElementData(h, "colShapeFix_IN", true)
										triggerClientEvent(h, "onEnterGreenzone", h)
									else
										setElementData(h, "greenzone", true)
										toggleControl(h, "fire", false)
										toggleControl(h, "aim_weapon", false)
										toggleControl(h, "vehicle_fire", false)
										toggleControl(h, "vehicle_secondary_fire", false)
										setVehicleDamageProof(getPedOccupiedVehicle(h), false)
										outputChatBox("Você esta na area verde", h, 0, 220, 0)
										triggerClientEvent(h, "onEnterGreenzone", h)
																				
									end
								end
							end
						)

						addEventHandler("onColShapeHit", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "vehicle" then
									setElementData(h, "greenzoneveh", true)
								end
							end
						)

						addEventHandler("onColShapeLeave", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "player" then
									if getElementData(h, "colShapeFix_IN") then
										setElementData(h, "colShapeFix_IN", false)
										return
									end

									if getElementData(h, "greenzone") then
										setElementData(h, "greenzone", false)
										toggleControl(h, "fire", true)
										toggleControl(h, "aim_weapon", true)
										toggleControl(h, "vehicle_fire", true)
										toggleControl(h, "vehicle_secondary_fire", true)
										setVehicleDamageProof(getPedOccupiedVehicle(h), true)
										outputChatBox("[AREA] Você saiu da area verde", h, 220, 220, 0)
										triggerClientEvent(h, "onLeaveGreenzone", h)
									else
										setElementData(h, "colShapeFix_OUT", true)
									end
								end
							end
						)

						addEventHandler("onColShapeLeave", c,
							function(h)
								if h and isElement(h) and getElementType(h) == "vehicle" then
									setTimer(setElementData, 350, 1, h, "greenzoneveh", false)
								end
							end
						)

					end
				end
			end
		end
	end
end
addEventHandler("onResourceStart", resourceRoot, initGreenzones)

function resetGreenzoneData()
	for _, p in ipairs(getElementsByType("player")) do
		if isElement(p) then
			removeElementData(p, "greenzone")
		end
	end
end
addEventHandler("onResourceStop", resourceRoot, resetGreenzoneData)

 

 

Edited by #RooTs
  • Sad 1
Link to comment

Teste : (Fiz pequenas alterações).

 
-- Format is: {x = 0, y = 0, z = 0, width = 0, depth = 0, height = 0},
local greenzones = {
	{x = 2441.173, y = -1721.99, z = 1 , width = 130, depth = 120, height = 100}, -- Grove Street
	{x = 304.336, y = -1836.197, z = 1 , width = 130, depth = 120, height = 100}, -- Praia Los Santos
	{x = 1154.833, y = -1385.175, z = 1 , width = 70, depth = 100, height = 115}, -- Los Santos Hospital
}

-- Initialize all zones on resource start
local z = {}
function initGreenzones()
	if greenzones and #greenzones ~= 0 then
		for _, v in ipairs(greenzones) do
			if v then
				if v.x and v.y and v.z and v.width and v.depth and v.height then
					local c = createColCuboid(v.x, v.y, v.z, v.width, v.depth, v.height)
					local rarea = createRadarArea(v.x, v.y, v.width, v.depth, 0, 255, 0, 150)
					setElementParent(rarea, c)
					if c then
						z[c] = true
						for _, p in ipairs(getElementsWithinColShape(c, "player")) do
							setElementData(p, "greenzone", true)
						end
						for _, v in ipairs(getElementsWithinColShape(c, "vehicle")) do
							setElementData(v, "greenzoneveh", true)
						end
						addEventHandler("onElementDestroy", c,
							function()
								if z[source] then
									z[source] = nil
								end
							end
						)
						
						--/> Entrar na Área
						addEventHandler("onColShapeHit", c,
							function(h)
								if isElement(h) and getElementType(h) == "player" then
									if getElementData(h, "colShapeFix_OUT") then
										setElementData(h, "colShapeFix_OUT", false)
										return
									end
									-- Hack to prevent shooting bug: if player teleports from one greenzone directly to another and fails to clean up (on time)
									if getElementData(h, "greenzone") then
										setElementData(h, "colShapeFix_IN", true)
										triggerClientEvent(h, "onEnterGreenzone", h)
									else
										setElementData(h, "greenzone", true)
										toggleControl(h, "fire", false)
										toggleControl(h, "aim_weapon", false)
										toggleControl(h, "vehicle_fire", false)
										toggleControl(h, "vehicle_secondary_fire", false)
										outputChatBox("Você esta na area verde", h, 0, 220, 0)
										triggerClientEvent(h, "onEnterGreenzone", h)
																				
									end
								end
								if isElement(h) and getElementType(h) == "vehicle" then
								   setElementData(h, "greenzoneveh", true)
								   setVehicleDamageProof(h, true)
								end
							end
						)

                        --/> Sair da Área 
						addEventHandler("onColShapeLeave", c,
							function(h)
								if isElement(h) and getElementType(h) == "player" then
									if getElementData(h, "colShapeFix_IN") then
										setElementData(h, "colShapeFix_IN", false)
										return
									end
									if getElementData(h, "greenzone") then
										setElementData(h, "greenzone", false)
										toggleControl(h, "fire", true)
										toggleControl(h, "aim_weapon", true)
										toggleControl(h, "vehicle_fire", true)
										toggleControl(h, "vehicle_secondary_fire", true)
										outputChatBox("[AREA] Você saiu da area verde", h, 220, 220, 0)
										triggerClientEvent(h, "onLeaveGreenzone", h)
									else
										setElementData(h, "colShapeFix_OUT", true)
									end
								end
								if isElement(h) and getElementType(h) == "vehicle" then
									setTimer(setElementData, 350, 1, h, "greenzoneveh", false)
									setVehicleDamageProof(h, false)
								end
							end
						)
					end
				end
			end
		end
	end
end
addEventHandler("onResourceStart", resourceRoot, initGreenzones)


function resetGreenzoneData()
	for _, p in ipairs(getElementsByType("player")) do
		if isElement(p) then
			removeElementData(p, "greenzone")
		end
	end
end
addEventHandler("onResourceStop", resourceRoot, resetGreenzoneData)

 

Link to comment
5 minutes ago, #RooTs said:

putssss... eu não percebi essa IF


if isElement(h) and getElementType(h) == "vehicle" then

que falta de atenção da minha parte... desculpe
@Angelo Pereira to voltando na ativa agora, depois de 3 anos mais ou menos.. acabei esquecendo de muita coisa

ah... faz parte Rsss

Não era esse o problema do veiculo indestrutivel, você colocou true quando sai da área, e false quando entrar, era somente isso mesmo.

Sem problemas hehe, faz parte, já já você aquece e volta no ritmo, e bem vindo novamente, agora +1 pra ajudar o pessoal hehe

Edited by Angelo Pereira
  • Thanks 1
Link to comment
1 minute ago, Angelo Pereira said:

Não era esse o problema do veiculo indestrutivel, você colocou true quando sai da área, e false quando entrar, era somente isso mesmo.

Sem problemas hehe, faz parte

Obrigado kk foii

9 minutes ago, #RooTs said:

putssss... eu não percebi essa IF


if isElement(h) and getElementType(h) == "vehicle" then

que falta de atenção da minha parte... desculpe
@Angelo Pereira to voltando na ativa agora, depois de 3 anos mais ou menos.. acabei esquecendo de muita coisa

ah... faz parte Rsss

Obrigado por me ajudar tbm foii ah quase esqueci thanks haha resolveram um problema mt pertubador

Link to comment
  • Other Languages Moderators

Fiz um básico aqui pra vc testar.

Server-side:

local greenzones = {
    {2441.173, -1721.99, 1, 130, 120, 100}, -- Grove Street
    {304.336, -1836.197, 1, 130, 120, 100}, -- Praia Los Santos
    {1154.833, -1385.175, 1, 70, 100, 115}, -- Los Santos Hospital
}

local colShapes = {}

addEventHandler ("onResourceStart", resourceRoot, function ()
    for i, v in ipairs (greenzones) do
        colShapes[i] = createColCuboid (v[1], v[2], v[3], v[4], v[5], v[6])
        createRadarArea (v[1], v[2], v[4], v[5], 0, 255, 0, 150)
        addEventHandler ("onColShapeHit", colShapes[i], function (hitElement)
            if (getElementType (hitElement) == "player") then
                setElementData (hitElement, "greenzone", true)
                outputChatBox ("Você está protegido na zona verde.", hitElement)
            elseif (getElementType (hitElement) == "vehicle") then
                setVehicleDamageProof (hitElement, true)
            end
        end)
        addEventHandler ("onColShapeLeave", colShapes[i], function (leaveElement)
            if (getElementType (leaveElement) == "player") then
                setElementData (leaveElement, "greenzone", false)
                outputChatBox ("Você não está mais protegido.", leaveElement)
            elseif (getElementType (leaveElement) == "vehicle") then
                setVehicleDamageProof (leaveElement, false)
            end
        end)
    end
end)

Client-side: (copiei o seu e arrumei a última função)

-- Protect greenzone'd players from getting attacked etcetera
function onDamage()
	if getElementData(source, "greenzone") then
		cancelEvent()
	end
end
addEventHandler("onClientPlayerDamage", localPlayer, onDamage)

-- Prevent people from being knifed while in greenzone
function onStealthKill(target)
	if getElementData(target, "greenzone") then
		cancelEvent()
	end
end
addEventHandler("onClientPlayerStealthKill", localPlayer, onStealthKill)

-- Render the "Greenzone protected" text above their heads
function renderGreenzoneTag()
	local streamedPlayers = getElementsByType("player", root, true)
	if streamedPlayers and #streamedPlayers ~= 0 then
		local lpos = {getElementPosition(localPlayer)}
		for _, p in ipairs(streamedPlayers) do
			if p and isElement(p) then
				if getElementData(p, "greenzone") then
					local ppos = {getElementPosition(p)}
					if getDistanceBetweenPoints3D(lpos[1], lpos[2], lpos[3], ppos[1], ppos[2], ppos[3]) <= 20 then
						local x, y = getScreenFromWorldPosition(ppos[1], ppos[2], ppos[3] + 1.2)
						if x and y then
							dxDrawText("Voce esta protegido", x + 1, y + 1, x, y, tocolor(0, 0, 0), 0.5, "bankgothic", "center")
							dxDrawText("Voce esta protegido", x, y, x, y, tocolor(0, 220, 0), 0.5, "bankgothic", "center")
						end
					end
				end
			end
		end
	end
end
addEventHandler("onClientRender", root, renderGreenzoneTag)

-- The next 4 functions are for ghostmode (vehicles ramming greenzone'd players on foot, lifting them off, etcetera)
-- This protection is important; they usually try to forklift you out of greenzone, spawn a vehicle on you and catch you inside/annoy-ram you, then TP off to a clear zone to kill you, etcetera.
function onStreamIn()
	if not getElementData(localPlayer, "greenzone") then
		return
	end
	if getElementType(source) == "vehicle" then
		setElementCollidableWith(localPlayer, source, false)
	end
end
addEventHandler("onClientElementStreamIn", root, onStreamIn)

function cleanUp()
	if not getElementData(source, "greenzoneveh") then
		return
	end
	if getElementType(source) == "vehicle" and isElementCollidableWith(localPlayer, source) == false then
		setElementCollidableWith(localPlayer, source, true)
	end
end
addEventHandler("onClientElementStreamOut", resourceRoot, cleanUp)

function enterGreenzone()
	local x, y, z = getElementPosition(localPlayer)
	local nearbyVehicles = getElementsWithinRange(x, y, z, 300, "vehicle")

	for i, v in ipairs(nearbyVehicles) do
		setElementCollidableWith(localPlayer, v, false)
	end
end
addEvent("onEnterGreenzone", true)
addEventHandler("onEnterGreenzone", localPlayer, enterGreenzone)

function leaveGreenzone(p)
	local x, y, z = getElementPosition(localPlayer)
	local nearbyVehicles = getElementsWithinRange(x, y, z, 300, "vehicle")

	for i, v in ipairs(nearbyVehicles) do
		setElementCollidableWith(localPlayer, v, true)
	end
end
addEvent("onLeaveGreenzone", true)
addEventHandler("onLeaveGreenzone", localPlayer, leaveGreenzone)

-- This 'bug' is not expected to happen without some sort of interference, but is a generic safeguard.
-- If player exits the greenzone after incidentally having the bugfix applied to them, all controls will be automatically re-enabled anyways (that mechanism is in serverside).
function antiGreenzoneBug()
	if getElementData(localPlayer, "greenzone") then
		setPedWeaponSlot (localPlayer, 0)
		toggleControl("fire", false)
		toggleControl("action", false)
		toggleControl("aim_weapon", false)
		toggleControl("vehicle_fire", false)
		toggleControl("vehicle_secondary_fire", false)
	end
end
addEventHandler("onClientPlayerWeaponFire", localPlayer, antiGreenzoneBug)

 

  • Like 1
Link to comment
4 hours ago, Angelo Pereira said:

Não era esse o problema do veiculo indestrutivel, você colocou true quando sai da área, e false quando entrar, era somente isso mesmo.

Sem problemas hehe, faz parte, já já você aquece e volta no ritmo, e bem vindo novamente, agora +1 pra ajudar o pessoal hehe

Obrigado man ?

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