Jump to content

Safe Zone.


Recommended Posts

Bonjour a tous,

Je fais ce poste afin d'essayer de comprendre le fonctionnement de la Safe Zone (Green Zone).

J'ai trouvé une ressource sur la communauté, puis par ailleurs j'ai voulu modifié la position de ce rectangle vert, pour pouvoir le mettre au spawn que j'ai modifié, après plusieurs essaie, je n'arrive toujours pas a comprendre, comment relever la position d'un rectangle parfait, convenant a mon spawn (Grandeur, largeur, longueur, profondeur).

Voici le code que j'ai trouvé:

Server:

-- By default it adds greenzone to the Freeroam/play standard spawnpoints to prevent spawnkills, you can add greenzone areas to it using the coordinate format 
-- Format is: {x = 0, y = 0, z = 0, width = 0, depth = 0, height = 0}, 
local greenzones = { 
    {x = 1611.72229 , y = -1721.5144, z = 15, width = 20, depth = 15, height = 30}, -- New spawn 
} 
  
-- 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) 
                                    outputChatBox ("* Greenzone * You have entered the greenzone", h, 0, 220, 0) 
                                end 
                            end 
                        ) 
                        addEventHandler ("onColShapeLeave", c, 
                            function (h, d) 
                                if h and d and isElement(h) and getElementType (h) == "player" then 
                                    removeElementData (h, "greenzone") 
                                    outputChatBox ("* Greenzone * You have left the greenzone", h, 220, 220, 0) 
                                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) 

Client:

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) 

J'ai relever la position x et y de mon rectangle en les prenants sur les largue puis longueur, mais visiblement cela n'a pas fonctionné, puis ça m'a ensuite spawn un mini rectangle a côté de mes positions choisit.

Si une personne pourras d'avantage prendre son temps pour m'expliqué ceci, j'en serai très reconnaissant.

Merci d'avance.

Link to comment
  • Moderators

Chaque zone est définit comme suit:

{x = 1611, y = -1721, z = 15, width = 20, depth = 15, height = 30}, 

x: La position x de l'angle sud-ouest de la zone

y: La position y de l'angle sud-ouest de la zone

z: La position z du sol de la zone

width: La largeur de la zone

depth: La profondeur de la zone

height: La hauteur de la zone

Pour remplir ces champs, il faut que tu prennes 2 positions (x, y, z) sur ta map qui vont correspondre aux 2 angles opposés de ta zone:

976ae109b6f0745ba8d366086dae4cf5.png

Les calculs à faire:

x = x1

y = y1

z = z1

width = x2-x1

depth = y2-y1

height = z2-y2

Remarque: Comme tu prendras les positions au sol, z2 sera égal ou très proche de z1 il faudra que tu donnes une hauteur toi même. 20 me paraît une bonne valeur pour commencer.

Cordialement,

Citizen

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