Saving unlocked skins
#1

Here's the thing, I want to create a system in which you can purchase and unlock almost any skin you want, but I have no idea how will I be able to save the unlocked skin data, storing the data ingame would most likely be with an array or something, but how exactly should I save without creating thousands of variables? Is it possible with MySQL? Or is it better with .ini files or something?
Reply
#2

Here is something you can try. Create a table called skins. Add two columns, userid, skinid, purcahsed. When someone unlocks a skin, Add a new entry to the table and set the purchased to false. When he purchases it, Set the purchased to true. When you want to read data, You can select * from skins where userid = `playeruserid` and then store it in an array.
Reply
#3

You can create an array as you said
Код:
#define MAX_SKINS 312
new unlockedSkin[MAX_PLAYERS][MAX_SKINS]; //This is meant to be a string
And then set it to 1 if it's unlocked and to 0 if it's not
Код:
unlockedSkin[playerid][SkinID] = '1'; //unlocked keep in mind we're using a string
unlockedSkin[playerid][SkinID] = '0'; //locked keep in mind we're using a string
Then you can use either MySQL or INI, depends on what you're server is using.
For MySQL you have to create a Column, let's say
Код:
unlockedSkin |  VARCHAR(312)
Why 312?
Because that's the number of skin available.
Reply
#4

Hmm, maybe. It was something I had in mind. I'm guessing mysql will have no problems storing this much skin data if lots of players are going to have lots of skins unlocked.
Reply
#5

If you're talking about my suggestion then you are right, mysql won't have any problem storing that information and it's easy to manipulate.
Reply
#6

Quote:
Originally Posted by Aly
Посмотреть сообщение
If you're talking about my suggestion then you are right, mysql won't have any problem storing that information and it's easy to manipulate.
I guess so, alright, thank you both for this consultation and suggestions.
Reply
#7

312 Bytes string for all players, rly ?

PHP код:
/*
IsTogglePlayerSkin(playerid,skinid);
TogglePlayerSkin(playerid,skinid,toggle); //toggle 0/1
*/
new unlockedSkin[MAX_PLAYERS][GetConfigSize(312)]; //real size MAX_PLAYERS * 10
#define IsTogglePlayerSkin(%0,%1)        IsToggleConfigInformation(unlockedSkin[(%0)],(%1))
#define TogglePlayerSkin(%0,%1,%2)        ToggleConfigInformation(unlockedSkin[(%0)],(%1),(%2))
// mysql/ini data store
//0 - 9
for(new 0GetConfigSize(312); i++){
    
//get or save unlockedSkin[playerid][i]

10 x 4 Bytes integer values vs 312 Bytes String

BitFunctions:
https://sampforum.blast.hk/showthread.php?tid=591223
Reply
#8

Wow, a whole 1.2 megabytes for a 1000 player server. /s Seriously, trade off memory for increased speed rather than the other way around. It's not like you're pressed for space or anything. I use bitflags and char arrays sometimes as well but I'm not going to bother with anything else

As far as I'm concerned, DarkSkull's method is still the best approach. Aly's approach may work too but it violates 1NF which states that each attribute may only contain exactly one atomic (indivisible) value.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)