Are adding a 200 columns can finish negative for server working (I guess yes)? So if yes, it is some another way to do save & load, is a player did buy skin?
Save them in rows, not columns.
Table account
Id | Nickname | ...
Table skins
AccountId | SkinModel
Then do something with it:
local skins = [], q = QuerySQL( db, "SELECT * FROM SkinModel WHERE `AccountId` = '" + accountId + "'" );
while ( GetSQLColumnData( q, 1 ) )
{
skins.push( GetSQLColumnData( q, 1 ) );
}
FreeSQLQuery( q );
if ( skins.find( modelid )) {
// bought
} else {
// not bought
}
Untested.
If you're really lazy you can even save them using nicknames instead of account IDs. It's just a bit more ugly.
Ok, thanks, but now i have a next problem with arrays/tables. How can I add some skin models in one array/table?
Because i can't use (I guess yes) something like this
Skins <- array(GetMaxPlayers(),SkinModel1,SkinModel2,...);
Because I need to a specific player, not all.
function onScriptLoad(){
Skins <- array(100,[]);
}
function onPlayerJoin( player ){
Skins[ player,ID ].push( SkinModel1, SkinModel2 );
}
Untested :P
Following one has been tested:
function onScriptLoad(){
Skins <- array(100,null);
}
function onPlayerJoin( player ){
Skins[ player.ID ] = [];
Skins[ player.ID ].push( SkinModel1, SkinModel2 );
}[/
Thanks, this is eaiser than I think.
My test code:
Skins <- array(GetMaxPlayers(),[]);
function onScriptLoad()
{
Skins[0].push(100);
Skins[0].push(101);
if (Skins[0].find(100) != null) print("Yes!");
else print("No!");
if (Skins[0].find(101) != null) print("Yes!");
else print("No!");
if (Skins[0].find(102) != null) print("Yes!");
else print("No!");
return 1;
}
And console:
[SCRIPT] Yes!
[SCRIPT] Yes!
[SCRIPT] No!
You can setup a foreach loop too!
I have a problem...
Skina <- array(GetMaxPlayers(),[]);
Skina[0].push(0);
Skina[1].push(1);
Skina[0].push(2);
Skina[1].push(3);
foreach (ids, ska in Skina[1])
{
print(ids+","+ska);
}
foreach (ide, skb in Skina[0])
{
print(ide+","+skb);
}
print("another script");
if (Skina[0].find(0) != null) print("Yes!");
else print("No!");
if (Skina[0].find(1) != null) print("Yes!");
else print("No!");
if (Skina[0].find(2) != null) print("Yes!");
else print("No!");
if (Skina[0].find(3) != null) print("Yes!");
else print("No!");
if (Skina[1].find(0) != null) print("Yes!");
else print("No!");
if (Skina[1].find(1) != null) print("Yes!");
else print("No!");
if (Skina[1].find(2) != null) print("Yes!");
else print("No!");
if (Skina[1].find(3) != null) print("Yes!");
else print("No!");
print:
[SCRIPT] 0,0
[SCRIPT] 1,1
[SCRIPT] 2,2
[SCRIPT] 3,3
[SCRIPT] 0,0
[SCRIPT] 1,1
[SCRIPT] 2,2
[SCRIPT] 3,3
[SCRIPT] another script
[SCRIPT] Yes!
[SCRIPT] Yes!
[SCRIPT] Yes!
[SCRIPT] Yes!
[SCRIPT] Yes!
[SCRIPT] Yes!
[SCRIPT] Yes!
[SCRIPT] Yes!
This happens because
Skina <- array(GetMaxPlayers(),[]);
Is saving the reference of the same array in all the Skina slots. Any change you make in Skina[0] will also reflect to Skin[1], Skin[2], Skin[3]....Skin[100].
A dirty way to get it done is to replace(untested)
Skina <- array(GetMaxPlayers(),[]);
with
Skina <- array(GetMaxPlayers(),null);
foreach(i,val in Skina)
{
Skina[i] = [];
}
Though, you should be using a player class for this sort of thing.
Thanks for help ;) Now working ;)
This can be a lot more better done using tables or class.
Edit: Didn't notice axxo's reply.