Jump to content

damage proof


Recommended Posts

hi guys i used this safe area to stop poeple killing each other in an event

and the the event is to killing a bot "slothbot" and the bot must kill us not to killing each other but now the bot can kill us now

so i want to cancel the damage only from the players 

 

-- Format is: {x = 0, y = 0, z = 0, width = 0, depth = 0, height = 0},
local greenzones = {
    {x = 1587.58, y = -1150.29, z = 0, width = 116, depth = 139, height = 46}, --boss ls
    {x = 1987.69, y = 1503.08, z = 8, width = 40, depth = 70, height = 25}, 
    {x = -727.38, y = 930.76, z = 11, width = 60, depth = 60, height = 25}, -- Wooden house thing
    {x = -2420, y = -626.2, z = 125, width = 60, depth = 60, height = 30}, -- San Fierro antenna thing
}

-- 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
                        addEventHandler ("onElementDestroy", c,
                            function()
                                if z[source] then
                                    z[source] = nil
                                end
                            end
                        )
                        addEventHandler ("onColShapeHit", c,
                            function (h, d)
                                if h and d and isElement(h) and getElementType (h) == "player" then
                                    setElementData (h, "greenzone", true)
                                    
                                end
                            end
                        )
                        addEventHandler ("onColShapeLeave", c,
                            function (h, d)
                                if h and d and isElement(h) and getElementType (h) == "player" then
                                    removeElementData (h, "greenzone")
                                    
                                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)

 

function onPDamage()
    if getElementData (source, "greenzone") then
        cancelEvent()
    end
end
addEventHandler ("onClientPlayerDamage", localPlayer, onPDamage)

function onPSKill(target)
    if getElementData (target, "greenzone") then
        cancelEvent()
    end
end
addEventHandler ("onClientPlayerStealthKill", localPlayer, onPSKill)

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 ("Greenzone protected", x+1, y+1, x, y, tocolor (0, 0, 0), 0.5, "bankgothic", "center")
                            dxDrawText ("Greenzone protected", x, y, x, y, tocolor (0, 220, 0), 0.5, "bankgothic", "center")
                        end
                    end
                end
            end
        end
    end
end
addEventHandler ("onClientRender", root, renderGreenzoneTag)

the second one is the client side

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