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.
[code]
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;
}
[/code]
[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, [url]http://wiki.garrysmod.com/?title=LUA:For_C_Programmers[/url]
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.
[code]
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
[/code]
I dont know how to do this [b]how to determine the players usergroup in assmod[/b]
But i found some code that maybe is to determine the playergroups(look below)
[code]
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
[/code]
[code]
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
[/code]
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)
[code]
lua_run local meta = FindMetaTable("Player") function meta:GetLevel() return 10 end
[/code]
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
[code]
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!
[/code]
* Thats my console after I use the script after a bit.
:O i diddent get that from the console prop undone XD
[code]
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)
[/code]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 :
[code]
RunConsoleCommand('lua_run local meta = FindMetaTable("Player") function meta:GetLevel() return 10 end')
[/code]
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
[code]
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! [/code] 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]
[code]
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!
[/code]
EntityRemoved hook isnt getting called.
Hmmm is it a code problem or my game ?
Try running it except removing with the tool gun.
So removing with Z wont work :/
But if i press Z it removes a prop and says in console Prop undone.
Cant you link that to props minus 1 ?
[editline]19th February 2011[/editline]
Now if i use remover tool.
It still does the same thing look below.
[code]
FD || Wesley removed prop_physics
FD || Wesley removed prop_physics
You hit the limit of 5 props!
FD || Wesley removed prop_physics
FD || Wesley removed prop_physics
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!
[/code]
What are you spawning?
[editline]19th February 2011[/editline]
I just noticed the error, you arent using the code I posted in post #10.
Just that standart Heli Bomb.
Ok using the code from post #10 again i will look what it wil say in the console.
[editline]19th February 2011[/editline]
[code]
You can spawn 4 more props.
You can spawn 3 more props.
You can spawn 2 more props.
Prop undone
Prop undone
Prop undone
You can spawn 1 more props.
You can spawn 0 more props.
You hit the limit of 5 props!
You hit the limit of 5 props!
[/code]
I think the problem is that its nothing removes a prop in the code if you do it ingame.
Hmmm.
EntityRemoved should be called whenever ANY entity is removed, wether it is by lua, undo or toolgun. Use the classic way of adding "print("1")" after each statement inside the EntityRemoved to see how far it goes before it stops.
I will let this over to zackkk.
I'm not pro at LUA :$
Make sure its in a serverside file. Tell me if you get any errors.
Ive tested this multiple times and its fully working.
I have it in garrysmod/lua/autorun/server/proplimit.lua
everything is workin.
Except the ent removed thing.
[editline]19th February 2011[/editline]
Ok come and test it on my server 94.75.251.55:27015
Your guest so prop limit would be 10
[editline]19th February 2011[/editline]
Ok it works now a friend changed some code.
Now another problem :$
When i use stacker it is dont added to the props variable.
A friend said.:
when stacker spawns props, make them belong to the player and increase the amount of props that they have spawned.
Sorry, you need to Log In to post a reply to this thread.