Jump to content

Damage Area


Recommended Posts

  • Vinyard changed the title to Damage Area
2 hours ago, Military Guy said:

Yes

You coud do something like this in a client script:

local DAMAGE_AREA = createColPolygon(-1, 4, 5, 8, 9, 4, 5, -2, -1, 4) -- colshape coordinates here

local DAMAGE_DELAY = 3000 -- miliseconds between damage hits

local DAMAGE_AMOUNT = 5 -- health points to lose

local damageTimer

local function takeDamage()
	-- cancel damage timer if dead
	if isPedDead(localPlayer) then
		if isTimer(damageTimer) then
			killTimer(damageTimer)
			damageTimer = nil
		end
		return
	end

	-- take damage (this may kill the player)
	setElementHealth(localPlayer, math.max(0, getElementHealth(localPlayer) - DAMAGE_AMOUNT))
	outputChatBox("Ouch", 255, 56, 56)

	-- you can trigger some visual effects here (if you want)
end

addEventHandler( "onClientColShapeHit", DAMAGE_AREA, 
function (theElement, matchingDimension)
	if (theElement ~= localPlayer) then return end
	if not (matchingDimension) then return end

	-- take damage instantly (if you want)
	takeDamage()

	-- set damage timer
	damageTimer = setTimer(takeDamage, DAMAGE_DELAY, 0)
end)

addEventHandler( "onClientColShapeLeave", DAMAGE_AREA, 
function (theElement, matchingDimension)
	if (theElement ~= localPlayer) then return end
	if not (matchingDimension) then return end

	-- cancel damage timer
	if isTimer(damageTimer) then
		killTimer(damageTimer)
		damageTimer = nil
	end
end)
Edited by FernandoMTA
  • Like 1
  • Thanks 1
Link to comment
2 hours ago, FernandoMTA said:

You coud do something like this in a client script:

local DAMAGE_AREA = createColPolygon(-1, 4, 5, 8, 9, 4, 5, -2, -1, 4) -- colshape coordinates here

local DAMAGE_DELAY = 3000 -- miliseconds between damage hits

local DAMAGE_AMOUNT = 5 -- health points to lose

local damageTimer

local function takeDamage()
	-- cancel damage timer if dead
	if isPedDead(localPlayer) then
		if isTimer(damageTimer) then
			killTimer(damageTimer)
			damageTimer = nil
		end
		return
	end

	-- take damage (this may kill the player)
	setElementHealth(localPlayer, math.max(0, getElementHealth(localPlayer) - DAMAGE_AMOUNT))
	outputChatBox("Ouch", 255, 56, 56)

	-- you can trigger some visual effects here (if you want)
end

addEventHandler( "onClientColShapeHit", DAMAGE_AREA, 
function (theElement, matchingDimension)
	if (theElement ~= localPlayer) then return end
	if not (matchingDimension) then return end

	-- take damage instantly (if you want)
	takeDamage()

	-- set damage timer
	damageTimer = setTimer(takeDamage, DAMAGE_DELAY, 0)
end)

addEventHandler( "onClientColShapeLeave", DAMAGE_AREA, 
function (theElement, matchingDimension)
	if (theElement ~= localPlayer) then return end
	if not (matchingDimension) then return end

	-- cancel damage timer
	if isTimer(damageTimer) then
		killTimer(damageTimer)
		damageTimer = nil
	end
end)

THX!

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