Vice City: Multiplayer

VC:MP Discussion => Support => Topic started by: rww on Mar 21, 2016, 06:43 PM

Title: Save unlocked skins
Post by: rww on Mar 21, 2016, 06:43 PM
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?
Title: Re: Save unlocked skins
Post by: Thijn on Mar 21, 2016, 08:09 PM
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.
Title: Re: Save unlocked skins
Post by: rww on Mar 23, 2016, 08:29 AM
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.
Title: Re: Save unlocked skins
Post by: KAKAN on Mar 23, 2016, 01:01 PM
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 );
}[/
Title: Re: Save unlocked skins
Post by: rww on Mar 23, 2016, 02:05 PM
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!
Title: Re: Save unlocked skins
Post by: KAKAN on Mar 23, 2016, 03:45 PM
You can setup a foreach loop too!
Title: Re: Save unlocked skins
Post by: rww on Apr 11, 2016, 04:24 PM
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!
Title: Re: Save unlocked skins
Post by: aXXo on Apr 11, 2016, 09:09 PM
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.
Title: Re: Save unlocked skins
Post by: rww on Apr 11, 2016, 10:13 PM
Thanks for help ;) Now working ;)
Title: Re: Save unlocked skins
Post by: DizzasTeR on Apr 12, 2016, 04:13 AM
This can be a lot more better done using tables  or class.

Edit: Didn't notice axxo's reply.