Garry's Mod

Garry's Mod

Nub's Safe Zones
 This topic has been pinned, so it's probably important
NubTheFatMan  [developer] 20 Jul, 2021 @ 9:57pm
Developer Support
Want to add your own functionality to this mod? This should help you get started. There are some things I want to change when I revisit this, so be sure to keep updated on this!

There's really only two functions you will use. An asterisk (*) means the argument is required.
nsz:RegisterZone(*title, *subtitle, *type, icon, color, variables) * string title: The title of the zone (to display on the HUD). * string subtitle: The subtitle of the zone (to display on the HUD). * string type: The zone identifier, used for permissions. string icon="materials/nsz/nsz.png": The icon to show on the HUD. Color color=Color(255, 255, 255): The color of the zone (for debug rendering). table variables={build = false, nodamage = false}: The default variables of the zone, but can be managed by an admin mod. Example: nsz:RegisterZone("Spawn Zone", "No building or killing here", "spawn", "materials/nsz/nsz.png", Color(255, 255, 62), {nodamage = true}) nsz:InZone(*ent, filter) * Vector/Entity/Player ent: Checks if the ent is in a zone. If this is a Vector, it just checks that Vector. If it's an Entity or Player, it will factor in the hitbox. string/table filter: The zone identifier filter. If left blank, it will check all zones, otherwise it'll only check the zones you specify. -> Returns a table of all zones the ent is in. If something went wrong, it will instead return false. What can go wrong: the nsz.zones table was deleted, or there are no zones in the world. Example: nsz:InZone(player.GetAll()[1], "spawn")

There are also some hooks:
"EntityZoneEnter" (ent, zone_type) Entity/Player ent: The Entity or Player trying to enter a zone. string zone_type: The zone identifier the Entity or Player is entering. -> Return false to disallow the entity from entering the zone. Or return true to allow it. Example: hook.Add("EntityZoneEnter", "my_entering_zone_permissions", function(ent, zone) -- Do some stuff to determine if they're worthy or not if notWorthy then return false end end) "EntityZoneLeave" (ent, zone_type) Entity/Player ent: The Entity or Player leaving a zone. string zone_type: The zone identifier the Entity or Player is leaving. Example: hook.Add("EntityZoneLeave", "log_players_who_leave_zones", function(ent, zone) if ent:IsPlayer() then MsgN(ent:Nick() .. " has left zone " .. zone) end end)