aboutsummaryrefslogtreecommitdiff
path: root/zone_example.lua
blob: 509eb886ae43d180919cd0e36c9c8d0c511e225f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
--This is an example usage of the zones system.
AddCSLuaFile("zones.lua")
include("zones.lua")

zones.RegisterClass("Arena Zone",Color(255,0,0))

--Use this to set default properties. Only called on server.
hook.Add("OnZoneCreated","Arena Zone",function(zone,class,zoneID)
	if class == "Arena Zone" then
		
		zone.DmgMul = 1
		
	end
end)

-- Use this hook to let a player change a zone after making it or with the edit tool.
-- class is zone.class, zone is the zone's full table, DPanel is a panel to parent your things to, zoneID is the zone's ID, DFrame is the whole frame.
-- Return your preferred width and height for the panel and the frame will size to it.
hook.Add("ShowZoneOptions","Arena Zone",function(zone,class,DPanel,zoneID,DFrame) 
	if class == "Arena Zone" then
		local w,h = 500, 400
		
		local mulbl = Label("Damage Multiplier:")
		mulbl:SetParent(DPanel)
		mulbl:SetPos(5,5)
		mulbl:SetTextColor(color_black)
		mulbl:SizeToContents()
		
		local mul = vgui.Create("DNumberWang",DPanel) --parent to the panel.
		mul:SetPos(5,mulbl:GetTall()+10)
		mul:SetValue(zone.DmgMul)
		mul:SetDecimals(1)
		mul:SetMinMax(0,10)
		function mul:OnValueChanged(new)
			net.Start("arena_zone")
				net.WriteFloat(zoneID)
				net.WriteFloat(new)
			net.SendToServer()
		end
		
		
		
		return w, h -- Specify the width and height for the DPanel container. The frame will resize accordingly.
		
	end
end)

if SERVER then
	util.AddNetworkString("arena_zone")
	net.Receive("arena_zone",function(len,ply)
		local id, new = net.ReadFloat(), net.ReadFloat()
		if not ply:IsAdmin() then return end
		
		zones.List[id].DmgMul = new
		zones.Sync()
		
	end)
end

hook.Add("ScalePlayerDamage","Arena Zone",function(ply, hitgroup, dmginfo)
	local zone = ply:GetCurrentZone() 
	if zone then
		if zone.class == "Arena Zone" then
			dmginfo:ScaleDamage(zone.DmgMul)
			
		end
	end
end)