SWEP:PrimaryAttack() attempt to index global 'SWEP' (a nil value)
9 replies, posted
Im using the WEAPON/PrimaryAttack
to run a function when the player shoots with his weapon.
This is how its supposed to work, example from gmod wiki
function SWEP:PrimaryAttack()
-- Make sure we can shoot first
if ( !self:CanPrimaryAttack() ) then return end
end
When i put this function in a autorun lua it gets the error that SWEP is a nil value.
Im sure this is a noob question, but do i have to define SWEP first? I tryd to use these kind of functions some time ago, functions like SWEP:Something,
and they always make the Error that SWEP is a nil value.
How do i define SWEP? If i have to define it even. I really dont know about this one.
Also, would this be correct? The sound plays when the player CAN shoot, and WHEN he actually shoots
function SWEP:PrimaryAttack()
-- Make sure we can shoot first
if ( !self:CanPrimaryAttack() ) then return end
surface.PlaySound("FightPew.mp3")
end
Well its supposed to run on every gun, that has bullets. What would i define SWEP as then?
Something like this?
local SWEP = --IDK what comes here...
yea, i do. I put in the function what i want to happen, but gmod has a error saying SWEP is a nil value
WEAPON/PrimaryAttack is only going to work on the SWEP you defined it for, not every SWEP in the game.
oh then this is not helpfull for me...i need a hook or function that runs everytime the player shoots a weapon with bullets
There's https://wiki.garrysmod.com/page/GM/EntityFireBullets, can't think of much else.
for some reason that hook doesn run when i shoot weapons. Like SMG or something
Sorry, you need to Log In to post a reply to this thread.