• Fixing The Melee Function On This Blaster
    4 replies, posted
I'm working on some Star Wars blasters to release for my Star Wars models because [I]everyone[/I] has been asking for them since I started putting my stuff on the Workshop. So far It's been going very well. I've contacted the guy who made the "Nomad" swep and he said I could use that as a base for the blasters. The only problem I'm facing now is making the melee function work on the swep. I have it to the point where primary fire works. Secondary fire plays the animation, plays the sound, and moves the camera. It just doesn't deal damage, and it gives a timer error. It's extremely messy code because it's a lot of copy and paste from existing weapons. Here's the code for one of the weapons, once I get one working, I can get them all to work. [CODE] AddCSLuaFile(); ------------ -- Info -- ------------ SWEP.Category = "Star Wars"; SWEP.PrintName = "DC-17m"; SWEP.Author = "Chad Barrett, Charles Conard"; SWEP.Contact = "cdbarrett@gmail.com, charlesmc49@gmail.com"; SWEP.Purpose = "Usable DC-17m Blaster Rifle"; SWEP.Instructions = "Mouse 1 for Blaster bolts, Mouse 2 for Melee"; SWEP.WorldModel = "models/SGG/StarWars/weapons/RC_Weapons/w_dc-17m.mdl"; SWEP.ViewModel = "models/SGG/StarWars/weapons/RC_Weapons/v_dc-17m.mdl"; SWEP.ViewModelFOV = 64; SWEP.Slot = 2; SWEP.SlotPos = 3; SWEP.Weight = 5; SWEP.SwayScale = 1.0; SWEP.BobScale = 1.0; SWEP.AutoSwitchTo = true; SWEP.AutoSwitchFrom = true; ------------- -- Misc. -- ------------- SWEP.Spawnable = true; SWEP.AdminSpawnable = false; SWEP.BounceWeaponIcon = false ---------------------- -- Primary Fire -- ---------------------- SWEP.Primary.ClipSize = 60; SWEP.Primary.DefaultClip = 300; SWEP.Primary.Automatic = true; SWEP.Primary.Ammo = "DC-17_Blaster_Power_Pack"; SWEP.ShootSound = "weapons/RC_Weapons/wep_GEN_dc17Fire_02.wav"; SWEP.EmptySound = "weapons/RC_Weapons/wep_empty_01.wav"; SWEP.Damage = 12; SWEP.FireRate = 0.1; SWEP.EmptyFireRate = 0.2; //SWEP.RegenerateRate = 0.0; //SWEP.RegenerateDelay = 0.0; SWEP.MaxEnergy = 50; //SWEP.Spread = 0.01; ---------------------- -- Secondary Fire -- ---------------------- SWEP.Secondary.Automatic = true SWEP.Secondary.Ammo = "none" SWEP.Secondary.Delay = 0.6 local SwingSound = Sound( "weapons/RC_weapons/fol_GEN_dc17Melee_01.wav" ) local HitSound = Sound( "Flesh.ImpactHard" ) --------------------------------------- -- Recoil, Spread, and Spray -- --------------------------------------- SWEP.RecoverTime = 0.8 -- Time in seconds it takes the player to re-steady his aim after firing. -- The following variables control the overall accuracy of the gun and typically increase with each shot -- Recoil: how much the gun kicks back the player's view. SWEP.MinRecoil = 0.15 SWEP.MaxRecoil = 0.5 SWEP.DeltaRecoil = 0.15 -- The recoil to add each shot. Same deal for spread and spray. -- Spread: the width of the gun's firing cone. More spread means less accuracy. SWEP.MinSpread = 0.002 SWEP.MaxSpread = 0.05 SWEP.DeltaSpread = 0.005 -- Spray: the gun's tendancy to point in random directions. More spray means less control. SWEP.MinSpray = 0 SWEP.MaxSpray = 1.4 SWEP.DeltaSpray = 0.16 --------------------------- -- Ironsight/Scope -- --------------------------- -- IronSightsPos and IronSightsAng are model specific paramaters that tell the game where to move the weapon viewmodel in ironsight mode. SWEP.IronSightsPos = Vector (-6.1052, -14.8804, 2.65) SWEP.IronSightsAng = Vector (0, 0, 0) SWEP.IronSightZoom = 1.3 -- How much the player's FOV should zoom in ironsight mode. SWEP.UseScope = true -- Use a scope instead of iron sights. SWEP.ScopeScale = 0.4 -- The scale of the scope's reticle in relation to the player's screen size. SWEP.ScopeZooms = {8} -- The possible magnification levels of the weapon's scope. If the scope is already activated, secondary fire will cycle through each zoom level in the table. SWEP.DrawParabolicSights = false -- Set to true to draw a cool parabolic sight (helps with aiming over long distances) ------------------- -- Modifiers -- ------------------- -- Modifiers scale the gun's recoil, spread, and spray based on the player's stance SWEP.CrouchModifier = 0.7 -- Applies if player is crouching. SWEP.IronSightModifier = 0.7 -- Applies if player is in iron sight mode. SWEP.RunModifier = 1.4 -- Applies if player is moving. SWEP.JumpModifier = 1.6 -- Applies if player is in the air (jumping) -- Note: the jumping and crouching modifiers cannot be applied simultaneously //---------- NPC Weapon list.Set( "NPCWeapons", "weapon_dc-17m", "DC-17m" ); if( SERVER ) then AccessorFunc( SWEP, "fNPCMinBurst", "NPCMinBurst" ); AccessorFunc( SWEP, "fNPCMaxBurst", "NPCMaxBurst" ); AccessorFunc( SWEP, "fNPCFireRate", "NPCFireRate" ); AccessorFunc( SWEP, "fNPCMinRestTime", "NPCMinRest" ); AccessorFunc( SWEP, "fNPCMaxRestTime", "NPCMaxRest" ); resource.AddFile( "models/SGG/StarWars/weapons/RC_Weapons/w_dc-17m.mdl" ); resource.AddFile( "models/SGG/StarWars/weapons/RC_Weapons/v_dc-17m.mdl" ); resource.AddFile( "materials/vgui/entities/weapon_nomad.vmt" ); resource.AddFile( "materials/nomad/glow.vmt" ); resource.AddFile( "materials/nomad/muzzle.vmt" ); resource.AddFile( "materials/nomad/scorch.vmt" ); resource.AddFile( "materials/nomad/scorch_model.vmt" ); resource.AddFile( "materials/models/weapons/v_nomad/texture4.vmt" ); resource.AddFile( "materials/models/weapons/v_nomad/texture5.vmt" ); resource.AddFile( "materials/models/weapons/v_nomad/v_smg1_sheet.vmt" ); resource.AddFile( "materials/models/weapons/w_nomad/smg_crosshair.vmt" ); resource.AddFile( "materials/models/weapons/w_nomad/w_smg2.vmt" ); resource.AddFile( "sound/nomad/whiz.wav" ); resource.AddFile( "sound/nomad/shoot.wav" ); SWEP.tblSounds = {} SWEP.tblSounds["Hit"] = {"physics/imp_GEN_cc_hitByMelee_01.wav", "physics/imp_GEN_cc_hitByMelee_02.wav", "physics/imp_GEN_cc_hitByMelee_03.wav", "physics/imp_GEN_cc_hitByMelee_04.wav", "physics/imp_GEN_cc_hitByMelee_05.wav"} SWEP.tblSounds["HitBod"] = {"physics/flesh/imp_GEN_bloodSplat_01.wav", "physics/flesh/imp_GEN_bloodSplat_02.wav", "physics/flesh/imp_GEN_bloodSplat_03.wav", "physics/flesh/imp_GEN_bloodSplat_04.wav"} SWEP.tblSounds["Miss"] = {"weapons/RC_weapons/wep_GEN_swing_01.wav", "weapons/RC_weapons/wep_GEN_swing_02.wav", "weapons/RC_weapons/wep_GEN_swing_03.wav"} function SWEP:SetIdleTime( time ) self.NextIdleTime = CurTime() + time; end //function SWEP:SetRegenTime( time ) // self.NextRegenTime = CurTime() + time; //end function SWEP:IdleTime() return self.NextIdleTime; end //function SWEP:RegenTime() // return self.NextRegenTime; //end function SWEP:TakeEnergy( amt ) self:SetEnergyVar( math.max( 0, self:GetEnergyVar() - amt ) ); end function SWEP:GiveEnergy( amt ) self:SetEnergyVar( math.min( self.MaxEnergy, self:GetEnergyVar() + amt ) ); end function SWEP:TakePrimaryAmmo( amt ) self:TakeEnergy( amt ); end function SWEP:ShouldDropOnDie() return false; end function SWEP:NPCShoot_Primary( pos, dir ) if( not IsValid( self.Owner ) ) then return; end self:PrimaryAttack(); end function SWEP:NPCShoot_Secondary( pos, dir ) if( not IsValid( self.Owner ) ) then return; end self:SecondaryAttack(); end function SWEP:GetCapabilities() return
[code][Star Wars Blasters] lua/weapons/weapon_dc-17m.lua:476: bad argument #1 to 'SetDamage' (number expected, got nil)[/code] [lua]dmginfo:SetDamage( self.Primary.Damage )[/lua] This seems to be your problem. SWEP:DealDamage seems to be what inflicts melee damage, and SWEP.Primary.Damage is defined nowhere in your script.
[QUOTE=_Kilburn;42073801][code][Star Wars Blasters] lua/weapons/weapon_dc-17m.lua:476: bad argument #1 to 'SetDamage' (number expected, got nil)[/code] [lua]dmginfo:SetDamage( self.Primary.Damage )[/lua] This seems to be your problem. SWEP:DealDamage seems to be what inflicts melee damage, and SWEP.Primary.Damage is defined nowhere in your script.[/QUOTE] I could love you forever, it works flawlessly now. Thank you so much! I have no idea what I'm doing so any help is greatly appreciated. Now I just need to figure out how to make the custom ammo type and make the numbers change on the display.
[QUOTE=ShoTGuNGuY49;42081360]I could love you forever, it works flawlessly now. Thank you so much! I have no idea what I'm doing so any help is greatly appreciated. Now I just need to figure out how to make the custom ammo type and make the numbers change on the display.[/QUOTE] Try [URL="http://wiki.garrysmod.com/page/game/AddAmmoType"]this[/URL] for your ammo type, and [URL="http://facepunch.com/showthread.php?t=1032378"]this[/URL] to make your own ammo display.
Hey Shotgun, how did you do it for the gun to fire laser? Trying to make the E-11 blaster
Sorry, you need to Log In to post a reply to this thread.