Reset PData for one person?

Hey, I created a points system that saves. I was wondering how I would delete someone’s points? Here is my code, if you need it:

[lua]local meta = FindMetaTable( “Player” )

function meta:AddPoints( amount )
local current_points = self:GetPoints()
self:SetPoints( current_points + amount )
end

function meta:SetPoints( amount )
self:SetNetworkedInt( “Points”, amount )
self:SavePoints()
end

function meta:SavePoints()
local pointss = self:GetPoints()
self:SetPData( “points”, pointss )
end

function meta:SavePointsTXT()
file.Write( gmod.GetGamemode().Name …"/Points/"… string.gsub( self:SteamID(), “:”, “_” ) …".txt", self:GetMoneyString() )
end

function meta:TakePoints( amount )
–Add points function here
self:AddPoints( -amount )
end

function meta:GetPoints()
return self:GetNWInt( “Points” )
end

POINTS_STARTAMOUNT = 0

function SpawnFirst( pl )
local pointss2 = pl:GetPData( “points” )

if pointss2 == nil then
	pl:SetPData( "points", POINTS_STARTAMOUNT )
	pl:SetPoints( POINTS_STARTAMOUNT )
else
	pl:SetPoints( pointss2 )
end

end
hook.Add( “PlayerInitialSpawn”, “PlayerInitialSpawnn”, SpawnFirst )

function PlayerDisconnectf( pl )
pl:SavePoints()
pl:SavePointsTXT()
end

hook.Add( “PlayerDeath”, “GivePoints”, function( victim, weapon, killer )
if killer:IsPlayer() and killer~=victim then
killer:AddPoints( 1 )
end
end ) [/lua]

Here’s the source to the PData functions, making a delete data function out of these should be pretty straightforward :

http://luabin.foszor.com/code/lua/includes/extensions/player.lua#140

Thanks. Will take a look at it.

Can’t you just set the Points to 0?

That would set it to 0 no matter what. I just want to reset it back to 0, so it starts at 0 and it keeps adding 1 each kill.

Also, crazy. What you gave me uses a database, I’m not using a database.

Yes you are. PData saves to the server’s sqlite database.

Oh. So there’s like an invisible database that I can’t access?

You can access it, with sql.Query

It’s the server.db file on your server. You can use the sql library to interact with it.

To have a look inside you could use sqliteman.

sv.db :eng101:

Quit making me wrong. :frown:

Lol Crazy…

Please stop with your useless posts trying to mkae your self look smart when we all know from your threads thats not true

When you want to reset it, just set it to 0. When you don’t want to reset it, don’t.
I don’t see the problem?

Wouldn’t this work? I don’t know much about SQL, but it looks like it should.

[lua]

function meta:RemovePData( name, value )

    name = Format( "%s[%s]", self:UniqueID(), name )

    sql.Query( "DELETE FROM playerpdata WHERE infoid = " .. SQLStr(name))

end

[/lua]

You shouldn’t delete from the database if you intend to keep on using it. In fact you should not use PData at all if it’s just a regular variable you’re manipulating during the game.