Jump to content

Vehicle keep hp in zone


Quenix

Recommended Posts

So i have a proection script for bases, i want the vehicles that are inside this zone will keep the HP they had when they first came in, so people wont throw nades or shoot the vehicles outside the zone.

 

I take no credits for the script as it is not mine!

Server 

--- Definire Poligon (phy)
function createZone(thePlayer, theCMD, accType, ...)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
        local clanFile = xmlLoadFile("security.xml")
        if not clanFile then
            outputChatBox("Sistemul nu a putut fi activat!", thePlayer, 255, 0, 0)
            return
        end
        local accRuleTable = {...}
        local accRule = table.concat(accRuleTable, " ")
        if tonumber(accType) == 1 then
            outputChatBox("Tipul de acces a fost setat la _Cont pentru "..tostring(accRule), thePlayer, 255, 155, 0, false)
        elseif tonumber(accType) == 2 then
            outputChatBox("Tipul de acces a fost setat la _Clan pentru "..tostring(accRule), thePlayer, 255, 155, 0, false)
        elseif tonumber(accType) == 3 then
            outputChatBox("Tipul de acces a fost setat la _Grup ACL pentru "..tostring(accRule), thePlayer, 255, 155, 0, false)
        elseif tonumber(accType) == 4 then
            outputChatBox("Tipul de acces a fost setat la _Zona Sigura!", thePlayer, 255, 155, 0, false)
        else
            outputChatBox("Tipul de acces este invalid!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Cont | 2 - Clan | 3 - Grup ACL | 4 - Zona Sigura", thePlayer, 255, 155, 0)
            return
        end
        if accRule == nil then
            outputChatBox("Regula de acces este gresita!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Jucator | 2 - Clan | 3 - Grup ACL | 4 - Zona Sigura", thePlayer, 255, 155, 0)
            return
        end
        local findClan = xmlFindChild(clanFile, "id", 0)
        local id = xmlNodeGetValue(findClan)
        local thisClan = xmlCreateChild (clanFile, "clan")
        local x, y, z = getElementPosition(thePlayer)
        --- Colt 1
        local x1 = getElementData(thePlayer, "x1") or false
        local y1 = getElementData(thePlayer, "y1") or false
        --- Colt 2
        local x2 = getElementData(thePlayer, "x2") or false
        local y2 = getElementData(thePlayer, "y2") or false
        --- Colt 3
        local x3 = getElementData(thePlayer, "x3") or false
        local y3 = getElementData(thePlayer, "y3") or false
        --- Colt 4
        local x4 = getElementData(thePlayer, "x4") or false
        local y4 = getElementData(thePlayer, "y4") or false
        --- Validarea Datelor [x1, y1, z1]
        if x1 == false and y1 == false then
            outputChatBox("Coltul #1 nu a fost setat!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Jucator | 2 - Clan | 3 - Grup ACL", thePlayer, 255, 155, 0)
            return
        end
        --- Validarea Datelor [x2, y2, z2]
        if x2 == false and y2 ~= false then
            outputChatBox("Coltul #2 nu a fost setat!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Jucator | 2 - Clan | 3 - Grup ACL", thePlayer, 255, 155, 0)
            return
        end
        --- Validarea Datelor [x3, y3, z3]
        if x3 == false and y3 == false then
            outputChatBox("Coltul #3 nu a fost setat!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Jucator | 2 - Clan | 3 - Grup ACL", thePlayer, 255, 155, 0)
            return
        end
        --- Validarea Datelor [x4, y4, z4]
        if x4 == false and y4 == false then
            outputChatBox("Coltul #4 nu a fost setat!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Jucator | 2 - Clan | 3 - Grup ACL", thePlayer, 255, 155, 0)
            return
        end
        xmlNodeSetAttribute (thisClan, "id", tonumber(id) + 1)
        --- Pozitia unde va fi dat afara!
        xmlNodeSetAttribute (thisClan, "x", x)
        xmlNodeSetAttribute (thisClan, "y", y)
        xmlNodeSetAttribute (thisClan, "z", z)
        --- Coltul 1
        xmlNodeSetAttribute (thisClan, "xa", x1)
        xmlNodeSetAttribute (thisClan, "ya", y1)
        --- Coltul 2
        xmlNodeSetAttribute (thisClan, "xb", x2)
        xmlNodeSetAttribute (thisClan, "yb", y2)
        --- Coltul 3
        xmlNodeSetAttribute (thisClan, "xc", x3)
        xmlNodeSetAttribute (thisClan, "yc", y3)
        --- Coltul 4
        xmlNodeSetAttribute (thisClan, "xd", x4)
        xmlNodeSetAttribute (thisClan, "yd", y4)
        --- Configurare
        xmlNodeSetAttribute (thisClan, "accType", accType)
        xmlNodeSetAttribute (thisClan, "accRule", accRule)
        local clanId = tostring(tonumber(id) + 1)
        xmlNodeSetValue (findClan, clanId)
        xmlSaveFile(clanFile)   
        xmlUnloadFile(clanFile)
        local clanProtection = createColPolygon(x, y, tonumber(x1), tonumber(y1), tonumber(x2), tonumber(y2), tonumber(x3), tonumber(y3), tonumber(x4), tonumber(y4))
        setElementData(clanProtection, "accId", clanId)
        setElementData(clanProtection, "accType", accType)
        setElementData(clanProtection, "accRule", accRule)
        setElementData(clanProtection, "exportX", x)
        setElementData(clanProtection, "exportY", y)
        setElementData(clanProtection, "exportZ", z)
        reloadClans()
    end
end
addCommandHandler("makepoly", createZone)

