aboutsummaryrefslogtreecommitdiff
path: root/gamemode/itemsystem/weapons/rustyaxe.lua
blob: 00547c89aaedf6ab1263d31e4e8c950249d8b6f7 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
--[[
	An axe that you can swing around!
]]
local pac
if SERVER then
	pac = nrequire("core/pac/sv_pac.lua")
end
local reg = nrequire("core/inventory/item.lua")
local com = nrequire("core/inventory/common/weapons.lua")
local itm = nrequire("core/inventory/common/items.lua")


local item = {}

--Required, a name, all item names must be unique
item.Name = "Rusty Axe"

--Optional, a tooltip to display
item.Tooltip = "An old axe, probably good for fighting."

--Required Returns the data needed to rebuild this item, should only contain the minimum data nessessary since this gets sent over the network
item.Serialize = function(self)
	return ""
end

--Required, Rebuilds the item from data created in Serialize, if the item is different from the "main" copy of the item, it should retun a tabl.Copy(self), with the appropriate fields set.
item.DeSerialize = function(self,string)
	return self
end

--Optional, when the player clicks this item, a menu will show up, if the menu item is clicked, the function is ran. This is all run client side, so if you want it to do something, you'll need to use the net library.
function item.GetOptions(self)
	local options = {}
	options["test"] = function() print("You pressed test!") end
	options["toste"] = function() print("You pressed toste!") end
	options["Drop"] = ART.DropItem(self)
	return options
end

function item.DoOnPanel(dimagebutton)
	dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe.png")
end

function item.DoOnEqupPanel(dimagebutton)
	print("called with panel:",panel)
	dimagebutton:SetImage( "weapons/rustyaxe/rustyaxe_eq.png")
end

--Required, the shape of this item.
item.Shape = {
	{true,true},
	{true},
	{true},
}

--Optional, If this item can be equiped in any player slots, put them here.
item.Equipable = "Right Hand"

local swingdata = {
	["fwd"] = {
		{0.011,Vector(-25,-3,-11)},
		{0.020,Vector(-25,-1,-3)},
		{0.031,Vector(-21,0,7)},
		{0.040,Vector(-13,-1,16)},
		{0.051,Vector(0,-5,22)},
		{0.060,Vector(17,-12,19)},
		{0.069,Vector(27,-18,11)},
		{0.077,Vector(31,-22,2)},
		{0.087,Vector(32,-26,-6)},
		{0.098,Vector(32,-28,-12)},
		{0.107,Vector(31,-29,-16)},
		{0.117,Vector(31,-29,-17)},
		{0.128,Vector(31,-29,-16)},
		{0.141,Vector(31,-29,-16)},
	},
	["lft"] = {
		{0.009,Vector(-34,-25,3)},
		{0.021,Vector(-29,-33,3)},
		{0.031,Vector(-21,-41,2)},
		{0.042,Vector(-9,-47,0)},
		{0.053,Vector(5,-48,-2)},
		{0.064,Vector(20,-44,-6)},
		{0.075,Vector(31,-34,-10)},
		{0.086,Vector(37,-24,-15)},
		{0.095,Vector(39,-16,-17)},
		{0.106,Vector(39,-10,-19)},
		{0.116,Vector(39,-8,-20)},
		{0.126,Vector(39,-8,-19)},
		{0.134,Vector(39,-9,-19)},
		{0.146,Vector(39,-10,-18)},
	},
	["rig"] = {
		{0.021,Vector(-2,9,11)},
		{0.031,Vector(5,10,10)},
		{0.042,Vector(12,8,9)},
		{0.053,Vector(19,4,6)},
		{0.062,Vector(26,-4,2)},
		{0.072,Vector(29,-12,-4)},
		{0.083,Vector(29,-21,-12)},
		{0.093,Vector(25,-27,-18)},
		{0.102,Vector(22,-30,-22)},
		{0.113,Vector(20,-31,-25)},
		{0.123,Vector(19,-32,-25)},
		{0.133,Vector(19,-32,-25)},
	},
}

local attacks = {
	["forward"] = {
		time = 2.33,
		anim = "axe_swing_up",
	}
}

