var/gender = (P.gender == "male" ? 1 : 0)
var/header = "(`Name`, `Ckey`, `Slot`, `Coords`, `Dir`, `Preview`, `Avatar`, \
`Gender`, `HP`, `MP`, `EXP`, `EXP_Next`, `Level`, `Max_HP`, `Max_MP`, \
`Melee`, `Agility`, `Spell`, `Techniques`, `Accessories`, `Spell_Points`, \
`Stat_Points`, `Class`, `PVP_Score`, `Craft_Mem`, `Checkpoint`, `Misc_Data`, `Guild`, `Guild_Rank`)"
var/coords = "[P.x];[P.y];[P.z]"
var/values = "('[P.name]','[ckey(P.key)]',[slot],'[coords]',[P.dir],\
'[encoded_preview]','[encoded_avatar]',[gender],[P.hp],[P.mp],[P.exp],[P.exp_next],[P.lvl],[P.max_hp],\
[P.max_mp],[P.melee],[P.agility],[P.spell],'[encoded_techs]','[P.write_accessories()]',\
[P.spell_points],[P.stat_points],'[P.class]',[P.pvp_score],'[list2text(P.crafting_memory, ";")]','[P.checkpoint]','[assoc2text(P.misc_data)]','None',[P.guild_rank])"
query = dbcon.NewQuery("INSERT INTO `player_savefiles` [header] VALUES [values]")
query.Execute()
Not the most efficient way to do it, certainly, but the most raw and simplistic.
Saving items is just as easy:
// Delete old entries
query = dbcon.NewQuery("SELECT * FROM `global_items` WHERE `Source`='[P.name]'")
query.Execute()
if(query.RowCount() > 0)
query = dbcon.NewQuery("DELETE FROM `global_items` WHERE `Source`='[P.name]'")
query.Execute()
for(var/obj/item/I in P.inventory)
var/I_header = "(`Source`, `Type`, `Cvars`)"
var/I_values = "('[P.name]','[I.type]','[I.write_vars()]')"
query = dbcon.NewQuery("INSERT INTO `global_items` [I_header] VALUES [I_values]")
query.Execute()
My `Cvars` row in this table serves to keep track of variables that have been overwritten in runtime. So if a user has an item that has been given a custom name, it'll be saved as "name=New Object" within `Cvars`.
[Pic] [Pic #2]
Never liked spreadsheets all that much.
Got it.
So, what you're telling me is that I can never add a new column or remove one? I always thought you could so long as the data wasn't dependent elsewhere (foreign keys and such)
I chose BYOND keys as my primary key. Because, well... BYOND keys are unique. To the best of my knowledge at least. Ckeys I believe can be duplicates sometimes I think.
That's one thing I learned in my database design course I was required to take in College two semesters ago. I made sure to keep things nice and neat.
Never learned about how to do this but it's always been talked about.
Also, I love PHPMyAdmin. I've never used Adminer. But, who knows, I may like it.
Also, could anyone provide some code for easily setting up a database that would save a users name, key, a variable and a datum that belongs to that user? Just some typical data so I could see what format would be normally used.