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)