[QUESTION] Saving Variables in DarkRP?

How can I save variables in DarkRP? Because it seems really hard to do… thanks.

What do you mean? To set a var networked to every player?

player:SetDarkRPVar(“var”, “vaule”)

Like I want to make my own achievements, so that they have the same variable when they leave and come back…

Is that what you use? If so, where does it go?


player:SetDarkRPVar("var", "vaule") 

Oh sorry I misunderstood you, disregard that post

Well, how do I do it then? I want to add more variables to the saving in darkrp…

You’ll have to store these in some kind of external source, ie, SQLite(sv.db), MySQL, or data files(.txt). Since DarkRP natively uses SQLite, and has MySQL built in, I’d recommend using one of those methods. Perhaps create 2 tables, one for storing all possible achievements, with perhaps a schema as simple as ID — Details, and then another table storing SteamID — Achievements, and store the IDs of the achievements in some way there. (string.Explode will help here.)

how would i start doing that

http://darkrp.googlecode.com

[lua]
player:SetPData(“10000_kills”,true);

if player:GetPData(“10000_kills”) then
print(“Good, you are the average player!”);
end
[/lua]

thats not how…

Just get the fuck out please.

You ask, I give you and answer and you complain.

You’re answer is dumb though. I would save a value called player_connect to SQLite, and each time the player joins get the value +1 it and save it, and then
[lua]
if( value == 1000 ) then print(“congratz, you have played our server to many times, you have no life fag”) end[/lua]

It was an example of using PData.

derp.

wu-
Jesus christ, you always post questions and never seem to use the wiki or even ever attempt to learn anything. What’re you trying to accomplish?

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

function P:SetVal(name,var,network)
if name && var then
self:SetPData(name,var)
if network != false then
if network == “string” or “String” then
umsg.Start(“SendString”,self)
umsg.String(var)
umsg.End()
end
if network == “Number” or “number” then
umsg.Start(“SendNum”,self)
usmg.Long(var)
umsg.End()
end
end
end
–this is basically setting pdata but being able to network it with ease.
–you can get the data back by using Player:GetPData(varname)

–Clientside
MyInfo = {}
usermessage.Hook(“SendString”,function(m)
MyInfo[m:ReadString()] = m:ReadString()
end)

usermessage.Hook(“SendNum”,function(m)
MyInfo[m:ReadLong()] = m:ReadLong() --EDIT: Don’t do it this way :V
end)

function GetInfo(info)
if MyInfo[info] then
return MyInfo[info]
end
end

A use for it

hook.Add(“PlayerSpawn”,":3",function(player)
if player:GetPData(“Fuckshitanus”) then
player:SetVal(“Fuckshitanus”, player:GetPData(“Fuckshitanus”),“Number”)
print(“Yo faggot, we found your anus.”)
else
player:SetVal("Fuckshitanus,0,“Number”)
print(“Yo faggot, we didn’t find your anus.”)
end
end)
–now it’s networked and such, you can retrieve it through a HUD if you need to. I’m not sure what you’re trying to do but this is an idea of networking the stuff so you can recieve it through the client and save shat with ease.
[/lua]
I can’t tab so yeah, also like I said, wasn’t sure so I hope this is right.