• Golden Deagle Problem
    10 replies, posted
Hey, I currently try to code a golden deagle (If traitor -> instantkill, else you die. If you kill a T, you get 1 bullet) since I can't find it online anymore. The problem is, it does nothing, it doesn't kill the T instantly nor me. [CODE]function GoldenCheck(att, path, dmginfo) local ent = path.Entity if not IsValid(ent) then return end if SERVER then -- disallow if prep or post round if ent:IsPlayer() and (not GAMEMODE:AllowPVP()) then return end if ent:IsTraitor() then ent.SetHealth(0) LocalPlayer():GiveAmmo(1,"RPG_Round"); else LocalPlayer():SetHealth(0) end end end function SWEP:ShootBullet( damage, num_bullets, aimcone ) local bullet = {} bullet.Num = 1 bullet.Src = self.Owner:GetShootPos() // Source bullet.Dir = self.Owner:GetAimVector() // Dir of bullet bullet.Spread = Vector( aimcone, aimcone, 0 ) // Aim Cone bullet.Tracer = 5 // Show a tracer on every x bullets bullet.TracerName = "Tracer" // what Tracer Effect should be used bullet.Force = 1 // Amount of force to give to phys objects bullet.Damage = damage bullet.AmmoType = "RPG_Round" bullet.Callback = GoldenCheck self.Owner:FireBullets( bullet ) self:ShootEffects() end[/CODE] Thanks for help, Lg
Post full code.
[code] if SERVER then AddCSLuaFile( "shared.lua" ) end SWEP.HoldType = "pistol" if CLIENT then SWEP.PrintName = "Golden Deagle" SWEP.Author = "TTT" SWEP.Slot = 1 SWEP.SlotPos = 1 SWEP.Icon = "VGUI/ttt/icon_goldendeagle" end SWEP.Base = "weapon_tttbase" SWEP.Spawnable = true SWEP.AdminSpawnable = true SWEP.Kind = WEAPON_EQUIP SWEP.WeaponID = AMMO_DEAGLE SWEP.Primary.Ammo = "RPG_Round" -- hijack an ammo type we don't use otherwise SWEP.Primary.Recoil = 6 SWEP.Primary.Damage = 1 SWEP.Primary.Delay = 0.6 SWEP.Primary.Cone = 0.02 SWEP.Primary.ClipSize = 1 SWEP.Primary.ClipMax = 1 SWEP.Primary.DefaultClip = 1 SWEP.Primary.Automatic = true SWEP.CanBuy = {ROLE_DETECTIVE} -- only traitors can buy SWEP.LimitedStock = true -- only buyable once SWEP.HeadshotMultiplier = 4 SWEP.AutoSpawnable = true SWEP.AmmoEnt = "item_ammo_revolver_ttt" SWEP.Primary.Sound = Sound( "Weapon_Deagle.Single" ) SWEP.UseHands = true SWEP.ViewModelFlip = false SWEP.ViewModelFOV = 54 SWEP.ViewModel = "models/weapons/v_pist_geagle.mdl" SWEP.WorldModel = "models/weapons/w_pist_geagle.mdl" SWEP.IronSightsPos = Vector(-6.361, -3.701, 2.15) SWEP.IronSightsAng = Vector(0, 0, 0) function GoldenCheck(att, path, dmginfo) local ent = path.Entity if not IsValid(ent) then return end if SERVER then -- disallow if prep or post round if ent:IsPlayer() and (not GAMEMODE:AllowPVP()) then return end if ent:IsTraitor() then ent.SetHealth(0) LocalPlayer():GiveAmmo(1,"RPG_Round"); else LocalPlayer():SetHealth(0) end end end function SWEP:ShootBullet( damage, num_bullets, aimcone ) local bullet = {} bullet.Num = 1 bullet.Src = self.Owner:GetShootPos() // Source bullet.Dir = self.Owner:GetAimVector() // Dir of bullet bullet.Spread = Vector( aimcone, aimcone, 0 ) // Aim Cone bullet.Tracer = 5 // Show a tracer on every x bullets bullet.TracerName = "Tracer" // what Tracer Effect should be used bullet.Force = 1 // Amount of force to give to phys objects bullet.Damage = damage bullet.AmmoType = "RPG_Round" bullet.Callback = GoldenCheck self.Owner:FireBullets( bullet ) self:ShootEffects() end [/code]
ent.SetHealth(0) to "if SERVER then ent:Kill() end"
-snip-
[QUOTE=Robotboy655;43113525]You do realize this function isn't even called? It would explode in Lua errors otherwise.[/QUOTE] Yeah, but if it was being called that's why it wouldn't work :v:
And why doesn't it get called?
[QUOTE=Nakroma;43113717]And why doesn't it get called?[/QUOTE] It's not getting called because "bullet.Callback = GoldenCheck" isn't how you call a function
Well, it does that in the flaregun.lua, so I assumed it would work that way (im quite new to LUA). I guess self:GoldenCheck will not work either? Where do I actually get what the bullet hit?
Actually scratch that, I am a blind idiot.[code]function SWEP:ShootBullet( damage, num_bullets, aimcone ) local bullet = {} bullet.Num = 1 bullet.Src = self.Owner:GetShootPos() // Source bullet.Dir = self.Owner:GetAimVector() // Dir of bullet bullet.Spread = Vector( aimcone, aimcone, 0 ) // Aim Cone bullet.Tracer = 5 // Show a tracer on every x bullets bullet.TracerName = "Tracer" // what Tracer Effect should be used bullet.Force = 1 // Amount of force to give to phys objects bullet.Damage = damage bullet.AmmoType = "RPG_Round" bullet.Callback = function(att, path, dmginfo) local ent = path.Entity if !IsValid(ent) || !ent:IsPlayer() || CLIENT then return end -- disallow if prep or post round if !GAMEMODE:AllowPVP() then return end if ent:IsTraitor() then ent:Kill() self.Owner:GiveAmmo(1,"RPG_Round"); else self.Owner:Kill() end end self.Owner:FireBullets( bullet ) self:ShootEffects() end[/code]
Well, apparently it doesn't work at all now. I got the damage up to 30, and when I shoot people, they don't get killed but they doesn't even get damaged at all.
Sorry, you need to Log In to post a reply to this thread.