Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ttt_smokegrenade_proj.lua
- AddCSLuaFile()
- ENT.Type = "anim"
- ENT.Base = "ttt_basegrenade_proj"
- ENT.Model = Model("models/weapons/w_eq_smokegrenade_thrown.mdl")
- AccessorFunc( ENT, "radius", "Radius", FORCE_NUMBER )
- function ENT:SetupDataTables()
- self:NetworkVar("Float", 0, "ExplodeTime")
- self:NetworkVar("Bool", 0, "Impact")
- end
- function ENT:Initialize()
- if not self:GetRadius() then self:SetRadius(100) end
- self:SetModel(self.Model)
- self:PhysicsInit(SOLID_VPHYSICS)
- self:SetMoveType(MOVETYPE_VPHYSICS)
- self:SetSolid(SOLID_BBOX)
- self:SetCollisionGroup(COLLISION_GROUP_PROJECTILE)
- if SERVER then
- self:SetExplodeTime(0)
- self:SetImpact(true)
- end
- end
- function ENT:Setsmokeimp(t)
- print(t)
- self:SetImpact(t)
- end
- if CLIENT then
- local smokeparticles = {
- Model("particle/particle_smokegrenade"),
- Model("particle/particle_noisesphere")
- };
- function ENT:CreateSmoke(center)
- local em = ParticleEmitter(center)
- local r = self:GetRadius()
- for i=1, 20 do
- local prpos = VectorRand() * r
- prpos.z = prpos.z + 30
- local p = em:Add(table.Random(smokeparticles), center + prpos)
- if p then
- local gray = math.random(75, 200)
- p:SetColor(gray, gray, gray)
- p:SetStartAlpha(255)
- p:SetEndAlpha(200)
- p:SetVelocity(VectorRand() * math.Rand(900, 1300))
- p:SetLifeTime(0)
- p:SetDieTime(math.Rand(100, 140))
- p:SetStartSize(math.random(280, 300))
- p:SetEndSize(math.random(1, 40))
- p:SetRoll(math.random(-180, 180))
- p:SetRollDelta(math.Rand(-0.1, 0.1))
- p:SetAirResistance(600)
- p:SetCollide(true)
- p:SetBounce(0.4)
- p:SetLighting(false)
- end
- end
- em:Finish()
- end
- end
- function ENT:Explode(tr)
- if SERVER then
- print("server?")
- self:SetNoDraw(true)
- self:SetSolid(SOLID_NONE)
- -- pull out of the surface
- if tr.Fraction != 1.0 then
- self:SetPos(tr.HitPos + tr.HitNormal * 0.6)
- end
- local pos = self:GetPos()
- self:Remove()
- else
- print("else?")
- local spos = self:GetPos()
- local trs = util.TraceLine({start=spos + Vector(0,0,64), endpos=spos + Vector(0,0,-128), filter=self})
- util.Decal("SmallScorch", trs.HitPos + trs.HitNormal, trs.HitPos - trs.HitNormal)
- --self:SetDetonateExact(0)
- if tr.Fraction != 1.0 then
- spos = tr.HitPos + tr.HitNormal * 0.6
- end
- -- Smoke particles can't get cleaned up when a round restarts, so prevent
- -- them from existing post-round.
- if GetRoundState() == ROUND_POST then return end
- self:CreateSmoke(spos)
- end
- end
- function ENT:Think()
- etime = self:GetExplodeTime() or 0
- if etime != 0 and etime < CurTime() then
- -- if thrower disconnects before grenade explodes, just don't explode
- if SERVER and (not IsValid(self:GetThrower())) then
- self:Remove()
- etime = 0
- return
- end
- -- find the ground if it's near and pass it to the explosion
- local spos = self:GetPos()
- local tr = util.TraceLine({start=spos, endpos=spos + Vector(0,0,-32), mask=MASK_SHOT_HULL, filter=self.thrower})
- local success, err = pcall(self.Explode, self, tr)
- if not success then
- -- prevent effect spam on Lua error
- self:Remove()
- ErrorNoHalt("ERROR CAUGHT: ttt_basegrenade_proj: " .. err .. "\n")
- end
- end
- end
- function ENT:PhysicsCollide( data, physobj )
- if self:GetImpact() == true then
- self:SetExplodeTime(CurTime())
- print(self:GetExplodeTime())
- end
- end
- weapon_ttt_smokegrenade.lua
- AddCSLuaFile()
- SWEP.HoldType = "grenade"
- if CLIENT then
- SWEP.PrintName = "grenade_smoke"
- SWEP.Slot = 3
- SWEP.ViewModelFlip = false
- SWEP.ViewModelFOV = 54
- SWEP.Icon = "vgui/ttt/icon_nades"
- SWEP.IconLetter = "Q"
- SWEP.EquipMenuData = {
- type = "Grenade",
- desc = "Smoke grenade, you should know what this is.\n!Right click Instantly detonates!."
- }
- end
- SWEP.Base = "weapon_tttbasegrenade"
- SWEP.WeaponID = AMMO_SMOKE
- SWEP.Kind = WEAPON_NADE
- SWEP.CanBuy = { ROLE_SURVIVALIST }
- SWEP.UseHands = true
- SWEP.ViewModel = "models/weapons/cstrike/c_eq_smokegrenade.mdl"
- SWEP.WorldModel = "models/weapons/w_eq_smokegrenade.mdl"
- SWEP.Weight = 5
- SWEP.AutoSpawnable = true
- SWEP.Spawnable = true
- SWEP.RCImpact = false
- -- really the only difference between grenade weapons: the model and the thrown
- -- ent.
- function SWEP:GetGrenadeName()
- return "ttt_smokegrenade_proj"
- end
- function SWEP:SecondaryAttack()
- self:SetNextSecondaryFire(CurTime() + self.Primary.Delay)
- if GetRoundState() == ROUND_PREP and GetConVar("ttt_no_nade_throw_during_prep"):GetBool() then
- return
- end
- self.RCImpact = true
- self:PullPin(0)
- end
- function SWEP:Throw()
- if CLIENT then
- self:SetThrowTime(0)
- elseif SERVER then
- local ply = self:GetOwner()
- if not IsValid(ply) then return end
- if self.was_thrown then return end
- self.was_thrown = true
- local ang = ply:EyeAngles()
- local src = ply:GetPos() + (ply:Crouching() and ply:GetViewOffsetDucked() or ply:GetViewOffset())+ (ang:Forward() * 8) + (ang:Right() * 10)
- local target = ply:GetEyeTraceNoCursor().HitPos
- local tang = (target-src):Angle() -- A target angle to actually throw the grenade to the crosshair instead of fowards
- -- Makes the grenade go upgwards
- if tang.p < 90 then
- tang.p = -10 + tang.p * ((90 + 10) / 90)
- else
- tang.p = 360 - tang.p
- tang.p = -10 + tang.p * -((90 + 10) / 90)
- end
- tang.p=math.Clamp(tang.p,-90,90) -- Makes the grenade not go backwards :/
- local vel = math.min(800, (90 - tang.p) * 6)
- local thr = tang:Forward() * vel + ply:GetVelocity()
- if self.RCImpact then
- self:CreateGrenade(src, Angle(0,0,0), thr, Vector(600, math.random(-1200, 1200), 0), ply, true)
- elseif not self.RCImpact then
- self:CreateGrenade(src, Angle(0,0,0), thr, Vector(600, math.random(-1200, 1200), 0), ply, false)
- else
- print("Bruh")
- end
- self:SetThrowTime(0)
- self:Remove()
- end
- end
- function SWEP:CreateGrenade(src, ang, vel, angimp, ply, impact)
- local gren = ents.Create(self:GetGrenadeName())
- if not IsValid(gren) then return end
- gren:SetPos(src)
- gren:SetAngles(ang)
- -- gren:SetVelocity(vel)
- gren:SetOwner(ply)
- gren:SetThrower(ply)
- gren:SetGravity(0.4)
- gren:SetFriction(0.2)
- gren:SetElasticity(0.45)
- gren:Spawn()
- gren:PhysWake()
- local phys = gren:GetPhysicsObject()
- if IsValid(phys) then
- phys:SetVelocity(vel)
- phys:AddAngleVelocity(angimp)
- end
- gren:SetDetonateExact(self:GetDetTime())
- -- This has to happen AFTER Spawn() calls gren's Initialize()
- if impact then
- gren:Setsmokeimp(true)
- elseif not impact then
- gren:Setsmokeimp(false)
- else
- print("Bruh")
- end
- return gren
- end
Add Comment
Please, Sign In to add comment