So I am developing a vulcan for my friend’s server and for some reason I get some errors. Im trying to put into the damagelogs after the timer has ended that it shows that he didn’t suicide but he died from a vulcan suicide.
if SERVER then
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "knife"
if CLIENT then
SWEP.PrintName = "Vulcan"
SWEP.Slot = 6
SWEP.ViewModelFlip = false
SWEP.EquipMenuData = {
type = "Weaponry ",
desc = "Shoot the fuckers"
};
SWEP.Icon = "VGUI/ttt/icon_mc_vulcan"
end
SWEP.Base = "weapon_tttbase"
SWEP.UseHands = true
SWEP.ViewModelFlip = false
SWEP.ViewModelFOV = 54
SWEP.ViewModel = "models/weapons/v_minigun.mdl"
SWEP.WorldModel = "models/weapons/w_minigun.mdl"
SWEP.DrawCrosshair = false
SWEP.Primary.Damage = 21
SWEP.Primary.ClipSize = 1000
SWEP.Primary.DefaultClip = 1000
SWEP.Primary.Automatic = true
SWEP.Primary.Delay = 0.1
SWEP.Primary.Ammo = "none"
SWEP.Primary.Recoil = 5
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Delay = 1.4
SWEP.Primary.Sound = Sound( "weapons/p90_mini/p90-1.wav" )
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy
SWEP.LimitedStock = true -- only buyable once
SWEP.WeaponID = AMMO_VULCAN
SWEP.IsSilent = true
-- Pull out faster than standard guns
SWEP.DeploySpeed = 5
function Kill( ply )
RunConsoleCommand("kill")
DamageLog( string.format( "VULCAN: %s died due to a vulcan suicide!", ply:Nick() ) )
end
timer.Create( "KillTimer", 60, 1, Kill )
SWEP.AllowDrop = false
if CLIENT then
function SWEP:Initialize()
chat.AddText(
Color(0,255,0), "[INFO]",
Color(255,0,0), "WARNING: Someone has a vulcanic eruption happening!!")
end
end
resource.AddFile("sound/weapons/p90_mini/p90-1.wav")
Also my errors:
[ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_minigun/shared.lua:58: attempt to index local 'ply' (a nil value)
1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_minigun/shared.lua:58
[lua]timer.Create( “KillTimer”, 60, 1, function( )
if ( SERVER ) then
self.Owner( ):Kill( );
DamageLog( string.format( “VULCAN: %s died due to a vulcan suicide!”, self.Owner:Nick() ) )
end
end );[/lua]
Get rid of the Kill function, anyone can bypass it by typing alias kill “say BLAH” in console.
Try putting [lua]local self.Owner() = ply[/lua] before creating the timer
then running Kill() with ply instead. But I’m not sure if that causes any difference
[ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_minigun/shared.lua:56: unexpected symbol near '.'
1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_minigun/shared.lua:0
Here is my current code:
if SERVER then
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "knife"
if CLIENT then
SWEP.PrintName = "Vulcan"
SWEP.Slot = 6
SWEP.ViewModelFlip = false
SWEP.EquipMenuData = {
type = "Weaponry ",
desc = "Shoot the fuckers"
};
SWEP.Icon = "VGUI/ttt/icon_mc_vulcan"
end
SWEP.Base = "weapon_tttbase"
SWEP.UseHands = true
SWEP.ViewModelFlip = false
SWEP.ViewModelFOV = 54
SWEP.ViewModel = "models/weapons/v_minigun.mdl"
SWEP.WorldModel = "models/weapons/w_minigun.mdl"
SWEP.DrawCrosshair = false
SWEP.Primary.Damage = 21
SWEP.Primary.ClipSize = 1000
SWEP.Primary.DefaultClip = 1000
SWEP.Primary.Automatic = true
SWEP.Primary.Delay = 0.1
SWEP.Primary.Ammo = "none"
SWEP.Primary.Recoil = 5
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Delay = 1.4
SWEP.Primary.Sound = Sound( "weapons/p90_mini/p90-1.wav" )
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy
SWEP.LimitedStock = true -- only buyable once
SWEP.WeaponID = AMMO_VULCAN
SWEP.IsSilent = true
-- Pull out faster than standard guns
SWEP.DeploySpeed = 5
local self.Owner() = ply
timer.Create( "KillTimer", 60, 1, function( )
if ( SERVER ) then
ply:Kill();
DamageLog( string.format( "VULCAN: %s died due to a vulcan suicide!", self.Owner:Nick() ) )
end
end );
SWEP.AllowDrop = false
if CLIENT then
function SWEP:Initialize()
chat.AddText(
Color(0,255,0), "[INFO]",
Color(255,0,0), "WARNING: Someone has caused a vulcan eruption!")
end
end
resource.AddFile("sound/weapons/p90_mini/p90-1.wav")
Also might as well not make the timer for CLIENT as it serves no purpose.
[lua]if ( SERVER ) then
timer.Create( “KillTimer”, 60, 1, function( )
self.Owner:Kill( );
DamageLog( string.format( “VULCAN: %s died due to a vulcan suicide!”, self.Owner:Nick() ) )
end );
end[/lua]
[ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_minigun/shared.lua:58: attempt to index global 'self' (a nil value)
1. unknown - gamemodes/terrortown/entities/weapons/weapon_ttt_minigun/shared.lua:58
Timer Failed! [KillTimer][@gamemodes/terrortown/entities/weapons/weapon_ttt_minigun/shared.lua (line 57)]
My current code:
if SERVER then
AddCSLuaFile( "shared.lua" )
end
SWEP.HoldType = "smg"
if CLIENT then
SWEP.PrintName = "Vulcan"
SWEP.Slot = 6
SWEP.ViewModelFlip = false
SWEP.EquipMenuData = {
type = "Weaponry ",
desc = "Shoot the fuckers"
};
SWEP.Icon = "VGUI/ttt/icon_mc_vulcan"
end
SWEP.Base = "weapon_tttbase"
SWEP.UseHands = true
SWEP.ViewModelFlip = false
SWEP.ViewModelFOV = 54
SWEP.ViewModel = "models/weapons/v_minigun.mdl"
SWEP.WorldModel = "models/weapons/w_minigun.mdl"
SWEP.DrawCrosshair = false
SWEP.Primary.Damage = 21
SWEP.Primary.ClipSize = 1000
SWEP.Primary.DefaultClip = 1000
SWEP.Primary.Automatic = true
SWEP.Primary.Delay = 0.1
SWEP.Primary.Ammo = "none"
SWEP.Primary.Recoil = 5
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = true
SWEP.Secondary.Ammo = "none"
SWEP.Secondary.Delay = 1.4
SWEP.Primary.Sound = Sound( "weapons/p90_mini/p90-1.wav" )
SWEP.Kind = WEAPON_EQUIP
SWEP.CanBuy = {ROLE_TRAITOR} -- only traitors can buy
SWEP.LimitedStock = true -- only buyable once
SWEP.WeaponID = AMMO_VULCAN
SWEP.IsSilent = true
-- Pull out faster than standard guns
SWEP.DeploySpeed = 5
if ( CLIENT ) then
timer.Create( "KillTimer", 60, 1, function( )
self.Owner:Kill( );
DamageLog( string.format( "VULCAN: %s died due to a vulcan suicide!", self.Owner:Nick() ) )
end );
end
SWEP.AllowDrop = false
if CLIENT then
function SWEP:Initialize()
chat.AddText(
Color(0,255,0), "[INFO]",
Color(255,0,0), "WARNING: Someone has caused a vulcan eruption!")
end
end
resource.AddFile("sound/weapons/p90_mini/p90-1.wav")
I tried both ‘if ( SERVER ) then’ and ‘if ( CLIENT ) then’
Leave it as SERVER because the CLIENT can not :Kill( )
self doesn’t exist because you aren’t calling the timer in a function and it will run as soon as the weapon code is created; not when the player has it.
You can use Initialize, or Deploy. I used deploy here. If you use initialize, remove your CLIENT tags wrapping it, and use
[lua]if ( SERVER ) then
my code
else
your client code
end[/lua]
[lua]function SWEP:Deploy()
if ( SERVER ) then
timer.Create( “KillTimer”, 60, 1, function( )
self.Owner:Kill( );
DamageLog( string.format( “VULCAN: %s died due to a vulcan suicide!”, self.Owner:Nick() ) )
end );
end
end