Greetings all,
I've been looking into a Detective weapon that when shot at someone does one of 2 things.
-if the target is a Traitor, it kills them
-if the target is an innocent or detective, it kills the user
Now, digging around on facepunch I found a script posted by code_gs.
However, when I use my SWEP, it seems to function just fine. It does as it should, but it throws me a lua error :c I just don't understand why it throws me this error :/ Any help would be greatly appreciated!
When I shoot a traitor:
[CODE]
[ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_golddeagle/shared.lua:88: attempt to call method 'Kill' (a nil value)
1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_golddeagle/shared.lua:88[/CODE]
When I shoot an innocent:
[CODE][ERROR] gamemodes/base/entities/weapons/weapon_base/shared.lua:179: attempt to compare boolean with number
1. TakePrimaryAmmo - gamemodes/base/entities/weapons/weapon_base/shared.lua:179
2. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_golddeagle/shared.lua:95[/CODE]
[CODE]
if SERVER then
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "pistol"
if CLIENT then
SWEP.PrintName = "Golden Gun"
SWEP.Author = "TTT"
SWEP.Slot = 7
SWEP.SlotPos = 0
SWEP.EquipMenuData = {
type="Weapon",
model="models/weapons/w_pist_deagle.mdl",
desc="Shoot a traitor, instant kill.\nShoot an innocent, you die.\nNow wouldn't that be a waste?"
};
SWEP.Icon = "materials/vgui/ttt/trips_deagle.png"
end
SWEP.Base = "weapon_tttbase"
SWEP.Primary.Recoil = 1.3
SWEP.Primary.Damage = 1
SWEP.Primary.Delay = 0.25
SWEP.Primary.Cone = 0.02
SWEP.Primary.ClipSize = 1
SWEP.Primary.Automatic = true
SWEP.Primary.DefaultClip = 1
SWEP.Primary.ClipMax = 1
SWEP.Primary.Ammo = "RPG_Round"
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_DETECTIVE} -- only detectives can buy
SWEP.WeaponID = AMMO_GOLDPISTOL
SWEP.LimitedStock = true
SWEP.AmmoEnt = nil
SWEP.IsSilent = false
SWEP.ViewModel = "models/weapons/v_pist_geagle.mdl"
SWEP.WorldModel = "models/weapons/w_pist_geagle.mdl"
SWEP.Primary.Sound = Sound( "Weapon_Deagle.Single" )
SWEP.Primary.SoundLevel = 500
SWEP.IronSightsPos = Vector(1.159, 0, -1)
SWEP.IronSightsAng = Vector(0, 0, 0)
SWEP.PrimaryAnim = ACT_VM_PRIMARYATTACK
SWEP.ReloadAnim = ACT_VM_RELOAD
function SWEP:PrimaryAttack()
if not self:CanPrimaryAttack() then return end
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
local trace = util.GetPlayerTrace(self.Owner)
local tr = util.TraceLine(trace)
if tr.Entity:IsPlayer() then
if tr.Entity:IsRole(ROLE_TRAITOR) then
bullet = {}
bullet.Num = 1
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector(0, 0, 0)
bullet.Tracer = 0
bullet.Force = 3000
bullet.Damage = 4000
self.Owner:FireBullets(bullet)
self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
self:TakePrimaryAmmo(1)
self.Weapon:EmitSound(Sound( "Weapon_Deagle.Single" ))
end
if tr.Entity:IsRole(ROLE_INNOCENT) or tr.Entity:IsRole(ROLE_DETECTIVE) then
self.Owner:Kill()
self.Weapon:EmitSound(Sound( "Weapon_Deagle.Single" ))
self:TakePrimaryAmmo(1)
end
end
self.Weapon:SendWeaponAnim(ACT_VM_PRIMARYATTACK)
self:TakePrimaryAmmo(1)
self.Owner:EmitSound(Sound( "Weapon_Deagle.Single" ))
end
function SWEP:WasBought(buyer)
if IsValid(buyer) then
// buyer:GiveAmmo( 1, "RPG_Round" )
end
end[/CODE]
You can probably clean up your code here:
[code]
local trace = util.GetPlayerTrace(self.Owner)
local tr = util.TraceLine(trace)
[/code]
You can just do [URL="http://wiki.garrysmod.com/page/Player/GetEyeTrace"]GetEyeTrace()[/URL].
You're getting an error on Kill because that only exists serverside. Replace
[code]
self.Owner:Kill()
[/code]
with
[code]
if (SERVER) then
self.Owner:Kill()
end
[/code]
Also, instead of sending a bullet, you can alternatively just kill the player they are looking at, again just using Kill()
Thanks a lot Lolcats :) That helped me out immensely!
Sorry, you need to Log In to post a reply to this thread.