Addon Errors

I am trying to make a SWEP that adjusts the players jump height. When using the SWEP I get the errors posted at the bottom of this thread.

This is my code in my shared.lua:


//This makes sure clients download the file
	AddCSLuaFile() -- No arguments means include itself for download

//How heavy the SWEP is
	SWEP.Weight = 1
 
//Allow automatic switching to/from this weapon when weapons are picked up
	SWEP.AutoSwitchTo = false
	SWEP.AutoSwitchFrom = false

	SWEP.PrintName = "Jump Enhancer"
	SWEP.Slot = 1
	SWEP.SlotPos = 3
	SWEP.DrawAmmo = false
	SWEP.DrawCrosshair = false
	
	SWEP.Author = "Praesdynamite"
	SWEP.Contact = "amrcommunity.com"
	SWEP.Purpose = "Increases Jump Height"
	SWEP.Instructions = "Left click to jump higher. Right click to set to normal. "
	SWEP.Category = "Praesdynamite's Schit Scripts"
	SWEP.Spawnable = true -- Whether regular players can see it
	SWEP.AdminSpawnable = true -- Whether Admins/Super Admins can see it

	SWEP.ViewModel = "models/weapons/v_hands.mdl" -- What the player with the gravity minimizer sees
	SWEP.WorldModel = "models/weapons/w_hands.mdl" -- What other players see.
	
	//Left click information
	SWEP.Primary.ClipSize 		= -1
	SWEP.Primary.DefaultClip 	= -1
	SWEP.Primary.Ammo 			= "none"
	SWEP.Primary.Delay          = 10
	SWEP.Primary.Automatic = false
	
	//Right click stuff
	SWEP.Secondary.ClipSize = -1
	SWEP.Secondary.DefaultClip = -1
	SWEP.Secondary.Automatic = false
	SWEP.Secondary.Ammo = "none"
	
	
local GravitySound = Sound("sound/weapons/gravity minimizer/gravitychange.wav")
	
function SWEP:PrimaryAttack()
	self:SetJumpPower(1000)
	self:EmitSound(GravitySound)
end

function SWEP:SecondaryAttack()
	self:SetJumpPower(200)
	self:EmitSound(GravitySound)
end

function SWEP:Reload()
	self.PrintMessage( HUD_PRINTTALK, "This does nothing XD!" )
end


Errors: [Gravity Minimizer] lua/weapons/gravity minimizer/shared.lua:45: attempt to call method 'SetJumpPower' (a nil value)
  1. unknown - lua/weapons/gravity minimizer/shared.lua:45

[Gravity Minimizer] lua/weapons/gravity minimizer/shared.lua:55: attempt to call field 'PrintMessage' (a nil value)
  1. unknown - lua/weapons/gravity minimizer/shared.lua:55

In-game these error appear when right/left clicking to change the players jump power

I also get an error when reloading:


[Gravity Minimizer] lua/weapons/gravity minimizer/shared.lua:55: attempt to call field 'PrintMessage' (a nil value)
  1. unknown - lua/weapons/gravity minimizer/shared.lua:55

Because of these errors the functions do not work. Another thing that doesn’t seem to work is the EmitSound function, though there are no errors to do with it. Anyone have any ideas that could fix these errors.

When you use self in a SWEP:Function() method self refers to the SWEP entity. In order to get the owner, access the Owner variable, “self.Owner”, try this
[lua]//This makes sure clients download the file
AddCSLuaFile()

//How heavy the SWEP is
SWEP.Weight = 1

//Allow automatic switching to/from this weapon when weapons are picked up
SWEP.AutoSwitchTo = false
SWEP.AutoSwitchFrom = false

SWEP.PrintName = "Jump Enhancer"
SWEP.Slot = 1
SWEP.SlotPos = 3
SWEP.DrawAmmo = false
SWEP.DrawCrosshair = false

SWEP.Author = "Praesdynamite"
SWEP.Contact = "amrcommunity.com"
SWEP.Purpose = "Increases Jump Height"
SWEP.Instructions = "Right click to jump higher. Left click to set to normal"
SWEP.Category = "Praesdynamite's Schit Scripts"
SWEP.Spawnable = true -- Whether regular players can see it
SWEP.AdminSpawnable = true -- Whether Admins/Super Admins can see it

SWEP.ViewModel = "models/weapons/v_hands.mdl" -- What the player with the gravity minimizer sees
SWEP.WorldModel = "models/weapons/w_hands.mdl" -- What other players see.

//Left click information
SWEP.Primary.ClipSize 		= -1
SWEP.Primary.DefaultClip 	= -1
SWEP.Primary.Ammo 			= "none"
SWEP.Primary.Delay          = 10
SWEP.Primary.Automatic = false

//Right click stuff
SWEP.Secondary.ClipSize = -1
SWEP.Secondary.DefaultClip = -1
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = "none"

local GravitySound = Sound(“sound/weapons/gravity minimizer/gravitychange.wav”)

function SWEP:PrimaryAttack()
self.Owner:SetJumpPower(1000)
self:EmitSound(GravitySound)
end

function SWEP:SecondaryAttack()
self.Owner:SetJumpPower(200)
self:EmitSound(GravitySound)
end
[/lua]

Thank you :wink: It works!