Hello Again. So today i come to you asking for some help with this Plasma Grenade. For some reason if it sticks to someone and it explodes, the body disappears. Any idea's on how to fix?
Here is the code:
[CODE]if SERVER then
AddCSLuaFile()
end
SWEP.Base = "weapon_base"
SWEP.PrintName = "Plasma Grenade"
SWEP.ClassName = "weapon_plasmanade"
SWEP.Author = "Slade Xanthas"
SWEP.Category = "Slade Xanthas"
SWEP.Instructions = "Left click to throw, right click to toss."
SWEP.Slot = 3
SWEP.SlotPos = 1
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = true
SWEP.ViewModelFOV = 55
SWEP.ViewModelFlip = false
SWEP.HoldType = "grenade"
SWEP.Spawnable = true
SWEP.AdminOnly = false
SWEP.ViewModel = "models/weapons/v_Grenade.mdl"
SWEP.WorldModel = "models/weapons/W_grenade.mdl"
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false
SWEP.Primary.Delay = 0.75
SWEP.Primary.ClipSize = 1
SWEP.Primary.DefaultClip = 1
SWEP.Primary.Automatic = true
SWEP.Primary.Ammo = "grenade"
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.Kind = WEAPON_NADE
SWEP.NextThrow = CurTime()
SWEP.NextAnimation = CurTime()
SWEP.Throwing = false
SWEP.StartThrow = false
SWEP.ResetThrow = false
SWEP.Tossed = false
SWEP.ThrowVel = 1500
/*SWEP.VElements = {
["hoverball"] = { type = "Model", model = "models/dav0r/hoverball.mdl", bone = "ValveBiped.Bip01_R_Finger1", rel = "", pos = Vector(1.557, 1.557, -0.519), angle = Angle(0, 0, 0), size = Vector(0.625, 0.625, 0.625), color = Color(255, 255, 255, 255), surpresslightning = false, material = "", skin = 0, bodygroup = {} }
}*/
function SWEP:Initialize()
self:SetWeaponHoldType(self.HoldType)
end
if CLIENT then
local function ShrinkHands(self)
local grenade = self:LookupBone("ValveBiped.Grenade_body")
local matr = self:GetBoneMatrix(grenade)
if matr then
matr:Scale(vector_origin)
self:SetBoneMatrix(grenade, matr)
end
end
local function ResetHands(self)
local grenade = self:LookupBone("ValveBiped.Grenade_body")
local matr = self:GetBoneMatrix(grenade)
if matr then
matr:Scale(Vector(1,1,1))
self:SetBoneMatrix(grenade,matr)
end
end
function SWEP:ShrinkViewModel(cmodel)
if IsValid(cmodel) then
cmodel:SetupBones()
cmodel.BuildBonePositions = ShrinkHands
end
end
function SWEP:ResetViewModel(cmodel)
if IsValid(cmodel) then
cmodel:SetupBones()
cmodel.BuildBonePositions = ResetHands
end
end
function SWEP:CreateViewProp()
self.CSModel = ClientsideModel("models/dav0r/hoverball.mdl", RENDER_GROUP_VIEW_MODEL_OPAQUE)
if IsValid(self.CSModel) then
self.CSModel:SetPos(self:GetPos())
self.CSModel:SetAngles(self:GetAngles())
self.CSModel:SetParent(self)
self.CSModel:SetNoDraw(true)
end
end
function SWEP:ResetWeapon()
if IsValid(self.CSModel) then self.CSModel:Remove() end
if IsValid(self.Owner) && IsValid(self.Owner:GetViewModel()) then
self:ResetViewModel(self.Owner:GetViewModel())
end
end
end
function SWEP:Deploy()
/*if game.SinglePlayer() then
self:CallOnClient("Deploy", "")
end*/
self.StartThrow = false
self.Throwing = false
self.ResetThrow = false
if !self.Throwing then
self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
if IsValid(self.Owner:GetViewModel()) then
self.Weapon:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
self.Weapon:SetNextSecondaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
self.NextThrow = CurTime() + self.Owner:GetViewModel():SequenceDuration()
end
if self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 && self:Clip1() <= 0 then
self.Owner:RemoveAmmo(1, self.Primary.Ammo)
self:SetClip1(self:Clip1()+1)
end
end
return true
end
function SWEP:Holster()
if game.SinglePlayer() then
self:CallOnClient("Holster", "")
end
self.StartThrow = false
self.Throwing = false
self.ResetThrow = false
if CLIENT then
self:ResetWeapon()
end
return true
end
function SWEP:OnRemove()
/*if game.SinglePlayer() then
self:CallOnClient("OnRemove", "")
end*/
/*if CLIENT then
self:ResetWeapon()
end*/
end
/*function SWEP:OnDrop()
if game.SinglePlayer() then
self:CallOnClient("OnDrop", "")
end
if IsValid(self.Weapon) then
self.Weapon:Remove()
end
end*/
function SWEP:CreateGrenade()
if IsValid(self.Owner) && IsValid(self.Weapon) then
if (SERVER) then
local ent = ents.Create("rj_plasmanade")
if !ent then return end
ent.Owner = self.Owner
ent.Inflictor = self.Weapon
ent:SetOwner(self.Owner)
local eyeang = self.Owner:GetAimVector():Angle()
local right = eyeang:Right()
local up = eyeang:Up()
if self.Tossed then
ent:SetPos(self.Owner:GetShootPos()+right*4-up*4)
else
ent:SetPos(self.Owner:GetShootPos()+right*4+up*4)
end
ent:SetAngles(self.Owner:GetAngles())
ent:SetPhysicsAttacker(self.Owner)
ent:Spawn()
local phys = ent:GetPhysicsObject()
if phys:IsValid() then
phys:SetVelocity(self.Owner:GetAimVector() * self.ThrowVel + (self.Owner:GetVelocity() * 0.75))
end
end
end
end
function SWEP:Think()
if self.Owner:KeyDown(IN_ATTACK2) then
self.ThrowVel = 700
self.Tossed = true
elseif self.Owner:KeyDown(IN_ATTACK) then
self.ThrowVel = 1500
self.Tossed = false
end
if self.StartThrow && !self.Owner:KeyDown(IN_ATTACK) && !self.Owner:KeyDown(IN_ATTACK2) && self.NextThrow < CurTime() then
self.StartThrow = false
self.Throwing = true
if self.Tossed then
self.Weapon:SendWeaponAnim(ACT_VM_SECONDARYATTACK)
else
self.Weapon:SendWeaponAnim(ACT_VM_THROW)
end
self.Owner:SetAnimation(PLAYER_ATTACK1)
self:CreateGrenade(self.Owner, self.Weapon)
self:TakePrimaryAmmo(1)
self.NextAnimation = CurTime() + self.Primary.Delay
self.ResetThrow = true
end
if self.Throwing && self.ResetThrow && self.NextAnimation < CurTime() then
if self.Owner:GetAmmoCount(self.Primary.Ammo) > 0 && self:Clip1() <= 0 then
self.Owner:RemoveAmmo(1, self.Primary.Ammo)
self:SetClip1(self:Clip1()+1)
self.Weapon:SendWeaponAnim(ACT_VM_DRAW)
if IsValid(self.Owner:GetViewModel()) then
self.NextThrow = CurTime() + self.Owner:GetViewModel():SequenceDuration()
self.Weapon:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
self.Weapon:SetNextSecondaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
end
else
self.Owner:ConCommand("lastinv")
end
self.ResetThrow = false
self.Throwing = false
end
end
function SWEP:CanPrimaryAttack()
if self.Throwing || ( self.Owner:GetAmmoCount(self.Primary.Ammo) <= 0 && self:Clip1() <= 0 ) then
return false
end
return true
end
function SWEP:PrimaryAttack()
if (!self:CanPrimaryAttack()) then return end
if !self.Throwing && !self.StartThrow then
self.StartThrow = true
self.Weapon:SendWeaponAnim(ACT_VM_PULLBACK_HIGH)
if IsValid(self.Owner:GetViewModel()) then
self.Weapon:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
self.Weapon:SetNextSecondaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
self.NextThrow = CurTime() + self.Owner:GetViewModel():SequenceDuration()
end
end
end
function SWEP:SecondaryAttack()
/*if (!self:CanPrimaryAttack()) then return end
if !self.Throwing && !self.StartThrow then
self.StartThrow = true
self.Weapon:SendWeaponAnim(ACT_VM_PULLBACK_LOW)
if IsValid(self.Owner:GetViewModel()) then
self.Weapon:SetNextPrimaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
self.Weapon:SetNextSecondaryFire(CurTime() + self.Owner:GetViewModel():SequenceDuration())
self.NextThrow = CurTime() + self.Owner:GetViewModel():SequenceDuration()
end
end*/
end
function SWEP:Reload()
end
/*function SWEP:
In ENT:Think, before self:Remove( )
Try unsetting the parent, as it sets the parent of the prop to the target it hits. It shouldn't cause the removal of the parent, but it could be a place to start debugging it.
Not many would take the time to even look through hundreds of lines of code...
Alright thanks, i will attempt to do that now.
Sorry, you need to Log In to post a reply to this thread.