local ITEM = {} 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.Structure = { { Bone = "ValveBiped.Bip01_R_Hand", Model = "models/props_junk/Rock001a.mdl", Size = Vector(1,1,1), Pos = Vector(0,0,0), Ang = Angle(0,0,0), }, } ITEM.Recipe = { Resources = { ["Plank"] = 2, ["Rope"] = 1, ["Sap"] = 1, }, Tools = {}, } ITEM.CD = 0.25 ITEM.Range = 9999 --[[ The number of fireballs a player has is held in a global table where each entry is [player] = # of fireballs ]] local NumFireballs = {} local 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) 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) end end self.Remove(self) end function ITEM:DoFireball(pl) print("Fully successfull fireball callback:") print(pl) local aim = pl:GetAimVector() local D = ents.Create("ws_projectile") for k,v in pairs(fireball) do D[k] = v end 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 NumFireballs[pl] ~= nil and NumFireballs[pl] > 0 then self:DoFireball(pl) NumFireballs[pl] = NumFireballs[pl]-1 end end hook.Add("PlayerDeath","remove_fireball_count",function(victim,inflictor,attacker) if NumFireballs ~= nil then NumFireballs[victim] = 0 else error("Tried to remove fireball count from non-existant table!") end end) hook.Add("PlayerDisconnected","clean_fireball_count",function(ply) NumFireballs[ply] = nil end) local fireballfunc = function(num,pl,self) print("Fireball func called with ",num,pl,self) print("NumFireballs was",NumFireballs) if num == 0 then return end if NumFireballs[pl] == nil then NumFireballs[pl] = 1 elseif NumFireballs[pl] < MaxFireballs then NumFireballs[pl] = NumFireballs[pl] + 1 end end function ITEM:OnPrimary(pl,tr) if CLIENT then return end print("Attempting to cast...") if NumFireballs[pl] == nil or NumFireballs[pl] < 3 then pl:Cast("Fireball",fireballfunc,self) else pl:ChatPrint("You can't summon any more fireballs") end end RegisterItem(ITEM)