• Completely lost on rank based limits
    4 replies, posted
Hey all, I'm trying to make a Rank Based Prop/tool limit system, but for some reason, it let's them spawn a prop every other time when they're over the limit, and adv dupe completely kills the way I have it coded. I know it's messy, I threw it together without looking at any other code. Here's the code: [lua] PWAM.LimitedTools = {"balloon","dynamite","wheel","lamp","thruster","hoverball","emitter","spawner","turret"} PWAM.OldTimez = os.time() function PWAM.SetLimits(ply) for k,v in pairs(PWAM.LimitsTable) do if v[1] == ply:GetNetworkedString( "rank" ) then PWAM.PLimits[ply:UniqueID()].limit = {} PWAM.PLimits[ply:UniqueID()].limit["props"] = tonumber(v[2]) PWAM.PLimits[ply:UniqueID()].limit["ragdolls"] = tonumber(v[3]) PWAM.PLimits[ply:UniqueID()].limit["vehicles"] = tonumber(v[4]) PWAM.PLimits[ply:UniqueID()].limit["effects"] = tonumber(v[5]) PWAM.PLimits[ply:UniqueID()].limit["entity"] = tonumber(v[8]) PWAM.PLimits[ply:UniqueID()].limit["balloon"] = tonumber(v[6]) PWAM.PLimits[ply:UniqueID()].limit["wheel"] = tonumber(v[11]) PWAM.PLimits[ply:UniqueID()].limit["thruster"] = tonumber(v[12]) PWAM.PLimits[ply:UniqueID()].limit["hoverball"] = tonumber(v[13]) PWAM.PLimits[ply:UniqueID()].limit["dynamite"] = tonumber(v[9]) PWAM.PLimits[ply:UniqueID()].limit["lamp"] = tonumber(v[10]) PWAM.PLimits[ply:UniqueID()].limit["emitter"] = tonumber(v[14]) PWAM.PLimits[ply:UniqueID()].limit["spawner"] = tonumber(v[15]) PWAM.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(PWAM.PLimits[ply:UniqueID()]["props"]) then PWAM.PLimits[ply:UniqueID()]["props"] = 0 end if PWAM.PLimits[ply:UniqueID()]["props"] >= tonumber(PWAM.PLimits[ply:UniqueID()].limit["props"]) then umsg.Start("PlayerLimitHit", ply) umsg.String("props") umsg.End() ent:Remove() else PWAM.RaiseCount(ply,"props") return true end end function GM:PlayerSpawnRagdoll( ply, mdl) if not(PWAM.PLimits[ply:UniqueID()]["ragdolls"]) then PWAM.PLimits[ply:UniqueID()]["ragdolls"] = 0 end if PWAM.PLimits[ply:UniqueID()]["ragdolls"] >= tonumber(PWAM.PLimits[ply:UniqueID()].limit["ragdolls"]) then umsg.Start("PlayerLimitHit", ply) umsg.String("ragdolls") umsg.End() return false else PWAM.RaiseCount(ply,"ragdolls") return true end end function GM:PlayerSpawnVehicle(ply) if not(PWAM.PLimits[ply:UniqueID()]["vehicles"]) then PWAM.PLimits[ply:UniqueID()]["vehicles"] = 0 end if PWAM.PLimits[ply:UniqueID()]["vehicles"] >= tonumber(PWAM.PLimits[ply:UniqueID()].limit["vehicles"]) then umsg.Start("PlayerLimitHit", ply) umsg.String("vehicles") umsg.End() return false else PWAM.RaiseCount(ply,"vehicles") return true end end function GM:PlayerSpawnEffect(ply) if not(PWAM.PLimits[ply:UniqueID()]["effects"]) then PWAM.PLimits[ply:UniqueID()]["effects"] = 0 end if PWAM.PLimits[ply:UniqueID()]["effects"] >= tonumber(PWAM.PLimits[ply:UniqueID()].limit["effects"]) then umsg.Start("PlayerLimitHit", ply) umsg.String("effects") umsg.End() return false else PWAM.RaiseCount(ply,"effects") return true end end function GM:PlayerSpawnSENT(ply,ent) if not(PWAM.PLimits[ply:UniqueID()]["entity"]) then PWAM.PLimits[ply:UniqueID()]["entity"] = 0 end if PWAM.PLimits[ply:UniqueID()]["entity"] >= tonumber(PWAM.PLimits[ply:UniqueID()].limit["entity"]) then umsg.Start("PlayerLimitHit", ply) umsg.String("entity") umsg.End() return false else PWAM.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 PWAM.LowerCount(ply,"props") elseif string.Left(ent:GetClass(),12) == "prop_vehicle" then PWAM.LowerCount(ply,"vehicles") elseif string.Left(ent:GetClass(),4) == "sent" then PWAM.LowerCount(ply,"entity") elseif ent:GetClass() == "prop_ragdoll" then PWAM.LowerCount(ply,"ragdolls") elseif string.Left(ent:GetClass(),5) == "gmod_" then local split = string.Explode("_",ent:GetClass()) if table.HasValue(PWAM.LimitedTools,split[2]) then PWAM.LowerCount(ply,split[2]) end end end end function PWAM.RaiseCount(ply,ent) PWAM.PLimits[ply:UniqueID()][ent] = PWAM.PLimits[ply:UniqueID()][ent] + 1 end function PWAM.LowerCount(ply,ent) if PWAM.PLimits[ply:UniqueID()][ent] != 0 then PWAM.PLimits[ply:UniqueID()][ent] = PWAM.PLimits[ply:UniqueID()][ent] - 1 end end function PWAM.ChkRaise(ply,ent) if not(PWAM.PLimits[ply:UniqueID()][ent]) then PWAM.PLimits[ply:UniqueID()][ent] = 0 end if PWAM.PLimits[ply:UniqueID()][ent] >= tonumber(PWAM.PLimits[ply:UniqueID()].limit[ent]) then umsg.Start("PlayerLimitHit", ply) umsg.String(ent) umsg.End() return false else PWAM.PLimits[ply:UniqueID()][ent] = PWAM.PLimits[ply:UniqueID()][ent] + 1 print(ent.." "..PWAM.PLimits[ply:UniqueID()][ent]) PWAM.OldTimez = os.time() return true end end function GM:CanTool( ply, tr, toolmode ) self.BaseClass:CanTool( ply, tr, toolmode ) if toolmode == "duplicator" then return false end if not(table.HasValue(PWAM.LimitedTools,toolmode)) then return true end if os.time() > PWAM.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 PWAM.ChkRaise(ply,toolmode) then return true end else return false end end if PWAM.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 PWAM.ChkRaise(ply,toolmode) then return true end end end end else print("NOPEEE") end end[/lua] If you have any questions about what things are in that just ask. I'd really appreciate it if I could get this working :O
I'm not sure if this is the cause for the glitch but, in this block (from CanTool); I noticed that the first 'if' for KeyDown doesn't have an 'else' while the second KeyDown check does. [lua] 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 PWAM.ChkRaise(ply,toolmode) then return true end else return false end end if PWAM.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 PWAM.ChkRaise(ply,toolmode) then return true end end end end [/lua] I would try adding the 'else' and rearanging the top of the function or commenting it out and debugging it. But like I said, I'm not really sure if that's it or not, Lua is weird like that though.
That fixes one issue, but the problem that they can spawn props every other try is still happening. No idea how to fix it. And I took a quick peek at another limits system, and it was a LOT shorter than this O.o
Is this a gamemode... or an addon? If it's an addon, shouldn't you be using hook.Add (instead of GM:)?
... I obviously know how to code. So that was a pretty dumb question. Yes. It's set up as a gamemode.
Sorry, you need to Log In to post a reply to this thread.