aboutsummaryrefslogtreecommitdiff
path: root/zone_example.lua
diff options
context:
space:
mode:
Diffstat (limited to 'zone_example.lua')
-rw-r--r--zone_example.lua82
1 files changed, 81 insertions, 1 deletions
diff --git a/zone_example.lua b/zone_example.lua
index 509eb88..737c706 100644
--- a/zone_example.lua
+++ b/zone_example.lua
@@ -1,4 +1,6 @@
---This is an example usage of the zones system.
+-- This is an example usage of the zones system.
+-- Lots of formal documentation is at the bottom of this file.
+
AddCSLuaFile("zones.lua")
include("zones.lua")
@@ -66,3 +68,81 @@ hook.Add("ScalePlayerDamage","Arena Zone",function(ply, hitgroup, dmginfo)
end
end
end)
+
+
+
+--[[
+ --Example structure of a zone.
+ zones.List[1] = { -- 1 is the zone ID. Automatically assigned.
+
+ -- points, height, bounds, and class are reserved.
+ points = { --List of areas in 3D space which define the zone.
+ { --each area is a list of points. Areas should intersect with one another but they don't have to.
+ Vector(),
+ Vector(),
+ Vector(),
+ },
+ {
+ Vector(),
+ Vector(),
+ Vector(),
+ },
+ },
+ height = {200,100}, -- How tall each area of the zone is. Each entry corresponds to an area listed above.
+ bounds = { --List of the min/max points in each area. Used to speed up point-in-zone testing. These are calculated when the zone is created/changed.
+ {
+ mins=Vector(),
+ maxs=Vector(),
+ },
+ {
+ mins=Vector(),
+ maxs=Vector(),
+ },
+ },
+ class = "GMaps Area", -- Zones with different classes are created and treated separately. Use zones.RegisterClass to create a new one.
+
+ -- Zones can have any other values saved to them. If you save a player, make sure to save it as a steamid.
+
+ }
+
+ -- Example of the ShowZoneOptions hook.
+ -- This hook lets you build your custom VGUI for your zone class which will pop up when players make a new zone or edit an existing one. Clientside.
+ -- Arguments are:
+ -- zone - The full zone table of the zone we are editing.
+ -- class - The class of the zone.
+ -- DPanel - The DPanel which your VGUI elements should be parented to.
+ -- zoneID - The ID of the zone.
+ -- DFrame - The DFrame which holds it all. Not likely you will need this but it's here anyway.
+ -- You must return:
+ -- width, height; How large you want the DPanel to be. It will automatically resize.
+ hook.Add("ShowZoneOptions","hookname_unique",function(zone,class,DPanel,zoneID,DFrame)
+ if class == "Baby Got Back" then --always check class.
+ local w,h = 80, 100
+
+ local mul = vgui.Create("DNumberWang",DPanel) --parent to the panel.
+ mul:SetPos(5,10)
+ mul:SetValue(zone.onlyIfShes) --The default value should be set in the OnZoneCreated hook.
+ mul:SetDecimals(1)
+ mul:SetMinMax(0,10)
+ function mul:OnValueChanged(new)
+ -- Do your stuff here.
+ end
+
+ return w, h
+ end
+ end)
+
+ -- Example of the OnZoneCreated hook.
+ -- This hook lets you set up your newly created zones with default values. Only called serverside.
+ -- Arguments are:
+ -- zone - The full zone table of the zone we are editing.
+ -- class - The class of the zone.
+ -- zoneID - The ID of the zone.
+ hook.Add("OnZoneCreated","hookname_unique",function(zone,class,zoneID)
+ if class == "Baby Got Back" then --always check class.
+ zone.waistSize = Vector(36,24,36)
+ zone.onlyIfShes = "5'3\""
+ end
+ end)
+]]
+