How do i set prop limit per player?

Hello,

As the title says, How do i set prop limit per player(i use Assmod)

Wit kind regards,
wesleydeman

You need to have a variable stored on the player to how many props they spawn and check if its greater then a certain ammt and if it is don’t spawn the prop.

I can code in C#, A little in lua.
But can someone provide me with a example and where to add it?

It would go in a serverside file such as init.lua

In C# it would be somthing like this.
i have no idea how to link this code to 1 player so the variable dont get overrided.




int props = 0;

When the player spawns a prop.
props++;

if (props > 75)
{
    (LUA)ply:notify(1,4,"You have reached the maxium amount of props")
    return;
}


[lua]
hook.Add(“PlayerSpawnProp”,“PropLimit”,function(ply)
local p = ply.props or 0
local limit = 25
if p == 25 then
ply:ChatPrint(“You hit the limit of 25 props!”)
return false
else
ply.props = p + 1
return true
end
end)
[/lua]

Thats an example of how to do it.

How do you get the players rank via assmod and a list, do you know?

Also I would read this, http://wiki.garrysmod.com/?title=LUA:For_C_Programmers

Ok that looks nice but when you remove a prop shoulden P do minus 1?

[lua]
hook.Add(“PlayerSpawnProp”,“PropLimit”,function(ply)
local p = ply.props or 0
if p == 25 then
ply:ChatPrint(“You hit the limit of 25 props!”)
return false
else
ply.props = p + 1
return true
end
end)

hook.Add(“PlayerSpawnedProp”, “SetOwner”, function(ply,m,e)
e.LimitOwner = ply
ply:ChatPrint(“You can spawn " … 25 - ply.props … " more props.”)
end)

hook.Add(“EntityRemoved”, “RemoveIt”, function(e)
if not e:GetClass() == “prop_physics” then return end
if not e.LimitOwner then return end
local o = e.LimitOwner
o.props = o.props - 1
end)
[/lua]

Forgot bout that :S

If you can get me a list of the usergroups of assmod and how to determine the players usergroup in assmod I can limit it per group. Or if you want I can limit it by SteamID.

Also, set sbox_maxprops to like 999 if you wish, it will overwrite this script.



ASS_LVL_SERVER_OWNER	        = 0
ASS_LVL_SUPER_ADMIN		= 1
ASS_LVL_ADMIN			= 2
ASS_LVL_TEMPADMIN		= 3
ASS_LVL_OPERATOR		= 4
ASS_LVL_DONATORGOLD	        = 5
ASS_LVL_DONATORSILVER	        = 6
ASS_LVL_RESPECTED		= 7
ASS_LVL_GUEST			= 10
ASS_LVL_BANNED			= 255


I dont know how to do this how to determine the players usergroup in assmod

But i found some code that maybe is to determine the playergroups(look below)



function ASS_Init_Shared()

	local PLAYER = FindMetaTable("Player")
	function PLAYER:IsSuperAdmin()		return self:GetNetworkedInt("ASS_isAdmin") <= ASS_LVL_SUPER_ADMIN	end
	function PLAYER:IsAdmin()			return self:GetNetworkedInt("ASS_isAdmin") <= ASS_LVL_ADMIN		end
	function PLAYER:IsTempAdmin()		return self:GetNetworkedInt("ASS_isAdmin") <= ASS_LVL_TEMPADMIN	end
	function PLAYER:IsOperator()		return self:GetNetworkedInt("ASS_isAdmin") <= ASS_LVL_OPERATOR	end
	function PLAYER:IsDonatorGold()		return self:GetNetworkedInt("ASS_isAdmin") <= ASS_LVL_DONATORGOLD	end
	function PLAYER:IsDonatorSilver()	return self:GetNetworkedInt("ASS_isAdmin") <= ASS_LVL_DONATORSILVER	end
	function PLAYER:IsRespected()		return self:GetNetworkedInt("ASS_isAdmin") <= ASS_LVL_RESPECTED	end
	function PLAYER:IsRespected()		return self:GetNetworkedInt("ASS_isAdmin") <= ASS_LVL_RESPECTED	end
	function PLAYER:IsPremium()			return self:GetNetworkedInt("ASS_isAdmin") == ASS_LVL_DONATORGOLD end

	function PLAYER:IsGuest()	return self:GetNetworkedInt("ASS_isAdmin") >= ASS_LVL_GUEST && self:GetNetworkedInt("ASS_isAdmin") < ASS_LVL_BANNED end
	function PLAYER:IsUnwanted()	return self:GetNetworkedInt("ASS_isAdmin") >= ASS_LVL_BANNED end

	function PLAYER:GetLevel()		return self:GetNetworkedInt("ASS_isAdmin")						end
	function PLAYER:HasLevel(n)		return self:GetNetworkedInt("ASS_isAdmin") <= n						end
	function PLAYER:IsBetterOrSame(PL2)	return self:GetNetworkedInt("ASS_isAdmin") <= PL2:GetNetworkedInt("ASS_isAdmin")	end
	function PLAYER:GetTAExpiry(n)		return self:GetNetworkedFloat("ASS_tempAdminExpiry")	end
	function PLAYER:AssId()		return self:GetNetworkedString("ASS_AssID")	end
	PLAYER = nil

