Using NW Integers to limit the spawning of an entity per steam ID

Hey guys, I’m trying to make it so that people can only spawn an entity I’ve coded once when on the server.

I use FPP, which deletes their entities after 2 minutes from disconnecting.

I’m trying to make it so that when they join, if their count of the entity is nil, set it to zero.

Then, if they try to spawn the entity through my derma menu, it checks if they have spawned any, and then let’s them spawn it or not.

I’ve been able to do this just fine using networked integers, but the way I’m doing this isn’t really going to work.

[lua]ply:SetNWInt(“Test”, 0)[/lua]

As you can see, ply is LocalPlayer, or rather the player that spawned the entity.

Here’s the problem: ply is userdata that is different each time they connect. So, if they leave, then come back before the 2 minute deletion period, they can spawn another entity because they aren’t the same ply as the original that spawned it.

I was trying to incorporate STEAM ID to track how many entities the person has spawned. Does anyone know how to do this?

This doesn’t work:
[lua]ply:SteamID():SetNWInt(“Test”, 0)[/lua]

ply:SetPData(“Test”, 0)

That saves it to a built in mysql database for your server.
Probably among the most helpful functions in GMod for saving data.

You can also check to see if the last time they got on was more than two minutes ago by doing something like…
[LUA]
hook.Add(“EntityRemoved”, “PlayerDisconnect”, function(ply)
if ply:IsPlayer() then
ply:SetPData(“LastDC”, os.time())
end
end)
hook.Add(“PlayerInitialSpawn”, “PlayerReconnect”, function(ply)
local last = ply:GetPData(“LastDC”,0)
if last+120 < os.time() --120 being the amount of seconds until entities are removed
ply:SetPData(“Entities”, 0) --reset the saved entity count.
end
end)
[/LUA]

I have the PData being reset in my ENT:OnRemove() function, which works as well I think.

Thank you!!!