aboutsummaryrefslogtreecommitdiff
path: root/gamemode/itemsystem/items/tent.lua
blob: 0df60d00bacc6e35c661f5a9093019049d2f398b (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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
local ITEM = {}
ITEM.Name 		= "Tent"
ITEM.Class 		= "structure"
ITEM.Desc 		= "Something to duck under.\nHold down shift to snap"
ITEM.Model 		= "models/props_debris/wood_board07a.mdl"
ITEM.Icon 		=  Material("settlement/icon_tent")
ITEM.Recipe		= {
	Resources = {
		["Fence"] = 4,
		["Rope"] = 2,
	},
	Tools = {
		["Crystal"] = 1,
	},
}

ITEM.Structure = {
	{
		Bone = "ValveBiped.Bip01_R_Hand",
		Model = "models/props_junk/Rock001a.mdl",
		Size = Vector(0.5,0.5,0.5),
		Pos = Vector(4,-3,-1),
		Ang = Angle(0,0,0),
	},
}

ITEM.Ghost = {
	{
		Model = "models/props_wasteland/wood_fence01a.mdl",
		Size = Vector(1,1,1),
		Pos = Vector(30,0,40),
		Ang = Angle(0,-90,45),
	},
	{
		Model = "models/props_wasteland/wood_fence01a.mdl",
		Size = Vector(1,1,1),
		Pos = Vector(-30,0,40),
		Ang = Angle(0,90,45),
	},
}

ITEM.Range 		= 300
ITEM.CD 		= 0.5

function ITEM:OnPrimary(pl,tr)
	if (CLIENT) then return end

	if (!pl:CanPlaceStructure(tr)) then pl:GhostStructure(self.Name) return end

	if (tr.Hit) then
		local Ang = Angle(0,pl:GetAimVector():Angle().y+90,0)
		local Pos = tr.HitPos
		if(pl:KeyDown(IN_SPEED)) then
			Pos.x = Pos.x - (Pos.x%20)
			Pos.y = Pos.y - (Pos.y%20)
			Pos.z = Pos.z - (Pos.z%20)
			Ang.yaw = Ang.yaw - (Ang.yaw%15)
		end

		for k,v in pairs(self.Ghost) do
			local Off = v.Pos*1
			Off:Rotate(Ang)

			local Roa = Ang*1

			Roa:RotateAroundAxis(Ang:Right(),v.Ang.p)
			Roa:RotateAroundAxis(Ang:Forward(),v.Ang.r)
			Roa:RotateAroundAxis(Ang:Up(),v.Ang.y)

			local drop = ents.Create("ws_prop")
			drop:SetModel(v.Model)
			drop:SetAngles(Roa)
			drop:SetPos(Pos+Off)
			drop:Spawn()
			drop:Activate()
		end

		if (pl:HasItem(self.Name)) then pl:RemoveItem(self.Name,1)
		else pl:UnEquipWeaponSlot(pl.Select,true) end

		pl:GhostRemove()
	else
		pl:EmitSound(Sound("weapons/iceaxe/iceaxe_swing1.wav"),100,math.random(90,110))
	end
end
RegisterItem(ITEM)