end




function LevelToString( LEVEL, TIME )

	    if (LEVEL <= ASS_LVL_SERVER_OWNER) then					return "Owner";
	elseif (LEVEL <= ASS_LVL_SUPER_ADMIN) then				return "Super Admin";
	elseif (LEVEL <= ASS_LVL_ADMIN) then					return "Admin";
	elseif (LEVEL <= ASS_LVL_TEMPADMIN) then				if (TIME) then return "Admin for " .. TIME else return "Temp Admin" end
	elseif (LEVEL <= ASS_LVL_OPERATOR) then					return "Operator"
	elseif (LEVEL <= ASS_LVL_DONATORGOLD) then				return "Donator Gold"
	elseif (LEVEL <= ASS_LVL_DONATORSILVER) then			return "Donator Silver"
	elseif (LEVEL <= ASS_LVL_RESPECTED) then				return "Respected"
	elseif (LEVEL >= ASS_LVL_GUEST && LEVEL < ASS_LVL_BANNED) then		return "Guest"
	else
		return "Banned";	
	end
end


Try this.

[lua]
local proplim = {}
proplim[0] = 100 – Owner
proplim[1] = 75 – SuperAdmin
proplim[2] = 50 – Admin
proplim[3] = 40 – TempAdmin
proplim[4] = 30 – Operator
proplim[5] = 25 – GoldDonator
proplim[6] = 20 – SilverDonator
proplim[7] = 15 – Respected
proplim[10] = 10 – Guest
proplim[255] = 0 – Banned

hook.Add(“PlayerSpawnProp”,“PropLimit”,function(ply)
local p = ply.props or 0
if p == proplim[ply:GetLevel()] then
ply:ChatPrint(“You hit the limit of “…proplim[ply:GetLevel()]…” props!”)
return false
else
ply.props = p + 1
return true
end
end)

hook.Add(“PlayerSpawnedProp”, “SetOwner”, function(ply,m,e)
e.LimitOwner = ply
ply:ChatPrint(“You can spawn " … proplim[ply:GetLevel()] - ply.props … " more props.”)
end)

hook.Add(“EntityRemoved”, “RemoveIt”, function(e)
if not e:GetClass() == “prop_physics” then return end
if not e.LimitOwner then return end
local o = e.LimitOwner
o.props = o.props - 1
end)
[/lua]

Untested, I don’t have AssMod.

garrysmod/lua/autorun/server/proplimit.lua
Is this correct ?
The code is in proplimit.lua

Yup.

Ok i have setted the limit for owner to 5.
I spawned 5 props then i want to do another one it says you have reached the limit of 5 props.
I deleted them all but it still says reached limit. I think something is going wrong in the code from doing minus from local p.
(But its working with assmod)



lua_run local meta = FindMetaTable("Player") function meta:GetLevel() return 10 end


I ran that first in console.

[lua]
local proplim = {}
proplim[0] = 100 – Owner
proplim[1] = 75 – SuperAdmin
proplim[2] = 50 – Admin
proplim[3] = 40 – TempAdmin
proplim[4] = 30 – Operator
proplim[5] = 25 – GoldDonator
proplim[6] = 20 – SilverDonator
proplim[7] = 15 – Respected
proplim[10] = 10 – Guest
proplim[255] = 0 – Banned

hook.Add(“PlayerSpawnProp”,“PropLimit”,function(ply)
local p = ply.props or 0
if p == proplim[ply:GetLevel()] then
ply:ChatPrint(“You hit the limit of “…proplim[ply:GetLevel()]…” props!”)
return false
else
ply.props = p + 1
return true
end
end)

hook.Add(“PlayerSpawnedProp”, “SetOwner”, function(ply,m,e)
e.LimitOwner = ply
ply:ChatPrint(“You can spawn " … proplim[ply:GetLevel()] - ply.props … " more props.”)
end)

hook.Add(“EntityRemoved”, “RemoveIt”, function(e)
if not e:GetClass() == “prop_physics” then return end
if not e.LimitOwner then return end
local o = e.LimitOwner
o.props = o.props - 1
end)
[/lua]

