Is there an way to get the current amout of props that an player got spawned?
[code]
hook.Add("PlayerSpawnedProp", "propCounter", function( ply, model, ent )
ply.spawnedProps = (ply.spawnedProps or 0) + 1
end)
[/code]
Sorry, need it more complex i need to count an specefic type of prop like
getPropAmout(model)
to check like if getPropAmout(model) = 5 then
print("You cant spawn theese kind of prop anymore")
ill hope thats not too much :o
[QUOTE=Spanky123;48418144]Sorry, need it more complex i need to count an specefic type of prop like
getPropAmout(model)
to check like if getPropAmout(model) = 5 then
print("You cant spawn theese kind of prop anymore")
ill hope thats not too much :o[/QUOTE]
Do you mean like... prop_physics or prop_ragdoll or the model name?
This is for the model:
[CODE]
function GetPropQuantity(sModel)
local i = 0
for k,v in ipairs(ents.FindByClass("prop_*")) do
if v:GetModel() == sModel then
i = i + 1
end
end
return i
end[/CODE]
Whereas the model type would be:
[CODE]function GetPropQuantity(sType)
return #ents.FindByClass(sType)
end[/CODE]
Where sType is either prop_physics or prop_ragdoll (or another if you want to be really specific)
Not prop_physics or ragdoll i need to count it by the model of the prop,
Like you spawn 5 chairs then you cant spawn more chairs
[QUOTE=Spanky123;48422417]Not prop_physics or ragdoll i need to count it by the model of the prop,
Like you spawn 5 chairs then you cant spawn more chairs[/QUOTE]
[code]
hook.Add("PlayerSpawnedProp", "propCounter", function( ply, model, ent )
ent.Owner = ply
end)
function GetPropQuantity(mdl, owner) -- mdl arg is model name while owner arg is the target player
local props_num = 0
for k, v in pairs(ents.FindByClass("prop_*")) do
if v:GetModel()==mdl && v.Owner == owner then
props_num = props_num + 1
end
end
end
[/code]
Thanks seems like its working :>
[editline]10th August 2015[/editline]
Okay got an error
when i do this :
if not GetPropQuantity(Prop.Model, ply) >= Prop.Limit then
i get :
[Error] attempt to compare string with boolean
[editline]10th August 2015[/editline]
[QUOTE=Abendorp;48422586][code]
hook.Add("PlayerSpawnedProp", "propCounter", function( ply, model, ent )
ent.Owner = ply
end)
function GetPropQuantity(mdl, owner) -- mdl arg is model name while owner arg is the target player
local props_num = 0
for k, v in pairs(ents.FindByClass("prop_*")) do
if v:GetModel()==mdl && v.Owner == owner then
props_num = props_num + 1
end
end
end
[/code][/QUOTE]
That function does not give me the amout of props it returns me an boolean
[lua]if not tonumber(GetPropQuantity(Prop.Model, ply)) >= tonumber(Prop.Limit) then[/lua]
if you are comparing variables like that, and they end up not being numbers, just use tonumber.
[QUOTE=Spanky123;48422620]
[editline]10th August 2015[/editline]
That function does not give me the amout of props it returns me an boolean[/QUOTE]
That's because there should be a brackets like so:
[CODE] if not (GetPropQuantity(Prop.Model, ply) >= Prop.Limit) then [/CODE]
What the code thinks you're doing is saying if !tonumber for the first part, and comparing !tonumber (which would be false) to the second tonumber for the prop limit.
Also, the GetPropQuantity modification from before doesn't return anything, it should be like this:
[CODE]hook.Add("PlayerSpawnedProp", "propCounter", function( ply, model, ent )
ent.Owner = ply
end)
function GetPropQuantity(mdl, owner) -- mdl arg is model name while owner arg is the target player
local props_num = 0
for k, v in pairs(ents.FindByClass("prop_*")) do
if v:GetModel()==mdl && v.Owner == owner then
props_num = props_num + 1
end
end
return props_num
end[/CODE]
Sorry, you need to Log In to post a reply to this thread.