Coder Social home page Coder Social logo

ps-zones's Introduction

ps-zones

image

Purpose

The purpose of this script is to create and handle polyzones more efficiently for zone enter/leave events. Every zone is added to a overarching combozone which greatly improves perfomance looping over the normal distance checking via coords/distance of a point.

The data passed into the exports is optional and not required.

Each Polyzone needs to have a UNIQUE NAME otherwise it will get triggered each time there is a zone.

Dependency:

Events

These events are triggered when a player enters/leaves a zone.

Client

RegisterNetEvent("ps-zones:enter", function(ZoneName, ZoneData)
    -- Code here
end)

RegisterNetEvent("ps-zones:leave", function(ZoneName, ZoneData)
    -- Code here
end)

Server

RegisterServerEvent("ps-zones:enter", function(ZoneName, ZoneData)
    -- Code here
end)

RegisterServerEvent("ps-zones:leave", function(ZoneName, ZoneData)
    -- Code here
end)

Client Exports:

exports["ps-zones"]:CreatePolyZone(name, points, data)

exports["ps-zones"]:CreateBoxZone(name, point, length, width, data)

exports["ps-zones"]:CreateCircleZone(name, point, radius, data)

exports["ps-zones"]:CreateEntityZone(name, entity, data)

exports["ps-zones"]:DestroyZone(name)

Examples:

-- Create Polyzone
exports["ps-zones"]:CreatePolyZone("poly-test", {
      vector2(-7.88, -1058.93),
      vector2(0.03, -1058.67),
      vector2(-3.75, -1054.05),
    }, {
        debugPoly = true,
        minZ =  38.16 - 1,
        maxZ =  38.16 + 1,
})

-- Create Box Zone
RegisterCommand("box", function()
    local ped = PlayerPedId()
    local coords = GetEntityCoords(ped)
    exports["ps-zones"]:CreateBoxZone("box-test", coords, 2.0, 2.0, {
        debugPoly = true,
        heading = 0.0,
        minZ = coords.z - 1,
        maxZ = coords.z + 1,
    })
end)

-- Create Circle Zone
RegisterCommand("circle", function()
    local ped = PlayerPedId()
    local coords = GetEntityCoords(ped)
    exports["ps-zones"]:CreateCircleZone("circle-test", coords, 5.0, {
        debugPoly = true,
        minZ = coords.z - 1,
        maxZ = coords.z + 1,
    })
end)

-- Create Entity Zone
RegisterCommand("entity", function()
    local ped = PlayerPedId()
    exports["ps-zones"]:CreateEntityZone("entity-test", ped, {
        debugPoly = true,
        useZ = false,
    })
end)

ps-zones's People

Contributors

darktrovx avatar monkeywhisper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.