I then ran that via luapad.

I spawned 5 props, removed them spawned 10 more and it cut me off.

Short: Worked fine for me. Post the exact code you are using.

Also



You hit the limit of 20 props!
You hit the limit of 20 props!
Prop undone
Prop undone
Prop undone
You can spawn 2 more props.
You can spawn 1 more props.
You can spawn 0 more props.
You hit the limit of 20 props!
You hit the limit of 20 props!


  • Thats my console after I use the script after a bit.

:open_mouth: i diddent get that from the console prop undone XD



hook.Add("PlayerSpawnProp","PropLimit",function(ply)
 
    local proplim = {}
    proplim[0] = 5 -- Owner
    proplim[1] = 75 -- SuperAdmin
    proplim[2] = 50 -- Admin
    proplim[3] = 40 -- TempAdmin
    proplim[4] = 30 -- Operator
    proplim[5] = 25 -- GoldDonator
    proplim[6] = 20 -- SilverDonator
    proplim[7] = 15 -- Respected
    proplim[10] = 10 -- Guest
    proplim[255] = 0 -- Banned
    
    local p = ply.props or 0
    if p == proplim[ply:GetLevel()] then
        ply:ChatPrint("You hit the limit of "..proplim[ply:GetLevel()].." props!")
        return false
    else
        ply.props = p + 1
        return true
    end
end)
 
hook.Add("PlayerSpawnedProp", "SetOwner", function(ply,m,e)
    e.LimitOwner = ply
    ply:ChatPrint("You can spawn " .. proplim[ply:GetLevel()] - ply.props .. " more props.")
end)
 
hook.Add("EntityRemoved", "RemoveIt", function(e)
    if not e:GetClass() == "prop_physics" then return end
    if not e.LimitOwner then return end
    local o = e.LimitOwner
    o.props = o.props - 1
end)


Cant a auto console command code be added that it auto runs :
lua_run local meta = FindMetaTable(“Player”) function meta:GetLevel() return 10 end

Issent it this :



RunConsoleCommand('lua_run local meta = FindMetaTable("Player") function meta:GetLevel() return 10 end') 


I ran “lua_run local meta = FindMetaTable(“Player”) function meta:GetLevel() return 10 end” because I didn’t have AssMod installed. That sets my rank to being a Guest(10).

Just use the code I have in Post #10.

ok ive been looking in my console it said this



 Prop undone 
You hit the limit of 5 props! 
You hit the limit of 5 props! 
Prop undone 
Prop undone 
Prop undone 
Prop undone 
You hit the limit of 5 props! 
You hit the limit of 5 props! 
You hit the limit of 5 props! 
You hit the limit of 5 props! 
You hit the limit of 5 props! 
You hit the limit of 5 props! 
You hit the limit of 5 props! 
You hit the limit of 5 props! 

Its saying prop undone. but when i spawn still the limit:/ Maybe because in your code its checking whats the value of local p And your doing local o minus 1

Try this then tell me you’re console.

[lua]

local proplim = {}
proplim[0] = 5 – Owner
proplim[1] = 75 – SuperAdmin
proplim[2] = 50 – Admin
proplim[3] = 40 – TempAdmin
proplim[4] = 30 – Operator
proplim[5] = 25 – GoldDonator
proplim[6] = 20 – SilverDonator
proplim[7] = 15 – Respected
proplim[10] = 10 – Guest
proplim[255] = 0 – Banned

hook.Add(“PlayerSpawnProp”,“PropLimit”,function(ply)

local p = ply.props or 0
if p == proplim[ply:GetLevel()] then
    ply:ChatPrint("You hit the limit of "..proplim[ply:GetLevel()].." props!")
    return false
else
    ply.props = p + 1
    return true
end

end)

hook.Add(“PlayerSpawnedProp”, “SetOwner”, function(ply,m,e)
e.LimitOwner = ply
ply:ChatPrint(“You can spawn " … proplim[ply:GetLevel()] - ply.props … " more props.”)
end)

hook.Add(“EntityRemoved”, “RemoveIt”, function(e)
if not e:GetClass() == “prop_physics” then return end
if not e.LimitOwner then return end
local o = e.LimitOwner
o.props = o.props - 1
print("[DEV] “…o.props…” & removed.")
end)

[/lua]



Prop undone
Prop undone
Prop undone
Prop undone
Prop undone
You hit the limit of 5 props!
You hit the limit of 5 props!
You hit the limit of 5 props!
You hit the limit of 5 props!


EntityRemoved hook isnt getting called.