• First SWEP not working and can't find a solution
    3 replies, posted
I'm trying to make my first SWEP for TTT and I keep getting the error [ERROR] gamemodes/terrortown/entities/weapons/weapon_ttt_test/shared.lua:23: attempt to index global 'SWEP' (a nil value) 1. fn - gamemodes/terrortown/entities/weapons/weapon_ttt_test/shared.lua:23 2. unknown - addons/ulib/lua/ulib/shared/hook.lua:183 Thanks for helping and forgive me for my lack of GMod Lua [CODE] if SERVER then AddCSLuaFile( "shared.lua" ) end SWEP.HoldType = "pistol" weps = {"AK-47", "Deagle", "Pistol", "Glock", "Rifle", "M16", "Shotgun", "R870 Pump", "Loud and Kill", "Knife", "Mac10", "AUG"} n = 0 if CLIENT then SWEP.PrintName = "The Incinerator" SWEP.Slot = 6 SWEP.ViewModelFOV = 54 SWEP.ViewModelFlip = false SWEP.EquipMenuData = { type = "The Incinerator", desc = "1 Shot. 100 Dmg. Disguises Kill. Use Wisely." }; function KeyPressed(pl, k) if (k == IN_SPEED) then SWEP.PrintName = nil SWEP.PrintName = weps[n] n = n + 1 if n == #weps + 1 then n = 0 end end end hook.Add("KeyPress", "KeyPressedHook", KeyPressed) SWEP.Icon = "VGUI/ttt/icon_deagle.vmt" end SWEP.Base = "weapon_tttbase" SWEP.Primary.Recoil = 4 SWEP.Primary.Damage = 100 SWEP.Primary.Delay = 1.0 SWEP.Primary.Cone = 0.01 SWEP.Primary.ClipSize = 1 SWEP.Primary.Automatic = false SWEP.Primary.DefaultClip = 1 SWEP.Primary.ClipMax = 1 SWEP.Kind = WEAPON_EQUIP SWEP.CanBuy = {ROLE_TRAITOR} SWEP.LimitedStock = true SWEP.WeaponID = AMMO_FLARE SWEP.Primary.Ammo = "AR2AltFire" SWEP.UseHands = true SWEP.ViewModel = Model("models/weapons/c_357.mdl") SWEP.WorldModel = Model("models/weapons/w_pist_fiveseven.mdl") SWEP.Primary.Sound = Sound( "Weapon_USP.SilencedShot" ) SWEP.Tracer = "AR2Tracer" function SWEP:SecondaryAttack() end [/CODE]
[code]function KeyPressed(pl, k) if (k == IN_SPEED) then SWEP.PrintName = nil SWEP.PrintName = weps[n] n = n + 1 if n == #weps + 1 then n = 0 end end end hook.Add("KeyPress", "KeyPressedHook", KeyPressed)[/code] You can't access the SWEP table like that. It gets removed as soon as server starts, after actually loading the weapons. Also, what you are trying to do is a very bad idea, use multiple sweps, don't try to put all sweps into one swep.
[QUOTE=Robotboy655;44257674] Also, what you are trying to do is a very bad idea, use multiple sweps, don't try to put all sweps into one swep.[/QUOTE] No, I'm trying to change the name so it can disguise the cause of death for the player (I don't intend for this to be the final method of how I do it) Also, how should I try to change the PrintName when the player presses a certain key then? [editline]16th March 2014[/editline] Anyone else willing to help? :(
Use self.VariableName instead of SWEP.
Sorry, you need to Log In to post a reply to this thread.