--- Creare Poligon
function createPoligonalCorners(thePlayer, theCMD, theNode)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
        local id = tonumber(theNode)
        if id == 1 then
            local x, y, z = getElementPosition(thePlayer)
            setElementData(thePlayer, "x"..id, x)
            setElementData(thePlayer, "y"..id, y)
            outputChatBox("The corner #"..id.." was created!", thePlayer, 255, 155, 0)
        elseif id == 2 then
            local x, y, z = getElementPosition(thePlayer)
            setElementData(thePlayer, "x"..id, x)
            setElementData(thePlayer, "y"..id, y)
            outputChatBox("The corner #"..id.." was created!", thePlayer, 255, 155, 0)
        elseif id == 3 then
            local x, y, z = getElementPosition(thePlayer)
            setElementData(thePlayer, "x"..id, x)
            setElementData(thePlayer, "y"..id, y)
            outputChatBox("The corner #"..id.." was created!", thePlayer, 255, 155, 0)
        elseif id == 4 then
            local x, y, z = getElementPosition(thePlayer)
            setElementData(thePlayer, "x"..id, x)
            setElementData(thePlayer, "y"..id, y)
            outputChatBox("The corner #"..id.." was created!", thePlayer, 255, 155, 0)
        else
            outputChatBox("The polygon can have up to 4 corners!", thePlayer, 255, 0, 0)
        end
    end
end
addCommandHandler("polynode", createPoligonalCorners, false)

--- Resetare Poligon
function resetPoligonalCorners(thePlayer)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
        setElementData(thePlayer, "x1", false)
        setElementData(thePlayer, "y1", false)
        setElementData(thePlayer, "x2", false)
        setElementData(thePlayer, "y2", false)
        setElementData(thePlayer, "x3", false)
        setElementData(thePlayer, "y3", false)
        setElementData(thePlayer, "x4", false)
        setElementData(thePlayer, "y4", false)
        outputChatBox("Colturile poligonale au fost resetate!", thePlayer, 255, 155, 0)
    end
end
addCommandHandler("resetpoly", resetPoligonalCorners, false)

--- Re-configurare Poligon
function rebuildZoneAccess(thePlayer, theCMD, theZoneId, newAccType, ...)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
        local clanFile = xmlLoadFile("security.xml")
        local findZone = xmlFindChild(clanFile, "clan", tonumber(theZoneId) - 1)
        local accRuleTable = {...}
        local newAccRule = table.concat(accRuleTable, " ")
        xmlNodeSetAttribute(findZone, "accType", newAccType)
        xmlNodeSetAttribute(findZone, "accRule", newAccRule)
        xmlSaveFile(clanFile)   
        xmlUnloadFile(clanFile)
        outputChatBox("Accesul zonei cu ID "..theZoneId.." a fost modificat!", thePlayer, 255, 155, 0)
        reloadClans()
    end
end
addCommandHandler("rebuildpoly", rebuildZoneAccess)

-- Functii de Creare/Distrugere
function loadClans()
    local clanFile = xmlLoadFile("security.xml")
    if (clanFile) then
        local clans = xmlNodeGetChildren(clanFile)
        for i,v in ipairs(clans) do
                local clanId = xmlNodeGetAttribute (v, "id")
                local x = xmlNodeGetAttribute (v, "x")
                local y = xmlNodeGetAttribute (v, "y")
                local z = xmlNodeGetAttribute (v, "z")
                local x1 = xmlNodeGetAttribute (v, "xa")
                local y1 = xmlNodeGetAttribute (v, "ya")
                local x2 = xmlNodeGetAttribute (v, "xb")
                local y2 = xmlNodeGetAttribute (v, "yb")
                local x3 = xmlNodeGetAttribute (v, "xc")
                local y3 = xmlNodeGetAttribute (v, "yc")
                local x4 = xmlNodeGetAttribute (v, "xd")
                local y4 = xmlNodeGetAttribute (v, "yd")
                local accType = xmlNodeGetAttribute (v, "accType")
                local accRule = xmlNodeGetAttribute (v, "accRule")
                if x then
                    local clanProtection = createColPolygon(x, y, tonumber(x1), tonumber(y1), tonumber(x2), tonumber(y2), tonumber(x3), tonumber(y3), tonumber(x4), tonumber(y4))
                    setElementData(clanProtection, "accId", clanId)
                    setElementData(clanProtection, "accType", accType)
                    setElementData(clanProtection, "accRule", accRule)
                    setElementData(clanProtection, "exportX", x)
                    setElementData(clanProtection, "exportY", y)
                    setElementData(clanProtection, "exportZ", z)
                end
        end
        xmlUnloadFile(clanFile)
    end
end

-- Destroy Poligon
function destroyClans()
    allClans = getElementsByType("colShape")
    for i,v in ipairs(allClans) do
        if tonumber(getElementData(v, "accType")) == 1 or tonumber(getElementData(v, "accType")) == 2 or tonumber(getElementData(v, "accType")) == 3 or tonumber(getElementData(v, "accType")) == 4 then
            destroyElement(v)
        end
    end
end

-- Reload Poligon
function reloadClans()
    destroyClans()
    loadClans()
end

function preloadClans(thePlayer)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
        destroyClans()
        loadClans()
        outputChatBox("Sistemul de securitate a actualizat zonele de securitate!", thePlayer, 255, 155, 0)
    end
end
addCommandHandler("reloadpoly", preloadClans, false)

-- Secure Polygon
function getSimplestTaskOf(thePlayer)
    getServerPedTask(thePlayer)
    return getElementData(thePlayer, "simplestTask") or "TASK_UNASSIGNED"
end

function getServerPedTask(thePlayer)
    triggerClientEvent(thePlayer, "onServerGetPedSimplestTask", thePlayer)
end

function getServerSimplestTask(theTask)
    setElementData(client, "simplestTask", theTask)
