Hey all, I've been trying to code up a rank based prop and tool limit system. I saw JG_Jazzy's topic and decided to give it a go. And it turns out, I can't even get it right apparently ;P. Could anyone possibly help me out on this? Here's my code I have.
[lua]
POAM.LimitedTools = {"balloon","dynamite","wheel","lamp","thruster","hoverball","emitter","spawner","turret"}
POAM.OldTimez = os.time()
function POAM.SetLimits(ply)
for k,v in pairs(POAM.LimitsTable) do
if v[1] == ply:GetNetworkedString( "rank" ) then
POAM.PLimits[ply:UniqueID()].limit = {}
POAM.PLimits[ply:UniqueID()].limit["props"] = tonumber(v[2])
POAM.PLimits[ply:UniqueID()].limit["ragdolls"] = tonumber(v[3])
POAM.PLimits[ply:UniqueID()].limit["vehicles"] = tonumber(v[4])
POAM.PLimits[ply:UniqueID()].limit["effects"] = tonumber(v[5])
POAM.PLimits[ply:UniqueID()].limit["entity"] = tonumber(v[8])
POAM.PLimits[ply:UniqueID()].limit["balloon"] = tonumber(v[6])
POAM.PLimits[ply:UniqueID()].limit["wheel"] = tonumber(v[11])
POAM.PLimits[ply:UniqueID()].limit["thruster"] = tonumber(v[12])
POAM.PLimits[ply:UniqueID()].limit["hoverball"] = tonumber(v[13])
POAM.PLimits[ply:UniqueID()].limit["dynamite"] = tonumber(v[9])
POAM.PLimits[ply:UniqueID()].limit["lamp"] = tonumber(v[10])
POAM.PLimits[ply:UniqueID()].limit["emitter"] = tonumber(v[14])
POAM.PLimits[ply:UniqueID()].limit["spawner"] = tonumber(v[15])
POAM.PLimits[ply:UniqueID()].limit["turret"] = tonumber(v[16])
print("Done")
end
end
end
function GM:PlayerSpawnedProp( ply, model, ent )
self.BaseClass:PlayerSpawnedProp( ply, model, ent )
if not(POAM.PLimits[ply:UniqueID()]["props"]) then
POAM.PLimits[ply:UniqueID()]["props"] = 0
end
if POAM.PLimits[ply:UniqueID()]["props"] >= tonumber(POAM.PLimits[ply:UniqueID()].limit["props"]) then
umsg.Start("PlayerLimitHit", ply)
umsg.String("props")
umsg.End()
ent:Remove()
else
POAM.RaiseCount(ply,"props")
return true
end
end
function GM:PlayerSpawnRagdoll( ply, mdl)
if not(POAM.PLimits[ply:UniqueID()]["ragdolls"]) then
POAM.PLimits[ply:UniqueID()]["ragdolls"] = 0
end
if POAM.PLimits[ply:UniqueID()]["ragdolls"] >= tonumber(POAM.PLimits[ply:UniqueID()].limit["ragdolls"]) then
umsg.Start("PlayerLimitHit", ply)
umsg.String("ragdolls")
umsg.End()
return false
else
POAM.RaiseCount(ply,"ragdolls")
return true
end
end
function GM:PlayerSpawnVehicle(ply)
if not(POAM.PLimits[ply:UniqueID()]["vehicles"]) then
POAM.PLimits[ply:UniqueID()]["vehicles"] = 0
end
if POAM.PLimits[ply:UniqueID()]["vehicles"] >= tonumber(POAM.PLimits[ply:UniqueID()].limit["vehicles"]) then
umsg.Start("PlayerLimitHit", ply)
umsg.String("vehicles")
umsg.End()
return false
else
POAM.RaiseCount(ply,"vehicles")
return true
end
end
function GM:PlayerSpawnEffect(ply)
if not(POAM.PLimits[ply:UniqueID()]["effects"]) then
POAM.PLimits[ply:UniqueID()]["effects"] = 0
end
if POAM.PLimits[ply:UniqueID()]["effects"] >= tonumber(POAM.PLimits[ply:UniqueID()].limit["effects"]) then
umsg.Start("PlayerLimitHit", ply)
umsg.String("effects")
umsg.End()
return false
else
POAM.RaiseCount(ply,"effects")
return true
end
end
function GM:PlayerSpawnSENT(ply,ent)
if not(POAM.PLimits[ply:UniqueID()]["entity"]) then
POAM.PLimits[ply:UniqueID()]["entity"] = 0
end
if POAM.PLimits[ply:UniqueID()]["entity"] >= tonumber(POAM.PLimits[ply:UniqueID()].limit["entity"]) then
umsg.Start("PlayerLimitHit", ply)
umsg.String("entity")
umsg.End()
return false
else
POAM.RaiseCount(ply,"entity")
return true
end
end
function GM:EntityRemoved( ent )
self.BaseClass:EntityRemoved( ent )
local ply = ent:GetNetworkedEntity("OwnerObj")
if ply and ply:IsValid() then
print(ent:GetClass())
if ent:GetClass() == "prop_physics" then
POAM.LowerCount(ply,"props")
elseif string.Left(ent:GetClass(),12) == "prop_vehicle" then
POAM.LowerCount(ply,"vehicles")
elseif string.Left(ent:GetClass(),4) == "sent" then
POAM.LowerCount(ply,"entity")
elseif ent:GetClass() == "prop_ragdoll" then
POAM.LowerCount(ply,"ragdolls")
elseif string.Left(ent:GetClass(),5) == "gmod_" then
local split = string.Explode("_",ent:GetClass())
if table.HasValue(POAM.LimitedTools,split[2]) then
POAM.LowerCount(ply,split[2])
end
end
end
end
function POAM.RaiseCount(ply,ent)
POAM.PLimits[ply:UniqueID()][ent] = POAM.PLimits[ply:UniqueID()][ent] + 1
end
function POAM.LowerCount(ply,ent)
if POAM.PLimits[ply:UniqueID()][ent] != 0 then
POAM.PLimits[ply:UniqueID()][ent] = POAM.PLimits[ply:UniqueID()][ent] - 1
end
end
function POAM.ChkRaise(ply,ent)
if not(POAM.PLimits[ply:UniqueID()][ent]) then
POAM.PLimits[ply:UniqueID()][ent] = 0
end
if POAM.PLimits[ply:UniqueID()][ent] >= tonumber(POAM.PLimits[ply:UniqueID()].limit[ent]) then
umsg.Start("PlayerLimitHit", ply)
umsg.String(ent)
umsg.End()
return false
else
POAM.PLimits[ply:UniqueID()][ent] = POAM.PLimits[ply:UniqueID()][ent] + 1
print(ent.." "..POAM.PLimits[ply:UniqueID()][ent])
POAM.OldTimez = os.time()
return true
end
end
function GM:CanTool( ply, tr, toolmode )
self.BaseClass:CanTool( ply, tr, toolmode )
if not(table.HasValue(POAM.LimitedTools,toolmode)) then return true end
if os.time() > POAM.OldTimez then
local tr = ply:GetEyeTrace()
if( tr.Entity:GetClass() != nil) and (tr.Entity:GetClass() != "worldspawn") then
if (ply:KeyDown(IN_ATTACK2)) and (toolmode == "spawner" or toolmode == "thruster")then
return false
end
if tr.Entity:GetClass() == "gmod_"..toolmode then
if toolmode == "wheel" then
if POAM.ChkRaise(ply,toolmode) then
return true
end
else
return false
end
end
if POAM.ChkRaise(ply,toolmode) then
return true
end
else
if (ply:KeyDown(IN_ATTACK2)) then
if toolmode == "wheel" or toolmode == "thruster" then
return true
end
else
if toolmode != "spawner" then
if POAM.ChkRaise(ply,toolmode) then
return true
end
end
end
end
else
print("NOPEEE")
end
end[/lua]
It works for the most part, but it seems that when you spawn a bunch of props with duplicator, it misses a lot of them, and when you dupe sents and effects, it doesn't count them at all O.o Any help would be greatly appreciated. If you want to help over steam, my steam is SpencerRawks.
Sorry, you need to Log In to post a reply to this thread.