• Stripping weapons when out of ammo
    9 replies, posted
So i have a molotov in my server and you keep it when your ammo is at 0 (seems legit right?) so can somebody help me with a code to strip the weapon when your ammo reaches 0. Thanks ~Cole
Is it the PERP molly glitch?
You can try something like this [lua] if self.Weapon:Clip1() == 0 then self.Owner:StripWeapon(self.Gun) end [/lua] in the primary attack function
[QUOTE=Acecool;40264231]Is it the PERP molly glitch?[/QUOTE] No, this is a molotov swep that i have and i just want it removed when you run out of ammo. (so theres no-body trading a molly with 0 ammo lol) [editline]13th April 2013[/editline] [QUOTE=Lerpaderp;40264397]You can try something like this [lua] if self.Weapon:Clip1() == 0 then self.Owner:StripWeapon(self.Gun) end [/lua] in the primary attack function[/QUOTE] Ill try it [editline]13th April 2013[/editline] [QUOTE=XxNAMExHERExX;40263690]So i have a molotov in my server and you keep it when your ammo is at 0 (seems legit right?) so can somebody help me with a code to strip the weapon when your ammo reaches 0. Thanks ~Cole[/QUOTE] -Bump- i really need this guys
[QUOTE=XxNAMExHERExX;40272814]No, this is a molotov swep that i have and i just want it removed when you run out of ammo. (so theres no-body trading a molly with 0 ammo lol) [editline]13th April 2013[/editline] Ill try it [editline]13th April 2013[/editline] -Bump- i really need this guys[/QUOTE] Why don't you explain what happened when you put Lerpaderp's perfectly functional code into the SWEP's Primary Attack function?
[QUOTE=Hyper Iguana;40272997]Why don't you explain what happened when you put Lerpaderp's perfectly functional code into the SWEP's Primary Attack function?[/QUOTE] Alright, sorry bout that, but um, this error gets spit out every time you use the weapon with his code. [CODE][Molotov Cocktail] lua/weapons/weapon_molotov_c/shared.lua:46: attempt to call method 'StripWeapon' (a nil value) 1. unknown - lua/weapons/weapon_molotov_c/shared.lua:46 [/CODE] Is this my stupid mistake? o_O?
[lua] if SERVER then if self.Weapon:Clip1() == 0 then self.Owner:StripWeapon(self.Gun) end end [/lua]
[QUOTE=Hyper Iguana;40285105][lua] if SERVER then if self.Weapon:Clip1() == 0 then self.Owner:StripWeapon(self.Gun) end end [/lua][/QUOTE] and i would put this in the primaryattack area as before? also, excuse me for being extreemly bad at lua. I just really started and i'm just starting to find my way, so thank you for being patient. and also, there is no errors but it doesn't work. I keep the weapon just as before- and here is my shared.lua [CODE][Lua] SWEP.ViewModelFOV = 75 SWEP.ViewModelFlip = false SWEP.ViewModel = "models/weapons/v_molotov.mdl" SWEP.WorldModel = "models/weapons/w_grenade.mdl" SWEP.ReloadSound = "" SWEP.Slot = 4 SWEP.SlotPos = 1 SWEP.DrawWorldModel = false SWEP.DrawViewModel = true SWEP.DrawShadow = true SWEP.HoldType = "grenade" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.Primary.ClipSize = 1 SWEP.Primary.DefaultClip = 1 SWEP.Primary.Automatic = false SWEP.Primary.Ammo = "grenade" SWEP.Secondary.ClipSize = -1 SWEP.Secondary.DefaultClip = -1 SWEP.Secondary.Automatic = false SWEP.Secondary.Ammo = "none" function SWEP:Initialize() self.Weapon:SetWeaponHoldType(self.HoldType) util.PrecacheSound("WeaponFrag.Throw") util.PrecacheModel("models/props_junk/garbage_glassbottle003a.mdl") util.PrecacheModel(self.ViewModel) util.PrecacheSound("physics/glass/glass_largesheet_break1.wav") util.PrecacheSound("physics/glass/glass_largesheet_break2.wav") util.PrecacheSound("physics/glass/glass_largesheet_break3.wav") end function SWEP:Deploy() end function SWEP:PrimaryAttack() if SERVER then if self.Weapon:Clip1() == 0 then self.Owner:StripWeapon(self.Gun) end end if !self:CanPrimaryAttack() then return end self:SetNextPrimaryFire(CurTime() + 0.5) self:SetWeaponHoldType(self.HoldType) self.Owner:EmitSound("WeaponFrag.Throw", 100, 100) self:SendWeaponAnim(ACT_VM_THROW) self.Owner:SetAnimation(PLAYER_ATTACK1) if (CLIENT) then return end local ent = ents.Create("ent_molotov_c") ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16)) ent:SetAngles(self.Owner:GetAngles()) ent:Spawn() local entobject = ent:GetPhysicsObject() entobject:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() * math.random(1500,2000)) self:TakePrimaryAmmo(1) end function SWEP:SecondaryAttack() end function SWEP:Reload() self.Weapon:DefaultReload(ACT_VM_DRAW) end function SWEP:Think() end [/Code][/lua] So anyone have any idea why this isn't working?
[lua]function SWEP:PrimaryAttack() if !self:CanPrimaryAttack() then return end self:SetNextPrimaryFire(CurTime() + 0.5) self:SetWeaponHoldType(self.HoldType) self.Owner:EmitSound("WeaponFrag.Throw", 100, 100) self:SendWeaponAnim(ACT_VM_THROW) self.Owner:SetAnimation(PLAYER_ATTACK1) if (CLIENT) then return end local ent = ents.Create("ent_molotov_c") ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16)) ent:SetAngles(self.Owner:GetAngles()) ent:Spawn() local entobject = ent:GetPhysicsObject() entobject:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() * math.random(1500,2000)) self:TakePrimaryAmmo(1) if self:Clip1() == 0 then self:Remove() end end[/lua]
[QUOTE=DeltaPhantom;40299329][lua]function SWEP:PrimaryAttack() if !self:CanPrimaryAttack() then return end self:SetNextPrimaryFire(CurTime() + 0.5) self:SetWeaponHoldType(self.HoldType) self.Owner:EmitSound("WeaponFrag.Throw", 100, 100) self:SendWeaponAnim(ACT_VM_THROW) self.Owner:SetAnimation(PLAYER_ATTACK1) if (CLIENT) then return end local ent = ents.Create("ent_molotov_c") ent:SetPos(self.Owner:EyePos() + (self.Owner:GetAimVector() * 16)) ent:SetAngles(self.Owner:GetAngles()) ent:Spawn() local entobject = ent:GetPhysicsObject() entobject:ApplyForceCenter(self.Owner:GetAimVector():GetNormalized() * math.random(1500,2000)) self:TakePrimaryAmmo(1) if self:Clip1() == 0 then self:Remove() end end[/lua][/QUOTE] Oohhh alright, stupid mistake on my side, thanks alot :)
Sorry, you need to Log In to post a reply to this thread.