end
addEvent("onSimplestTaskReturned", true)
addEventHandler("onSimplestTaskReturned", resourceRoot, getServerSimplestTask)

function updateTask(thePlayer)
    getServerPedTask(thePlayer)
end
addEventHandler("onVehicleStartEnter", root, updateTask)
addEventHandler("onVehicleStartExit", root, updateTask)
addEventHandler("onVehicleEnter", root, updateTask)
addEventHandler("onVehicleExit", root, updateTask)

function handlePoly(thePlayer)
    local currentPoly = getElementData(source, "accId") or false
    if currentPoly then
        local polyAccType = getElementData(source, "accType")
        local polyAccRule = getElementData(source, "accRule")
        if getElementType(thePlayer) == "player" and isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
            outputChatBox("Because you're an administrator, you will not be affected by zone settings!", thePlayer, 255, 155, 0)
            if tonumber(polyAccType) == 1 then
                outputChatBox("ID: "..currentPoly.." | Acces: "..polyAccRule.." | Tip Acces: Cont", thePlayer, 255, 155, 0)
            elseif tonumber(polyAccType) == 2 then
                outputChatBox("ID: "..currentPoly.." | Acces: "..polyAccRule.." | Tip Acces: Clan", thePlayer, 255, 155, 0)
            elseif tonumber(polyAccType) == 3 then
                outputChatBox("ID: "..currentPoly.." | Acces: "..polyAccRule.." | Tip Acces: Grup ACL", thePlayer, 255, 155, 0)
            elseif tonumber(polyAccType) == 4 then
                outputChatBox("ID: "..currentPoly.." | Acces: --- | Tip Acces: Zona Sigura", thePlayer, 255, 155, 0)
            else
                outputChatBox("ID: "..currentPoly.." | Zona nu este configurata corect!", thePlayer, 255, 0, 0)
            end
        else
            if tonumber(polyAccType) == 1 then
                if getElementType(thePlayer) == "player" and getAccountName(getPlayerAccount(thePlayer)) ~= tostring(polyAccRule) or isGuestAccount(getPlayerAccount(thePlayer)) then
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a incercat sa patrunda intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Cont | Regula de Acces: "..tostring(polyAccRule))
                    local exportX = getElementData(source, "exportX")
                    local exportY = getElementData(source, "exportY")
                    local exportZ = getElementData(source, "exportZ")
                    setTimer(function(thePlayer, theZone) warpOutIfStillIn(thePlayer, theZone) end, 2000, 1, thePlayer, source)
                    if not isPedInVehicle(thePlayer) then
                        setElementPosition(thePlayer, exportX, exportY, exportZ)
                        outputChatBox("Ai fost teleportat deoarece nu esti detinatorul bazei!", thePlayer, 255, 155, 0, true)
                    else
                        if getSimplestTaskOf(thePlayer) == "TASK_SIMPLE_CAR_DRIVE" then
                            if getElementModel(getPedOccupiedVehicle(thePlayer)) == 487 or getElementModel(getPedOccupiedVehicle(thePlayer)) == 497 then
                                local px, py, pz = getElementPosition(thePlayer)
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ + 25)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("Ai fost teleportat deoarece nu esti detinatorul bazei!", thePlayer, 255, 155, 0, true)
                            else
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("Ai fost teleportat deoarece nu esti detinatorul bazei!", thePlayer, 255, 155, 0, true)
                            end
                        else
                            removePedFromVehicle(thePlayer)
                            setElementPosition(thePlayer, exportX, exportY, exportZ)
                            outputChatBox("Ai fost teleportat deoarece nu esti detinatorul bazei!", thePlayer, 255, 155, 0, true)
                        end
                    end
                else
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a intrat intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Cont | Regula de Acces: "..tostring(polyAccRule))
                end
            elseif tonumber(polyAccType) == 2 then
                if tostring(getElementData(thePlayer, "gang")) ~= tostring(polyAccRule) then
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a incercat sa patrunda intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Clan | Regula de Acces: "..tostring(polyAccRule))
                    local exportX = getElementData(source, "exportX")
                    local exportY = getElementData(source, "exportY")
                    local exportZ = getElementData(source, "exportZ")
                    setTimer(function(thePlayer, theZone) warpOutIfStillIn(thePlayer, theZone) end, 2000, 1, thePlayer, source)
                    if not isPedInVehicle(thePlayer) then
                        setElementPosition(thePlayer, exportX, exportY, exportZ)
                        outputChatBox("You were teleported because you do not belong to the clan #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                    else
                        if getSimplestTaskOf(thePlayer) == "TASK_SIMPLE_CAR_DRIVE" then
                            if getElementModel(getPedOccupiedVehicle(thePlayer)) == 487 or getElementModel(getPedOccupiedVehicle(thePlayer)) == 497 then
                                local px, py, pz = getElementPosition(thePlayer)
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ + 25)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("You were teleported because you do not belong to the clan #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                            else
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("You were teleported because you do not belong to the clan #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                            end
                        else
                            removePedFromVehicle(thePlayer)
                            setElementPosition(thePlayer, exportX, exportY, exportZ)
                            outputChatBox("You were teleported because you do not belong to the clan #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                            outputChatBox(getSimplestTaskOf(thePlayer), thePlayer, 255, 155, 0)
                        end
                    end
                else
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a intrat intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Clan | Regula de Acces: "..tostring(polyAccRule))
                end
            elseif tonumber(polyAccType) == 3 then
                if not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup(tostring(polyAccRule))) then
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a incercat sa patrunda intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Grup ACL | Regula de Acces: "..tostring(polyAccRule))
                    local exportX = getElementData(source, "exportX")
                    local exportY = getElementData(source, "exportY")
                    local exportZ = getElementData(source, "exportZ")
                    setTimer(function(thePlayer, theZone) warpOutIfStillIn(thePlayer, theZone) end, 2000, 1, thePlayer, source)
                    if not isPedInVehicle(thePlayer) then
                        setElementPosition(thePlayer, exportX, exportY, exportZ)
                        outputChatBox("Ai fost teleportat deoarece nu apartii grupului #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                    else
                        if getSimplestTaskOf(thePlayer) == "TASK_SIMPLE_CAR_DRIVE" then
                            if getElementModel(getPedOccupiedVehicle(thePlayer)) == 487 or getElementModel(getPedOccupiedVehicle(thePlayer)) == 497 then
                                local px, py, pz = getElementPosition(thePlayer)
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ + 25)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("Ai fost teleportat deoarece nu apartii grupului #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                            else
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("Ai fost teleportat deoarece nu apartii grupului #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                            end
                        else
                            removePedFromVehicle(thePlayer)
                            setElementPosition(thePlayer, exportX, exportY, exportZ)
                            outputChatBox("Ai fost teleportat deoarece nu apartii grupului #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                        end
                    end
                else
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a intrat intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Grup ACL | Regula de Acces: "..tostring(polyAccRule))
                end
            elseif tonumber(polyAccType) == 4 then
                if getElementType(thePlayer) == "player" then 
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a intrat intr-o zona sigura!")
                    outputChatBox("Ai patruns intr-o zona sigura! Armele tale au fost dezactivate temporar!", thePlayer, 255, 155, 0)
                    toggleControl (thePlayer, "fire", false)
                    toggleControl (thePlayer, "next_weapon", false)
                    toggleControl (thePlayer, "previous_weapon", false)
                    toggleControl (thePlayer, "aim_weapon", false)
                    toggleControl (thePlayer, "vehicle_fire", false)
                    setPlayerHudComponentVisible (thePlayer, "ammo", false)
                    setPlayerHudComponentVisible (thePlayer, "weapon", false)
                end
            end
        end
    end
end
addEventHandler("onColShapeHit", resourceRoot, handlePoly)

function resetAntiPvP(thePlayer)
    local accType = getElementData(source, "accType")
    if tonumber(accType) == 4 and getElementType(thePlayer) == "player" then
        outputChatBox("Ai parasit zona sigura! Armele tale au fost re-activate!", thePlayer, 255, 155, 0)
        toggleControl (thePlayer, "fire", true)
        toggleControl (thePlayer, "next_weapon", true)
        toggleControl (thePlayer, "previous_weapon", true)
        toggleControl (thePlayer, "aim_weapon", true)
        toggleControl (thePlayer, "vehicle_fire", true)
        setPlayerHudComponentVisible (thePlayer, "ammo", true)
        setPlayerHudComponentVisible (thePlayer, "weapon", true)
    end
end
addEventHandler("onColShapeLeave", resourceRoot, resetAntiPvP)

function warpOutIfStillIn(thePlayer, theZone)
    if isElement(thePlayer) and isElementWithinColShape(thePlayer, theZone) then
        local exportX = getElementData(theZone, "exportX")
        local exportY = getElementData(theZone, "exportY")
        local exportZ = getElementData(theZone, "exportZ")
        removePedFromVehicle(thePlayer)
        setElementPosition(thePlayer, exportX, exportY, exportZ)
    end
end

 

I know you can enable godmode like this, but how can i use this on the script above?

 

    elseif getElementType ( theElement ) == "vehicle" then 
        SetVehicleGodMode(theElement,true) 
    end 
end 
  
function ExitPlace ( theElement ) 
    if getElementType ( theElement ) == "vehicle" then 
        SetVehicleGodMode(theElement,false) 
    end 
end 

 

Link to comment

 

so @JeViCo this is what i did, i added the below script to the Server side script which ive provided aswell, but the godmode enables on every col and not the one around the base, which is the protection polygon, this polygon is called handlepoly i think according to the script is there a way to make only godmode get enabled/disabled on entering/leaving just this colshape that this script is making or has made?

 

 

The vehicle godmode:

function vehicleGodMod(player) 
  if isPedInVehicle ( player ) and getPedOccupiedVehicleSeat( player ) == 0 then 
  vehicle = getPedOccupiedVehicle ( player ) 
  setVehicleDamageProof( vehicle, true )
outputChatBox ( "#FFFFFFVehicle godmode #00FF00enabled", getRootElement(), 255, 0, 0, true )
    end
end
addEventHandler("onColShapeHit", root, vehicleGodMod)

function vehicleGodMod2(player) 
  if isPedInVehicle ( player ) and getPedOccupiedVehicleSeat( player ) == 0 then 
    setVehicleDamageProof( vehicle, false ) 
    outputChatBox ( "Vehicle godmode #FF0004disabled", getRootElement(), 255, 255, 255, true )
    end 
end
addEventHandler("onColShapeLeave", root, vehicleGodMod2)



The serverside script with the car godmode in it which is working but works on all polygons:

--- Definire Poligon (phy)
function createZone(thePlayer, theCMD, accType, ...)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
        local clanFile = xmlLoadFile("security.xml")
        if not clanFile then
            outputChatBox("Sistemul nu a putut fi activat!", thePlayer, 255, 0, 0)
            return
        end
        local accRuleTable = {...}
        local accRule = table.concat(accRuleTable, " ")
        if tonumber(accType) == 1 then
            outputChatBox("Tipul de acces a fost setat la _Cont pentru "..tostring(accRule), thePlayer, 255, 155, 0, false)
        elseif tonumber(accType) == 2 then
            outputChatBox("Tipul de acces a fost setat la _Clan pentru "..tostring(accRule), thePlayer, 255, 155, 0, false)
        elseif tonumber(accType) == 3 then
            outputChatBox("Tipul de acces a fost setat la _Grup ACL pentru "..tostring(accRule), thePlayer, 255, 155, 0, false)
        elseif tonumber(accType) == 4 then
            outputChatBox("Tipul de acces a fost setat la _Zona Sigura!", thePlayer, 255, 155, 0, false)
        else
            outputChatBox("Tipul de acces este invalid!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Cont | 2 - Clan | 3 - Grup ACL | 4 - Zona Sigura", thePlayer, 255, 155, 0)
            return
        end
        if accRule == nil then
            outputChatBox("Regula de acces este gresita!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Jucator | 2 - Clan | 3 - Grup ACL | 4 - Zona Sigura", thePlayer, 255, 155, 0)
            return
        end
        local findClan = xmlFindChild(clanFile, "id", 0)
        local id = xmlNodeGetValue(findClan)
        local thisClan = xmlCreateChild (clanFile, "clan")
        local x, y, z = getElementPosition(thePlayer)
        --- Colt 1
        local x1 = getElementData(thePlayer, "x1") or false
        local y1 = getElementData(thePlayer, "y1") or false
        --- Colt 2
        local x2 = getElementData(thePlayer, "x2") or false
        local y2 = getElementData(thePlayer, "y2") or false
        --- Colt 3
        local x3 = getElementData(thePlayer, "x3") or false
        local y3 = getElementData(thePlayer, "y3") or false
        --- Colt 4
        local x4 = getElementData(thePlayer, "x4") or false
        local y4 = getElementData(thePlayer, "y4") or false
        --- Validarea Datelor [x1, y1, z1]
        if x1 == false and y1 == false then
            outputChatBox("Coltul #1 nu a fost setat!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Jucator | 2 - Clan | 3 - Grup ACL", thePlayer, 255, 155, 0)
            return
        end
        --- Validarea Datelor [x2, y2, z2]
        if x2 == false and y2 ~= false then
            outputChatBox("Coltul #2 nu a fost setat!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Jucator | 2 - Clan | 3 - Grup ACL", thePlayer, 255, 155, 0)
            return
        end
        --- Validarea Datelor [x3, y3, z3]
        if x3 == false and y3 == false then
            outputChatBox("Coltul #3 nu a fost setat!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Jucator | 2 - Clan | 3 - Grup ACL", thePlayer, 255, 155, 0)
            return
        end
        --- Validarea Datelor [x4, y4, z4]
        if x4 == false and y4 == false then
            outputChatBox("Coltul #4 nu a fost setat!", thePlayer, 255, 0, 0)
            outputChatBox("SINTAXA: /makemark [Tip Acces] [Regula Acces]", thePlayer, 255, 155, 0)
            outputChatBox("TIPURI ACCES: 1 - Jucator | 2 - Clan | 3 - Grup ACL", thePlayer, 255, 155, 0)
            return
        end
        xmlNodeSetAttribute (thisClan, "id", tonumber(id) + 1)
        --- Pozitia unde va fi dat afara!
        xmlNodeSetAttribute (thisClan, "x", x)
        xmlNodeSetAttribute (thisClan, "y", y)
        xmlNodeSetAttribute (thisClan, "z", z)
        --- Coltul 1
        xmlNodeSetAttribute (thisClan, "xa", x1)
        xmlNodeSetAttribute (thisClan, "ya", y1)
        --- Coltul 2
        xmlNodeSetAttribute (thisClan, "xb", x2)
        xmlNodeSetAttribute (thisClan, "yb", y2)
        --- Coltul 3
        xmlNodeSetAttribute (thisClan, "xc", x3)
        xmlNodeSetAttribute (thisClan, "yc", y3)
        --- Coltul 4
        xmlNodeSetAttribute (thisClan, "xd", x4)
        xmlNodeSetAttribute (thisClan, "yd", y4)
        --- Configurare
        xmlNodeSetAttribute (thisClan, "accType", accType)
        xmlNodeSetAttribute (thisClan, "accRule", accRule)
        local clanId = tostring(tonumber(id) + 1)
        xmlNodeSetValue (findClan, clanId)
        xmlSaveFile(clanFile)   
        xmlUnloadFile(clanFile)
        local clanProtection = createColPolygon(x, y, tonumber(x1), tonumber(y1), tonumber(x2), tonumber(y2), tonumber(x3), tonumber(y3), tonumber(x4), tonumber(y4))
        setElementData(clanProtection, "accId", clanId)
        setElementData(clanProtection, "accType", accType)
        setElementData(clanProtection, "accRule", accRule)
        setElementData(clanProtection, "exportX", x)
        setElementData(clanProtection, "exportY", y)
        setElementData(clanProtection, "exportZ", z)
        reloadClans()
    end
end
addCommandHandler("makepoly", createZone)

--- Creare Poligon
function createPoligonalCorners(thePlayer, theCMD, theNode)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
        local id = tonumber(theNode)
        if id == 1 then
            local x, y, z = getElementPosition(thePlayer)
            setElementData(thePlayer, "x"..id, x)
            setElementData(thePlayer, "y"..id, y)
            outputChatBox("The corner #"..id.." was created!", thePlayer, 255, 155, 0)
        elseif id == 2 then
            local x, y, z = getElementPosition(thePlayer)
            setElementData(thePlayer, "x"..id, x)
            setElementData(thePlayer, "y"..id, y)
            outputChatBox("The corner #"..id.." was created!", thePlayer, 255, 155, 0)
        elseif id == 3 then
            local x, y, z = getElementPosition(thePlayer)
            setElementData(thePlayer, "x"..id, x)
            setElementData(thePlayer, "y"..id, y)
            outputChatBox("The corner #"..id.." was created!", thePlayer, 255, 155, 0)
        elseif id == 4 then
            local x, y, z = getElementPosition(thePlayer)
            setElementData(thePlayer, "x"..id, x)
            setElementData(thePlayer, "y"..id, y)
            outputChatBox("The corner #"..id.." was created!", thePlayer, 255, 155, 0)
        else
            outputChatBox("The polygon can have up to 4 corners!", thePlayer, 255, 0, 0)
        end
    end
end
addCommandHandler("polynode", createPoligonalCorners, false)

--- Resetare Poligon
function resetPoligonalCorners(thePlayer)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
        setElementData(thePlayer, "x1", false)
        setElementData(thePlayer, "y1", false)
        setElementData(thePlayer, "x2", false)
        setElementData(thePlayer, "y2", false)
        setElementData(thePlayer, "x3", false)
        setElementData(thePlayer, "y3", false)
        setElementData(thePlayer, "x4", false)
        setElementData(thePlayer, "y4", false)
        outputChatBox("Colturile poligonale au fost resetate!", thePlayer, 255, 155, 0)
    end
end
addCommandHandler("resetpoly", resetPoligonalCorners, false)

--- Re-configurare Poligon
function rebuildZoneAccess(thePlayer, theCMD, theZoneId, newAccType, ...)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
        local clanFile = xmlLoadFile("security.xml")
        local findZone = xmlFindChild(clanFile, "clan", tonumber(theZoneId) - 1)
        local accRuleTable = {...}
        local newAccRule = table.concat(accRuleTable, " ")
        xmlNodeSetAttribute(findZone, "accType", newAccType)
        xmlNodeSetAttribute(findZone, "accRule", newAccRule)
        xmlSaveFile(clanFile)   
        xmlUnloadFile(clanFile)
        outputChatBox("Accesul zonei cu ID "..theZoneId.." a fost modificat!", thePlayer, 255, 155, 0)
        reloadClans()
    end
end
addCommandHandler("rebuildpoly", rebuildZoneAccess)

-- Functii de Creare/Distrugere
function loadClans()
    local clanFile = xmlLoadFile("security.xml")
    if (clanFile) then
        local clans = xmlNodeGetChildren(clanFile)
        for i,v in ipairs(clans) do
                local clanId = xmlNodeGetAttribute (v, "id")
                local x = xmlNodeGetAttribute (v, "x")
                local y = xmlNodeGetAttribute (v, "y")
                local z = xmlNodeGetAttribute (v, "z")
                local x1 = xmlNodeGetAttribute (v, "xa")
                local y1 = xmlNodeGetAttribute (v, "ya")
                local x2 = xmlNodeGetAttribute (v, "xb")
                local y2 = xmlNodeGetAttribute (v, "yb")
                local x3 = xmlNodeGetAttribute (v, "xc")
                local y3 = xmlNodeGetAttribute (v, "yc")
                local x4 = xmlNodeGetAttribute (v, "xd")
                local y4 = xmlNodeGetAttribute (v, "yd")
                local accType = xmlNodeGetAttribute (v, "accType")
                local accRule = xmlNodeGetAttribute (v, "accRule")
                if x then
                    local clanProtection = createColPolygon(x, y, tonumber(x1), tonumber(y1), tonumber(x2), tonumber(y2), tonumber(x3), tonumber(y3), tonumber(x4), tonumber(y4))
                    setElementData(clanProtection, "accId", clanId)
                    setElementData(clanProtection, "accType", accType)
                    setElementData(clanProtection, "accRule", accRule)
                    setElementData(clanProtection, "exportX", x)
                    setElementData(clanProtection, "exportY", y)
                    setElementData(clanProtection, "exportZ", z)
                end
        end
        xmlUnloadFile(clanFile)
    end
end

-- Destroy Poligon
function destroyClans()
    allClans = getElementsByType("colShape")
    for i,v in ipairs(allClans) do
        if tonumber(getElementData(v, "accType")) == 1 or tonumber(getElementData(v, "accType")) == 2 or tonumber(getElementData(v, "accType")) == 3 or tonumber(getElementData(v, "accType")) == 4 then
            destroyElement(v)
        end
    end
end

-- Reload Poligon
function reloadClans()
    destroyClans()
    loadClans()
end

function preloadClans(thePlayer)
    if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
        destroyClans()
        loadClans()
        outputChatBox("Sistemul de securitate a actualizat zonele de securitate!", thePlayer, 255, 155, 0)
    end
end
addCommandHandler("reloadpoly", preloadClans, false)

-- Secure Polygon
function getSimplestTaskOf(thePlayer)
    getServerPedTask(thePlayer)
    return getElementData(thePlayer, "simplestTask") or "TASK_UNASSIGNED"
end

function getServerPedTask(thePlayer)
    triggerClientEvent(thePlayer, "onServerGetPedSimplestTask", thePlayer)
end

function getServerSimplestTask(theTask)
    setElementData(client, "simplestTask", theTask)
end
addEvent("onSimplestTaskReturned", true)
addEventHandler("onSimplestTaskReturned", resourceRoot, getServerSimplestTask)

function updateTask(thePlayer)
    getServerPedTask(thePlayer)
end
addEventHandler("onVehicleStartEnter", root, updateTask)
addEventHandler("onVehicleStartExit", root, updateTask)
addEventHandler("onVehicleEnter", root, updateTask)
addEventHandler("onVehicleExit", root, updateTask)

function vehicleGodMod(player) 
  if isPedInVehicle ( player ) and getPedOccupiedVehicleSeat( player ) == 0 then 
  vehicle = getPedOccupiedVehicle ( player ) 
  setVehicleDamageProof( vehicle, true )
outputChatBox ( "#FFFFFFVehicle godmode #00FF00enabled", getRootElement(), 255, 0, 0, true )
    end
end
addEventHandler("onColShapeHit", root, vehicleGodMod)

function vehicleGodMod2(player) 
  if isPedInVehicle ( player ) and getPedOccupiedVehicleSeat( player ) == 0 then 
    setVehicleDamageProof( vehicle, false ) 
    outputChatBox ( "Vehicle godmode #FF0004disabled", getRootElement(), 255, 255, 255, true )
    end 
end
addEventHandler("onColShapeLeave", root, vehicleGodMod2)

function handlePoly(thePlayer)
    local currentPoly = getElementData(source, "accId") or false
    if currentPoly then
        local polyAccType = getElementData(source, "accType")
        local polyAccRule = getElementData(source, "accRule")
        
        
        
        if getElementType(thePlayer) == "player" and isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup("Admin")) then
            outputChatBox("Because you're an administrator, you will not be affected by zone settings!", thePlayer, 255, 155, 0)
            if tonumber(polyAccType) == 1 then
                outputChatBox("ID: "..currentPoly.." | Acces: "..polyAccRule.." | Tip Acces: Cont", thePlayer, 255, 155, 0)
            elseif tonumber(polyAccType) == 2 then
                outputChatBox("ID: "..currentPoly.." | Acces: "..polyAccRule.." | Tip Acces: Clan", thePlayer, 255, 155, 0)
            elseif tonumber(polyAccType) == 3 then
                outputChatBox("ID: "..currentPoly.." | Acces: "..polyAccRule.." | Tip Acces: Grup ACL", thePlayer, 255, 155, 0)
            elseif tonumber(polyAccType) == 4 then
                outputChatBox("ID: "..currentPoly.." | Acces: --- | Tip Acces: Zona Sigura", thePlayer, 255, 155, 0)
            else
                outputChatBox("ID: "..currentPoly.." | Zona nu este configurata corect!", thePlayer, 255, 0, 0)
            end
        else
            if tonumber(polyAccType) == 1 then
                if getElementType(thePlayer) == "player" and getAccountName(getPlayerAccount(thePlayer)) ~= tostring(polyAccRule) or isGuestAccount(getPlayerAccount(thePlayer)) then
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a incercat sa patrunda intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Cont | Regula de Acces: "..tostring(polyAccRule))
                    local exportX = getElementData(source, "exportX")
                    local exportY = getElementData(source, "exportY")
                    local exportZ = getElementData(source, "exportZ")
                    setTimer(function(thePlayer, theZone) warpOutIfStillIn(thePlayer, theZone) end, 2000, 1, thePlayer, source)
                    if not isPedInVehicle(thePlayer) then
                        setElementPosition(thePlayer, exportX, exportY, exportZ)
                        outputChatBox("Ai fost teleportat deoarece nu esti detinatorul bazei!", thePlayer, 255, 155, 0, true)
                    else
                        if getSimplestTaskOf(thePlayer) == "TASK_SIMPLE_CAR_DRIVE" then
                            if getElementModel(getPedOccupiedVehicle(thePlayer)) == 487 or getElementModel(getPedOccupiedVehicle(thePlayer)) == 497 then
                                local px, py, pz = getElementPosition(thePlayer)
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ + 25)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("Ai fost teleportat deoarece nu esti detinatorul bazei!", thePlayer, 255, 155, 0, true)
                            else
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("Ai fost teleportat deoarece nu esti detinatorul bazei!", thePlayer, 255, 155, 0, true)
                            end
                        else
                            removePedFromVehicle(thePlayer)
                            setElementPosition(thePlayer, exportX, exportY, exportZ)
                            outputChatBox("Ai fost teleportat deoarece nu esti detinatorul bazei!", thePlayer, 255, 155, 0, true)
                        end
                    end
                else
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a intrat intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Cont | Regula de Acces: "..tostring(polyAccRule))
                end
            elseif tonumber(polyAccType) == 2 then
                if tostring(getElementData(thePlayer, "gang")) ~= tostring(polyAccRule) then
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a incercat sa patrunda intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Clan | Regula de Acces: "..tostring(polyAccRule))
                    local exportX = getElementData(source, "exportX")
                    local exportY = getElementData(source, "exportY")
                    local exportZ = getElementData(source, "exportZ")
                    setTimer(function(thePlayer, theZone) warpOutIfStillIn(thePlayer, theZone) end, 2000, 1, thePlayer, source)
                    if not isPedInVehicle(thePlayer) then
                        setElementPosition(thePlayer, exportX, exportY, exportZ)
                        outputChatBox("You were teleported because you do not belong to the clan #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                    else
                        if getSimplestTaskOf(thePlayer) == "TASK_SIMPLE_CAR_DRIVE" then
                            if getElementModel(getPedOccupiedVehicle(thePlayer)) == 487 or getElementModel(getPedOccupiedVehicle(thePlayer)) == 497 then
                                local px, py, pz = getElementPosition(thePlayer)
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ + 25)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("You were teleported because you do not belong to the clan #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                            else
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("You were teleported because you do not belong to the clan #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                            end
                        else
                            removePedFromVehicle(thePlayer)
                            setElementPosition(thePlayer, exportX, exportY, exportZ)
                            outputChatBox("You were teleported because you do not belong to the clan #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                            outputChatBox(getSimplestTaskOf(thePlayer), thePlayer, 255, 155, 0)
                        end
                    end
                else
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a intrat intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Clan | Regula de Acces: "..tostring(polyAccRule))
                end
            elseif tonumber(polyAccType) == 3 then
                if not isObjectInACLGroup("user."..getAccountName(getPlayerAccount(thePlayer)), aclGetGroup(tostring(polyAccRule))) then
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a incercat sa patrunda intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Grup ACL | Regula de Acces: "..tostring(polyAccRule))
                    local exportX = getElementData(source, "exportX")
                    local exportY = getElementData(source, "exportY")
                    local exportZ = getElementData(source, "exportZ")
                    setTimer(function(thePlayer, theZone) warpOutIfStillIn(thePlayer, theZone) end, 2000, 1, thePlayer, source)
                    if not isPedInVehicle(thePlayer) then
                        setElementPosition(thePlayer, exportX, exportY, exportZ)
                        outputChatBox("Ai fost teleportat deoarece nu apartii grupului #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                    else
                        if getSimplestTaskOf(thePlayer) == "TASK_SIMPLE_CAR_DRIVE" then
                            if getElementModel(getPedOccupiedVehicle(thePlayer)) == 487 or getElementModel(getPedOccupiedVehicle(thePlayer)) == 497 then
                                local px, py, pz = getElementPosition(thePlayer)
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ + 25)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("Ai fost teleportat deoarece nu apartii grupului #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                            else
                                setElementPosition(getPedOccupiedVehicle(thePlayer), exportX, exportY, exportZ)
                                setElementVelocity(getPedOccupiedVehicle(thePlayer), 0, 0, 0)
                                outputChatBox("Ai fost teleportat deoarece nu apartii grupului #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                            end
                        else
                            removePedFromVehicle(thePlayer)
                            setElementPosition(thePlayer, exportX, exportY, exportZ)
                            outputChatBox("Ai fost teleportat deoarece nu apartii grupului #FFFFFF"..polyAccRule, thePlayer, 255, 155, 0, true)
                        end
                    end
                else
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a intrat intr-o zona de acces!")
                    call(getResourceFromName("logsys"), "outputLog", "Tipul de Acces: Grup ACL | Regula de Acces: "..tostring(polyAccRule))
                end
            elseif tonumber(polyAccType) == 4 then
                if getElementType(thePlayer) == "player" then 
                    call(getResourceFromName("logsys"), "outputLog", "Securitate: "..getPlayerName(thePlayer).." a intrat intr-o zona sigura!")
                    outputChatBox("Ai patruns intr-o zona sigura! Armele tale au fost dezactivate temporar!", thePlayer, 255, 155, 0)
                    toggleControl (thePlayer, "fire", false)
                    toggleControl (thePlayer, "next_weapon", false)
                    toggleControl (thePlayer, "previous_weapon", false)
                    toggleControl (thePlayer, "aim_weapon", false)
                    toggleControl (thePlayer, "vehicle_fire", false)
                    setPlayerHudComponentVisible (thePlayer, "ammo", false)
                    setPlayerHudComponentVisible (thePlayer, "weapon", false)
                end
            end
        end
    end
    
end

addEventHandler("onColShapeHit", resourceRoot, handlePoly)


function resetAntiPvP(thePlayer)
    local accType = getElementData(source, "accType")
    if tonumber(accType) == 4 and getElementType(thePlayer) == "player" then
        outputChatBox("Ai parasit zona sigura! Armele tale au fost re-activate!", thePlayer, 255, 155, 0)
        toggleControl (thePlayer, "fire", true)
        toggleControl (thePlayer, "next_weapon", true)
        toggleControl (thePlayer, "previous_weapon", true)
        toggleControl (thePlayer, "aim_weapon", true)
        toggleControl (thePlayer, "vehicle_fire", true)
        setPlayerHudComponentVisible (thePlayer, "ammo", true)
        setPlayerHudComponentVisible (thePlayer, "weapon", true)
    end
end
addEventHandler("onColShapeLeave", resourceRoot, resetAntiPvP)

function warpOutIfStillIn(thePlayer, theZone)
    if isElement(thePlayer) and isElementWithinColShape(thePlayer, theZone) then
        local exportX = getElementData(theZone, "exportX")
        local exportY = getElementData(theZone, "exportY")
        local exportZ = getElementData(theZone, "exportZ")
        removePedFromVehicle(thePlayer)
        setElementPosition(thePlayer, exportX, exportY, exportZ)
  end

  end
Link to comment
6 hours ago, Quenix said:

but the godmode enables on every col

you not defined specific colshape here

function vehicleGodMod(player) 
  if isPedInVehicle ( player ) and getPedOccupiedVehicleSeat( player ) == 0 then 
  vehicle = getPedOccupiedVehicle ( player ) 
  setVehicleDamageProof( vehicle, true )
outputChatBox ( "#FFFFFFVehicle godmode #00FF00enabled", getRootElement(), 255, 0, 0, true )
    end
end
addEventHandler("onColShapeHit", root, vehicleGodMod)
function vehicleGodMod2(player) 
  if isPedInVehicle ( player ) and getPedOccupiedVehicleSeat( player ) == 0 then 
    setVehicleDamageProof( vehicle, false ) 
    outputChatBox ( "Vehicle godmode #FF0004disabled", getRootElement(), 255, 255, 255, true )
    end 
end
addEventHandler("onColShapeLeave", root, vehicleGodMod2)

you should add

if source == your_colshape then -- using colshape directly

another idea (attach to elementData + useful function). Also, sorry) i forgot that onVehicleDamage doesn't have cancel effect so here (client-side):

addEventHandler("onClientVehicleDamage",root,function()
	local col = isElementWithinAColShape(source)
	if col then
		if getElementData(col,"safe-zone") then
			cancelEvent()
		end
	end
end)

function isElementWithinAColShape(element)
   local element = element or localPlayer
   if element or isElement(element)then
      for _,colshape in ipairs(getElementsByType("colshape"))do
	 if isElementWithinColShape(element,colshape) then
	    return colshape
	 end
      end
   end
   outputDebugString("isElementWithinAColShape - Element does not exist",1)
   return false
end

@Quenix, try both ideas and find out which one is better

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