Hello,
im trying to write an addon to make the Silenced AWP only deal Damage at 5 Players or more...
but im getting an error
[ERROR] addons/ds_194965598/lua/weapons/weapon_ttt_awp.lua:22: attempt to index global 'SWEP' (a nil value)
1. unknown - addons/ds_194965598/lua/weapons/weapon_ttt_awp.lua:22
Timer Failed! [AWP-Damage][@addons/ds_194965598/lua/weapons/weapon_ttt_awp.lua (line 20)]
[CODE]
timer.Create( "AWP-Damage", 30, 0, function()
if #player.GetAll() < 5 then
SWEP.Primary.Damage = 0
else
SWEP.Primary.Damage = 500
end
end )
[/CODE]
this is the part of the code i changed.
before i changed it it was only
SWEP.Primary.Damage = 500
[QUOTE=Plichso;49476433]Hello,
im trying to write an addon to make the Silenced AWP only deal Damage at 5 Players or more...
but im getting an error
[ERROR] addons/ds_194965598/lua/weapons/weapon_ttt_awp.lua:22: attempt to index global 'SWEP' (a nil value)
1. unknown - addons/ds_194965598/lua/weapons/weapon_ttt_awp.lua:22
Timer Failed! [AWP-Damage][@addons/ds_194965598/lua/weapons/weapon_ttt_awp.lua (line 20)]
[CODE]
timer.Create( "AWP-Damage", 30, 0, function()
if #player.GetAll() < 5 then
SWEP.Primary.Damage = 0
else
SWEP.Primary.Damage = 500
end
end )
[/CODE]
this is the part of the code i changed.
before i changed it it was only
SWEP.Primary.Damage = 500[/QUOTE]
is this code inside of a function?
Stick this at the top of your file:
[code]local SWEP = SWEP[/code]
Correct me if im wrong, but after the swep file has been called, i dont think you can change its default variables..
You can just use a hook to check if an entity has been hit
[url]http://wiki.garrysmod.com/page/GM/PlayerShouldTakeDamage[/url]
This was happening to me last night.
Make sure your addon is inside the garrysmod/lua/weapons folder.
EDIT: Is this all your code? If not, can we see the rest?
everyone seems to be giving bad advice :\ and the op didnt even reply to my question.
but im going to go ahead and help anyways.
the timer is probably outside of a function, so put it inside of SWEP:Deploy() and rename SWEP. to self. (SWEP. is outside of functions, self. is inside)
and, why is there a timer? that doesnt make sense
[CODE]
function SWEP:Deploy()
if #player.GetAll() < 5 then
self.Primary.Damage = 0
else
self.Primary.Damage = 500
end
end
[/CODE]
[editline]8th January 2016[/editline]
[QUOTE=nulls;49478050]This was happening to me last night.
Make sure your addon is inside the garrysmod/lua/weapons folder.
EDIT: Is this all your code? If not, can we see the rest?[/QUOTE]
you dont put addons in the weapons folder, they go in the addons folder.
and look at the error message again, because he posted one
[QUOTE=GbrosMC;49485875]
you dont put addons in the weapons folder, they go in the addons folder.
and look at the error message again, because he posted one[/QUOTE]
I thought you developed your code in the lua folder, then compiled(?) your addon to a .gma file and placed it in the addons folder? I could be wrong, I've never made an addon before.
And I asked for the rest of the addon code, not an error code.
Either way, I was having this same problem a couple days ago. Dropped my SWEP in the lua/weapons folder and everything worked perfectly.
[QUOTE=nulls;49486105]I thought you developed your code in the lua folder, then compiled(?) your addon to a .gma file and placed it in the addons folder? I could be wrong, I've never made an addon before.
And I asked for the rest of the addon code, not an error code.
Either way, I was having this same problem a couple days ago. Dropped my SWEP in the lua/weapons folder and everything worked perfectly.[/QUOTE]
jesus, i told you to look at the error report because it shows you that the weapon was located in lua/weapons and not autorun
[QUOTE=GbrosMC;49488151]jesus, i told you to look at the error report because it shows you that the weapon was located in lua/weapons and not autorun[/QUOTE]
It's located under [b]addons/ds_194965598/lua/weapons[/b]
[QUOTE=nulls;49489487]It's located under [b]addons/ds_194965598/lua/weapons[/b][/QUOTE]
well gee i would have never guessed
Sorry, you need to Log In to post a reply to this thread.