sbox_max makes me worried :/

Hey Guys. I want a Sbox_Max Function in my Script, its a Swep
I created:

if (SERVER) then
CreateConVar(‘sbox_max_popcans’, 20)
end

and

if !CheckLimit(“popcans”) then return end

But i Get Lua Errors.
Please Help me!

greetings*
/edit:
I think its just a Simple error. But i am to Sleepy. But i cant Sleep :smiley:

if !CheckLimit("_popcans") then return end

or change sbox_max_popcans to sbox_maxpopcans

weapons\can\shared.lua:42: attempt to call global ‘CheckLimit’ (a nil value)
:frowning:
Ill Post the Full Code maybe you’ll find the Error.

[lua]
//ConCommands. Yay
local Can_Trail = CreateClientConVar(“Can_Trail”,1,false,true)
local Can_Trail_Color_r = CreateClientConVar(“Can_Trail_Color_r”,255,false,true)
local Can_Trail_Color_g = CreateClientConVar(“Can_Trail_Color_g”,255,false,true)
local Can_Trail_Color_b = CreateClientConVar(“Can_Trail_Color_b”,255,false,true)
local Can_Trail_Color_a = CreateClientConVar(“Can_Trail_Color_a”,255,false,true)
local Can_Trail_Texture = CreateClientConVar(“Can_Trail_Texture”,“trails/plasma.vmt”,false,true)
local Can_Trail_Startsize = CreateClientConVar(“Can_Trail_Startsize”,15,false,true)
local Can_Trail_Endsize = CreateClientConVar(“Can_Trail_Endsize”,1,false,true)
local Can_Trail_Lifetime = CreateClientConVar(“Can_Trail_Lifetime”,12,false,true)
local Can_Texture = CreateClientConVar(“Can_Texture”,“Can/PopCan01a.vmt”,false,true)
if (SERVER) then
CreateConVar(‘sbox_max_popcans’, 20)
end

//Swep-Configs.OBey

SWEP.Author = “Peacemaker”
SWEP.Contact = “Garrysmod.de - User peacemaker”
SWEP.Instructions = “Rightclick to Spawn a Can / Leftclick To Spawn and Wekd a Can to a Prop”
SWEP.Spawnable = “True”
SWEP.AdminSpawnable = “True”
SWEP.ViewModel = “models/weapons/v_pistol.mdl”
SWEP.WorldModel = “models/weapons/w_pistol.mdl”
SWEP.Primary.Clipsize = “-1”
SWEP.Primary.DefaultClip= “-1”
SWEP.Primary.Automatic = false
SWEP.Primary.Ammo = “none”
SWEP.Secondary.Clipsize = “-1”
SWEP.Secondary.DefaultClip= “-1”
SWEP.Secondary.Automatic = false
SWEP.Secondary.Ammo = “none”
cleanup.Register( “Can” )
//Primary Attack Function (Insert other Stupid Insider Word here)

function SWEP:PrimaryAttack(tr)
local tr = self.Owner:GetEyeTrace()
if (!SERVER) then return end

//Create Prop
local Can_Texture = Can_Texture:GetString()
if !CheckLimit("_popcans") then return end
local ent = ents.Create (“prop_physics”)
ent:SetModel (“models/props_junk/PopCan01a.mdl”)
ent:SetMaterial(Can_Texture)
ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -3 )
ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()

//Spawn ‘n’ Weld it… Have a Thankie

local weld = constraint.Weld( tr.Entity, ent, tr.PhysicsBone, 0, 0 )

//Undo Things

undo.Create( “OMFG CAN!” )
undo.AddEntity( weld )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()

// The Trail Part
local TrailColor_r = Can_Trail_Color_r:GetString()
local TrailColor_g = Can_Trail_Color_g:GetString()
local TrailColor_b = Can_Trail_Color_b:GetString()
local TrailColor_a = Can_Trail_Color_a:GetString()
local TrailTexture = Can_Trail_Texture:GetString()
local TrailStartsize = Can_Trail_Startsize:GetString()
local TrailEndsize = Can_Trail_Endsize:GetString()
local TrailLifetime = Can_Trail_Lifetime:GetString()

