• How to get prop limit value in a lua script?
    12 replies, posted
Hello, how to get any limit values in lua script? I found a CheckLimit(string) function that return only bool but I need real value.
what limit???
You can see how the function works here: https://github.com/Facepunch/garrysmod/blob/master/garrysmod/gamemodes/sandbox/gamemode/player_extension.lua#L9-L24 And thus deduce a way to get the limit as a number.
Get the value of the cvar sbox_maxprops
Like this? if ply.isAdmin() == true then     local ConVaredPropLimit = GetConVar("sbox_maxprops")     propLimit = ConVaredPropLimit:GetInt() end It worked. By the way do anyone know how I can check the lua script with my friend? If I create a server and invite him will the script run anyways or my friend will need to get the lua script too?
If it's serverside then your friend wouldn't need to download it(cos it runs only serverside obviously), if it's clientside then you need to AddCSLuaFile it, it will be marked for download for all the joining players.
if ply.isAdmin() == true then Use method ( : ) and it is IsAdmin. case sensitive.
Okay, so putting it /lua/autorun/server/ will be enough for creating a server and inviting my friend to it?
If you put that code it will do nothing. Maybe throw the error
For what purpose do you need this convar?
This is my current code: local propLimit = 0 -- Get player's privileges and other stuff hook.Add( "PlayerSpawn", "IfPlayerIsAdmin", function( ply )     UserPrivileges = ply:IsAdmin()     if UserPrivileges then         local ConVaredPropLimit = GetConVar( "sbox_maxprops" )         propLimit = ConVaredPropLimit:GetInt()     end end ) -- Check player's privileges if not UserPrivileges then     -- Nocliping     hook.Add( "PlayerNoClip", "IsPlayerNoClipping", function( ply )         return ply:IsAdmin()     end )     -- Spawning props     hook.Add( "PlayerSpawnProp" , "PropLimit", function( ply, model )         ply.props = ply.props or {}         local count = 0         for k,v in pairs( ply.props ) do             if IsValid( v ) then                 count = count+1             end         end         if count >= propLimit then             ply:ChatPrint( "You've reached the prop limit!" )             return false         end     end )      end I see this code partially doesn't work on my friend. Namely the spawning props part. Maybe it only works for me and ignores others?
what are you doing walk through this code logically, here i'll even help you before i head off to bed [ When the player spawns, if they are an admin, then store maxprops in propLimit. If the player is not an admin (even though this is outside of scope), then: when a player tries to noclip, let them if they're an admin. when a player tries to spawn a prop, reset their prop table and prop count, then for each of the player's props, add 1 to the prop count then, if the prop count is greater than or equal to the propLimit, don't let them spawn the prop ] what are you trying to do anyway, make a prop limit? that's like a default behavior of sandbox
Sorry, I'm not really good at programming. I get confused in Gmod Lua functions. hook.Add( "PlayerNoClip", "IsPlayerNoClipping", function( ply ) return ply:IsAdmin() end ) get the same result as hook.Add( "PlayerNoClip", "IsPlayerNoClipping", function( ply ) return false end ) How I can make count variable for every player different? -- Spawning props     hook.Add( "PlayerSpawnProp" , "PropLimit", function( ply, model )         ply.props = ply.props or {}         local count = 0         for k,v in pairs( ply.props ) do             if IsValid( v ) then                 count = count+1             end         end         if count >= propLimit then             ply:ChatPrint( "You've reached the prop limit!" )             return false         end     end )
Sorry, you need to Log In to post a reply to this thread.