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
|
ITEM.Name = "Fireball"
ITEM.Class = "weapon"
ITEM.Desc = "Warning: Warm"
ITEM.Model = "models/props_debris/wood_board02a.mdl"
ITEM.Icon = Material("wintersurvival2/hud/ws2_icons/icon_spellfireball.png")
ITEM.HoldType = "magic"
//Load some nessessary stuff
game.AddParticles("particles/particletest.pcf")
PrecacheParticleSystem("firetest")
ITEM.Recipe = {
Resources = {
["Plank"] = 2,
["Rope"] = 1,
["Sap"] = 1,
},
Tools = {},
}
ITEM.CD = 0.25
ITEM.NumFireballs = {}
ITEM.MaxFireballs = 3
local fireball = {}
fireball["model"] = "models/hunter/blocks/cube025x025x025.mdl"
fireball["speed"] = 700
fireball["drop"] = 50
fireball["init"] = function(fb) fb:Ignite(10) end
fireball["onhit"] = function (self,data,phys)
print("Explode called")
local exp = ents.Create("env_explosion")
exp:SetPos(self:GetPos())
exp:Fire("Explode","",0)
exp:Spawn()
for k,v in pairs(ents.FindInSphere(self:GetPos(),200)) do
if(v.TakeDamage) then
local dmg = ( 200 - v:GetPos():Distance( self:GetPos() ) )/2
v:TakeDamage(dmg,nil,self)
print("Takeing " .. dmg .. " dammage")
end
end
self:Remove()
end
function ITEM:DoFireball(pl)
print("Fully successfull fireball callback:")
print(pl)
local aim = pl:GetAimVector()
local D = ents.Create("ws_projectile")
if(fireball.speed) then D.speed = fireball.speed end
if(fireball.model) then D.model = fireball.model end
if(fireball.drop) then D.drop = fireball.drop end
if(fireball.init) then D.init = fireball.init end
if(fireball.onhit) then D.onhit = fireball.onhit end
print("D's speed:" .. D.speed)
D:SetPos(pl:GetShootPos()+aim*50)
D:SetOwner(pl)
D:SetAngles(aim:Angle())
D:Spawn()
pl:EmitSound(Sound("physics/flesh/flesh_impact_hard.wav"),100,math.random(90,110))
end
function ITEM:OnSecondary(pl,tr)
ParticleEffect("firetest",pl:GetPos(),pl:GetAngles(),pl)
if(self.NumFireballs[pl] ~= nil and self.NumFireballs[pl] > 0) then
self:DoFireball(pl)
self.NumFireballs = self.NumFireballs-1
end
end
hook.Add("PlayerDeath","remove_fireball_count",function(victim,inflictor,attacker)
self.NumFireballs[victim] = 0
end)
hook.Add("PlayerDisconnected","clean_fireball_count",function(ply)
self.NumFireballs[ply] = nil
end)
local fireballfunc = function(num,pl,self)
if(num == 0) then return end
if self.NumFireballs[ply] == nil then
self.NumFireballs[ply] = 1
elseif self.NumFireballs[ply] < self.MaxFireballs then
self.NumFireballs[ply] = self.NumFireballs[ply] + 1
end
end
function ITEM:OnPrimary(pl,tr)
if(CLIENT) then return end
print("Attempting to cast...")
pl:Cast("Fireball",fireballfunc,self)
end
|