Skip to content

Additional helpers

Michael Afrin edited this page Dec 21, 2020 · 3 revisions

Additional Helper Functions

There are a few additional helper functions that expose some internal variables, in case you might have a use for them. These functions are all based on the bounding box that surrounds the zone and are:

getBoundingBoxMin() - Minimum x and y of the bounding box (works on PolyZone)
getBoundingBoxMax() - Maximum x and y of the bounding box (works on PolyZone)
getBoundingBoxSize() - Size of the bounding box (max - min) (works on PolyZone, BoxZone, and EntityZone)
getBoundingBoxCenter() - Center of the bounding box (works on PolyZone, BoxZone, and EntityZone)
getHeading() - Heading of zone (works on BoxZone and EntityZone)
getLength() - Length of zone (works on BoxZone and EntityZone)
getWidth() - Width of zone (works on BoxZone and EntityZone)
PolyZone.ensureMetatable(zone) - Ensures the correct metatable is present on the passed-in zone (works with any zone)
Note: ensureMetatable will only work if you import the same files you would if you were creating the zone (i.e. if you are calling it on a BoxZone, then you must import client.lua and BoxZone.lua)
printInfo() - Prints some helpful info about a ComboZone (works on ComboZone)

Zone Events

Zone Events are events you can add to any zone, and then trigger for all clients on the server that are inside of that zone. This can be useful if you have things are are triggered by one player, but should take some action for all players in the zone.

Adding and Removing Zone Events

-- To add a new zone event, just call addEvent and pass in a name
zone:addEvent("event_name")

-- ComboZones can optionally take a 'zoneName' parameter
-- which will test if the player is within a zone with that name in the ComboZone,
-- rather than any zone in the ComboZone
combozone:addEvent("event_name", "zone_name")

-- To remove an existing zone event, just call removeEvent and pass in the name
zone:removeEvent("event_name")

Listening to a Zone Event

-- This works just like any other event. Just add an event handler
-- You can have whatever args you want on the event handler callback
-- Any args you pass when you trigger the event will be passed to the handler
AddEventHandler("event_name", function (arg1, arg2)

end

Triggering a Zone Event

-- To trigger a zone event, call the server event 'PolyZone:TriggerZoneEvent'
-- and pass the name of the event you want to trigger, followed by any arguments
TriggerServerEvent("PolyZone:TriggerZoneEvent", "event_name")

-- With args...
TriggerServerEvent("PolyZone:TriggerZoneEvent", "event_name", "string for arg1", "string for arg2")

Additional Helper Commands

pzcomboinfo - Calls printInfo() on every created ComboZone