1. Post #1
    m0nst3rkill3r's Avatar
    February 2009
    32 Posts
    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 :D

  2. Post #2
    Lap
    Lap's Avatar
    December 2006
    523 Posts
    if !CheckLimit("_popcans") then return end

    or change sbox_max_popcans to sbox_maxpopcans

  3. Post #3
    m0nst3rkill3r's Avatar
    February 2009
    32 Posts
    weapons\can\shared.lua:42: attempt to call global 'CheckLimit' (a nil value)
    :(
    Ill Post the Full Code maybe you'll find the Error.

    //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
    

  4. Post #4
    bromvlieg's Avatar
    August 2008
    968 Posts
    i cant find the function "CheckLimit" in the code..... lol? think thats the problem since "CheckLimit" returns a nil becouse it dont exists!

  5. Post #5
    m0nst3rkill3r's Avatar
    February 2009
    32 Posts
    i cant find the function "CheckLimit" in the code..... lol? think thats the problem since "CheckLimit" returns a nil becouse it dont exists!
    :| ........ I hate my life..
    Uhm
    wait. line 42 it is. or not?

  6. Post #6
    bromvlieg's Avatar
    August 2008
    968 Posts
    :| ........ I hate my life..
    Uhm
    Dont worry, lua hates every one.

  7. Post #7
    m0nst3rkill3r's Avatar
    February 2009
    32 Posts
    Its in line 42 isnt it?
    Dont make funny answers, just help me xD Im going to freakin out >.<

  8. Post #8
    Gold Member
    Pecius's Avatar
    May 2007
    1,622 Posts
    You forgot about player entity.
    http://wiki.garrysmod.com/?title=Player.CheckLimit

  9. Post #9
    m0nst3rkill3r's Avatar
    February 2009
    32 Posts
    Uhm... I Copy Pasted the Little script. Player does not work

  10. Post #10
    Gold Member
    Pecius's Avatar
    May 2007
    1,622 Posts
    You must replace CheckLimit( "_popcans" ) with self.Owner:CheckLimit( "_popcans" ).
    There's no CheckLimit( "blah" ) there is Player:CheckLimit( "blah" ).

  11. Post #11
    m0nst3rkill3r's Avatar
    February 2009
    32 Posts
    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

  12. Post #12
    Gold Member
    Pecius's Avatar
    May 2007
    1,622 Posts
    You cant get entity owner with GetOwner() without setting it by SetOwner() so You should use self.Owner table.

  13. Post #13
    Gold Member
    Lexic's Avatar
    March 2009
    6,123 Posts
    You cant get entity owner with GetOwner() without setting it by SetOwner() so You should use self.Owner table.
    It's in a SWEP.

  14. Post #14
    m0nst3rkill3r's Avatar
    February 2009
    32 Posts
    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

  15. Post #15
    m0nst3rkill3r's Avatar
    February 2009
    32 Posts
    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:
    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) 
    
    
    Please Help me, so i can Upload my v1.2 :D

    greetings*