//Set The Trail to The Prop
if (Can_Trail:GetInt() == 1) then
local trail = util.SpriteTrail(ent,
0,
Color( TrailColor_r, TrailColor_g, TrailColor_b, TrailColor_a ),
false,
TrailStartsize,
TrailEndsize,
TrailLifetime,
1/(15+1)*0.5,
TrailTexture)
else
return false
end
end
//Primary Function End. Should Work.

//Secondary Function

function SWEP:SecondaryAttack()
local tr = self.Owner:GetEyeTrace()
if (!SERVER) then return end
//Spawn the Prop
local Can_Texture = Can_Texture:GetString()
local ent = ents.Create (“prop_physics”)
ent:SetModel (“models/props_junk/PopCan01a.mdl”)
ent:SetMaterial(Can_Texture)
ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -3 )
ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()

//Just a Spawn

//Undo Things
undo.Create( “OMFG CAN!” )
undo.AddEntity( ent )
undo.SetPlayer( self.Owner )
undo.Finish()
end
//Secondary… End

//Kill the Other not needed Functions
function SWEP:Think()
end
function SWEP:Reload()
end

//Made by peacemaker… and so on… Visit Gmod.de
//Comments Rules
//rly
[/lua]

i cant find the function “CheckLimit” in the code… lol? think thats the problem since “CheckLimit” returns a nil becouse it dont exists!

:expressionless: … I hate my life…
Uhm
wait. line 42 it is. or not?

Dont worry, lua hates every one.

Its in line 42 isnt it?
Dont make funny answers, just help me xD Im going to freakin out >.<

You forgot about player entity.

Uhm… I Copy Pasted the Little script. Player does not work

You must replace CheckLimit( “_popcans” ) with self.Owner:CheckLimit( “_popcans” ).
There’s no CheckLimit( “blah” ) there is Player:CheckLimit( “blah” ).

i just made now a fuckin shortcut
local ply = self:GetOwner()

The Script looks like:
//Create Prop
local Can_Texture = Can_Texture:GetString()
local ply = self:GetOwner()
if !ply:CheckLimit(“popcans”) then return end
ply:AddCount(“popcans”, “models/props_junk/PopCan01a.mdl”)
local ent = ents.Create (“prop_physics”)
ent:SetModel (“models/props_junk/PopCan01a.mdl”)
ent:SetMaterial(Can_Texture)
ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -3 )
ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()
now

You cant get entity owner with GetOwner() without setting it by SetOwner() so You should use self.Owner table.

It’s in a SWEP.

okay, i fixed it.
local Can_Texture = Can_Texture:GetString()
local ply = self:GetOwner()
if !ply:CheckLimit("_popcans") then return end
local ent = ents.Create (“prop_physics”)
ent:SetModel (“models/props_junk/PopCan01a.mdl”)
ent:SetMaterial(Can_Texture)
ent:SetPos( tr.HitPos + self.Owner:GetAimVector() * -3 )
ent:SetAngles( tr.HitNormal:Angle() )
ent:Spawn()
ply:AddCount("_popcans", ent)

greetings

Okay.
If Got a Problem now.
I Wrote my Full Script in a STool. Yay
Everything Works. Only the Limit does not work.
My Script looks now:
[lua]
local ply = self.Owner()
local Trace = tr.Entity
local Pos = tr.HitPos
if !ply:CheckLimit(“popcans”) then return end
local ent = ents.Create (“prop_physics”)
ent:SetModel (“models/props_junk/PopCan01a.mdl”)
ent:SetMaterial(Can_Texture)
ent:SetPos( Pos )
ent:SetAngles(tr.HitNormal:Angle())
ent:Spawn()
ent:SetSolid(SOLID_NONE)
ply:AddCount(“popcans”, ent)

[/lua]
Please Help me, so i can Upload my v1.2 :smiley:

greetings*