• Why doesn't this SWEP work?
    2 replies, posted
[lua] // Variables that are used on both client and server SWEP.Base = "weapon_mad_base" SWEP.ViewModelFOV = 80 SWEP.ViewModel = "models/items/v_medkit2.mdl" SWEP.WorldModel = "models/items/w_medkit.mdl" SWEP.Spawnable = false SWEP.AdminSpawnable = false SWEP.Primary.Sound = Sound("items/smallmedkit1.wav") SWEP.Secondary.Sound = Sound("items/medshotno1.wav") SWEP.Primary.Recoil = 0 SWEP.Primary.Damage = 0 SWEP.Primary.NumShots = 1 SWEP.Primary.Cone = 0.075 SWEP.Primary.Delay = 1 SWEP.Primary.ClipSize = 100 // Size of a clip SWEP.Primary.DefaultClip = 100 // Default number of bullets in a clip SWEP.Primary.Automatic = false // Automatic/Semi Auto SWEP.Primary.Ammo = "Pistol" SWEP.Secondary.ClipSize = -1 // Size of a clip SWEP.Secondary.DefaultClip = -1 // Default number of bullets in a clip SWEP.Secondary.Automatic = false // Automatic/Semi Auto SWEP.Secondary.Ammo = "none" SWEP.ShellEffect = "none" // "effect_mad_shell_pistol" or "effect_mad_shell_rifle" or "effect_mad_shell_shotgun" SWEP.ShellDelay = 0 SWEP.Pistol = true SWEP.Rifle = false SWEP.Shotgun = false SWEP.Sniper = false //SWEP.RunArmOffset = Vector (0.041, 0, 5.6778) //SWEP.RunArmAngle = Vector (-17.6901, 0.321, 0) SWEP.Power = 0 /*--------------------------------------------------------- Name: SWEP:Precache() Desc: Use this function to precache stuff. ---------------------------------------------------------*/ function SWEP:Precache() util.PrecacheSound("items/smallmedkit1.wav") util.PrecacheSound("items/medshotno1.wav") end /*--------------------------------------------------------- Name: SWEP:PrimaryAttack() Desc: +attack2 has been pressed. ---------------------------------------------------------*/ cleanup.Register("Medic Kit") function SWEP:PrimaryAttack() // Holst/Deploy your fucking weapon if (not self.Owner:IsNPC() and self.Owner:KeyDown(IN_USE)) then bHolsted = !self.Weapon:GetNetworkedBool("Holsted", false) self:SetHolsted(bHolsted) self.Weapon:SetNextPrimaryFire(CurTime() + 0.3) self.Weapon:SetNextSecondaryFire(CurTime() + 0.3) self:SetIronsights(false) return end if not IsFirstTimePredicted() then return end if self.ActionDelay > CurTime() then return end self.Weapon:SetNextPrimaryFire(CurTime() + self.Primary.Delay) self.Weapon:SetNextSecondaryFire(CurTime() + self.Primary.Delay) self.ActionDelay = (CurTime() + self.Primary.Delay) self.Owner:SetAnimation(PLAYER_ATTACK1) // 3rd Person Animation if (SERVER) then self.Weapon:EmitSound(self.Secondary.Sound) end if (CLIENT) then return end local trace = self.Owner:GetEyeTrace() if trace.HitPos:Distance(self.Owner:GetShootPos()) <= 100 then local ent = self.Owner:GetEyeTrace().Entity if ((ent:IsValid())and(ent:IsPlayer() or ent:IsNPC())) then local current = ent:Health() local max = ent:GetMaxHealth() if ((current < max)and(self:Clip1() > 0)) then ent:SetHealth( current + 1 ) self:TakePrimaryAmmo(1) self.Weapon:EmitSound( self.Primary.Sound, 40, 120 ) else self.Weapon:EmitSound(self.Secondary.Sound, 40, 120 ) end end else self.Weapon:EmitSound(self.Secondary.Sound, 60, 100 ) end end /*--------------------------------------------------------- Name: SWEP:SecondaryAttack() Desc: +attack1 has been pressed. ---------------------------------------------------------*/ function SWEP:SecondaryAttack() if self.Owner:Health() >= 100 then self.Weapon:EmitSound( self.Secondary.Sound, 40, 120 ) else if(self:Clip1()>0) then self.Owner:SetHealth( self.Owner:Health() + 1 ) self.Weapon:EmitSound( self.Primary.Sound, 40, 120 ) self:TakePrimaryAmmo(1) end end self.Weapon:SetNextSecondaryFire(CurTime() + 1) end /*--------------------------------------------------------- Name: SWEP:Deploy() Desc: Whip it out. ---------------------------------------------------------*/ function SWEP:Deploy() self.Weapon:SendWeaponAnim(ACT_VM_DRAW) self.Weapon:SetNextPrimaryFire(CurTime() + self.DeployDelay) self.Weapon:SetNextSecondaryFire(CurTime() + self.DeployDelay) self.ActionDelay = (CurTime() + self.DeployDelay) return true end [/lua] It's a medkit. Yes it is based on madcow's medkit. It's supposed to be like this: Uses pistol ammo (for now) When you leftclick on someone, it takes 1 ammo and heals them 1 point. When you rightclick, it takes 1 ammo and heals you 1 point. If you can't decipher it then at least tell me it's epic fail messed up all wrong so I can stop trying to make it work.
[lua]SWEP.Base = "weapon_mad_base"[/lua] Let's start from there. Are you even using this base? If not you better use it or just remove this line and start adding in your own details.
Madcows wep base IS pretty irrelevant to this weapon because this weapon is so unconventional. This wep is really simple though, so I don' think I'd be unable to make it from scratch. So I can remove the SWEP.Base line and the Holster/Deploy code (this wep doesn't need a holster function)? I'm just afraid that it will stop working altogether if I remove the base dependency. I'm not sure what else I would have to add when I remove the base. Also, quick question: can a SWEP still have a Clip1 if it doesn't have an ammo type? If I put "none" as the ammo type, will all the clip functions be broken? I want this swep's "ammo" to be more of a single-use-only inherent property rather than actual usage of a real ammo type. How could I simulate that? [editline]11:22AM[/editline] If you don't understand what I mean, I want it to be like this: There's 100 units in the SWEP's Clip1 by default. Using the SWEP (primary or secondary firing) subtracts from Clip1. The number in Clip1 never increases, and when it reaches 0 the SWEP disappears. Or instead of using Clip1, is there some way I could create some kind of "ammo" or "remaining medical supply" variable that I could assign to the SWEP to keep track of how much more it can be used?
Sorry, you need to Log In to post a reply to this thread.