--Optional, what to do when the player clicks, and this item is in the slot in inventory. only works for items equipable in left and right
item.lastSwing = {}
item.onClick = function(self,owner)
	item.lastSwing[owner] = item.lastSwing[owner] or 0
	if item.lastSwing[owner] > CurTime() then
		print("returning because item.lastSwing is " .. item.lastSwing[owner], "but Curtime is",CurTime())
		 return end
	item.lastSwing[owner] = CurTime() + 1.33
	local movementtbl = {
		["forward"] = function()
			--Do the animation
			owner:SetLuaAnimation("axe_swing_up")
			timer.Simple(2.33,function()
				owner:StopLuaAnimation("axe_swing_up")
			end)
			--Do the traces
			local times,pos = {},{}
			for k,v in ipairs(swingdata["fwd"]) do
				times[k] = 1 + v[1]
				pos[k] = Vector(v[2])
				pos[k]:Rotate(owner:GetAimVector():Angle())
			end
			--What to do when our weapon hits
			com.swingarc(owner,times,pos,function(tr)
				print("Calling the swingarc function")
				if not tr.Hit then return end
				print("We hit something!")
				print("takedamage is",tr.Entity.TakeDamage)
				if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "forward" then
					ART.ApplyEffect(owner,"weapon_blocked")
				elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
					print("I hit a ", tr.Entity)
					tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon())
				end
			end)

		end,
		["backward"] = function()

		end,
		["left"] = function()
			owner:SetLuaAnimation("axe_swing_left")
			timer.Simple(2.33,function()
				owner:StopLuaAnimation("axe_swing_left")
			end)
			timer.Simple(1,function()
				ART.TraceWeapon = true
			end)
			timer.Simple(1.33,function()
				ART.TraceWeapon = false
			end)

			local times,pos = {},{}
			for k,v in ipairs(swingdata["lft"]) do
				times[k] = 1 + v[1]
				pos[k] = Vector(v[2])
				pos[k]:Rotate(owner:GetAimVector():Angle())
			end
			if pos[1] == nil then return end
			com.swingarc(owner,times,pos,function(tr)
				if not tr.Hit then return end
				if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "left" then
					ART.ApplyEffect(owner,"weapon_blocked")
				elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
					tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon())
				end
			end)
		end,
		["right"] = function()
			owner:SetLuaAnimation("axe_swing_right")
			timer.Simple(2.33,function()
				owner:StopLuaAnimation("axe_swing_right")
			end)
			timer.Simple(1,function()
				ART.TraceWeapon = true
			end)
			timer.Simple(1.33,function()
				ART.TraceWeapon = false
			end)

			local times,pos = {},{}
			for k,v in ipairs(swingdata["rig"]) do
				times[k] = 1 + v[1]
				pos[k] = Vector(v[2])
				pos[k]:Rotate(owner:GetAimVector():Angle())
			end
			if pos[1] == nil then return end
			com.swingarc(owner,times,pos,function(tr)
				if not tr.Hit then return end
				if tr.Entity.Blocking ~= nil and tr.Entity.Blocking == "right" then
					ART.ApplyEffect(owner,"weapon_blocked")
				elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
					tr.Entity:TakeDamage(5, owner, owner:GetActiveWeapon())
				end
			end)
		end,
	}
	print("At time of doing playermovedir, com is", com)
	movementtbl[com.playermovedir(owner)]()
end

--Optional, if we should do something special on equip(like draw the PAC for this weapon)
item.onEquip = function(self,who)
	print("onEquip",who)
	if CLIENT then print("onEquip client!") end
	if SERVER then
		print("pac is", pac)
		PrintTable(pac)
		who:GetActiveWeapon():SetHoldType("melee")
		pac.ApplyPac(who,"rustyaxe")
		--local outfit = pac.luadata.ReadFile("pac3/mech.txt")
		--who:AttachPACPart(outfit)
		--print("onEquip server!")
	end
end

--Optional, if we should do something speical on unequip(like setting animations back to normal)
item.onUnEquip = function(self,who)
	print("Unequiping axe")
	who:GetActiveWeapon():SetHoldType("normal")
	if SERVER then pac.RemovePac(who,"rustyaxe") end
end

item.onDropped = function(self, ent)
	if SERVER then pac.ApplyPac(ent,"rustyaxe") end
end

print("Hello from rustyaxe.lua")
--Don't forget to register the item!
reg.RegisterItem(item)