aboutsummaryrefslogtreecommitdiff
path: root/gamemode/itemsystem/weapons/scraphammer.lua
blob: 25349073c3da7bbc7d24f554bed49dfb6e63551b (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
--[[
    An example item
]]
do return end
local com = nrequire("core/inventory/common/weapons.lua")
local itm = nrequire("core/inventory/common/items.lua")
local reg = nrequire("core/inventory/item.lua")
local pac,eff
if SERVER then
	pac = nrequire("core/pac/sv_pac.lua")
else
	eff = nrequire("core/clienteffects/blocked.lua")
end

local item = {}

--Required, a name, all item names must be unique
item.Name = "Scrap Hammer"

--Optional, a tooltip to display
item.Tooltip = "Bits of scrap put togeather to resemble a hammer"

--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["toast"] = function() print("You pressed toast!") end
	options["Drop"] = itm.DropItem(self)
	return options
end

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

function item.DoOnEquipPanel(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},
	{false,true},
	{false,true},
}

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

local swingdata = {
	["fwd"] = {
		{0.007,Vector(-27,1,9)},
		{0.014,Vector(-20,3,16)},
		{0.020,Vector(-11,6,22)},
		{0.027,Vector(0,7,26)},
		{0.032,Vector(15,7,25)},
		{0.039,Vector(28,6,21)},
		{0.045,Vector(38,4,14)},
		{0.052,Vector(46,0,3)},
		{0.059,Vector(50,-3,-6)},
		{0.065,Vector(52,-6,-15)},
		{0.072,Vector(52,-8,-22)},
		{0.078,Vector(51,-10,-28)},
		{0.084,Vector(50,-11,-31)},
		{0.091,Vector(50,-11,-32)},
		{0.097,Vector(50,-11,-32)}
	},
	["lft"] = {
		{0.007,Vector(-6,24,2)},
		{0.014,Vector(-1,26,2)},
		{0.020,Vector(5,28,1)},
		{0.027,Vector(12,28,-1)},
		{0.035,Vector(19,27,-4)},
		{0.042,Vector(27,24,-7)},
		{0.048,Vector(37,17,-13)},
		{0.055,Vector(42,12,-17)},
		{0.061,Vector(45,5,-20)},
		{0.068,Vector(48,-2,-23)},
		{0.075,Vector(49,-8,-25)},
		{0.084,Vector(49,-14,-26)},
		{0.091,Vector(49,-19,-27)},
		{0.097,Vector(48,-22,-27)},
		{0.104,Vector(48,-25,-27)},
		{0.110,Vector(48,-26,-27)},
		{0.117,Vector(48,-27,-27)},
		{0.123,Vector(48,-26,-27)},
		{0.131,Vector(48,-26,-27)}
	},
	["rig"] = {
		{0.009,Vector(-3,25,2)},
		{0.017,Vector(3,27,1)},
		{0.025,Vector(11,28,-1)},
		{0.032,Vector(20,27,-4)},
		{0.040,Vector(28,24,-7)},
		{0.051,Vector(36,19,-12)},
		{0.059,Vector(42,11,-17)},
		{0.067,Vector(47,2,-22)},
		{0.075,Vector(49,-5,-25)},
		{0.083,Vector(49,-13,-27)},
		{0.090,Vector(49,-19,-28)},
		{0.098,Vector(48,-24,-28)},
		{0.106,Vector(48,-27,-28)},
		{0.114,Vector(48,-28,-28)},
		{0.121,Vector(48,-27,-28)},
		{0.129,Vector(48,-27,-27)}
	},
}

local attacks = {
	forward = {
		anim = "hammer_swing_up",
		animtime = 2.33,
		data = swingdata["fwd"],
		dammage = 5
	},
	left = {
		anim = "hammer_swing_left",
		animtime = 2.33,
		data = swingdata["lft"],
		dammage = 5
	},
	right = {
		anim = "hammer_swing_right",
		animtime = 2.33,
		data = swingdata["rig"],
		dammage = 5
	}
}

--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)
	--Make sure we can swing (off cooldown)
	item.lastSwing[owner] = item.lastSwing[owner] or 0
	if item.lastSwing[owner] > CurTime() then return end
	item.lastSwing[owner] = CurTime()+1.33
	
	--[[
	local movementtbl = {}
	for k,v in pairs(attacks) do
		movementtbl[k] = function()
			owner:SetLuaAnimation(v.anim)
			timer.Simple(v.animtime,function()
				owner:StopLuaAnimation(v.anim)
			end)
			local times, pos = {},{}
			for i,j in pairs(v.data) do
				times[i] = 1 + j[1]
				pos[i] = Vector(j[2])
				pos[i]: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 == k then
					eff()
				elseif tr.Entity.TakeDamage ~= nil and tr.Entity ~= owner then
					tr.Entity:TakeDamage(v.dammage,owner,owner:GetActiveWeapon())
				end
			end)
		end
	end
	]]
	local movementtbl = com.createattackstable(attacks)

	--Do the attack
	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("woo! i'm being used!")
	if SERVER then
		who:GetActiveWeapon():SetHoldType("melee2")
		pac.ApplyPac(who,"scraphammer")
	end
end

--Optional, if we should do something speical on unequip(like setting animations back to normal)
item.onUnEquip = function(self,who)
	print("aw, I'm being put away :(")
	who:GetActiveWeapon():SetHoldType("normal")
	pac.RemovePac(who,"scraphammer")
end

item.onDropped = function(self, ent)
    pac.ApplyPac(ent,"scraphammer")
end

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