ok i have done this myself and it works ill post the code just in case anyone needs it
PHP код:
new DB: SkinDB;
enum sInfo
{
sID,
sOwnerID,
sOwnerName[24]
}
new SkinInfo[MAX_PLAYERS][sInfo];
//gamemodeinit
PHP код:
if ((SkinDB = db_open("skins.db")) == DB: 0)
{
print("Failed to open a connection to \"skins.db\"");
}
else
{
db_query(SkinDB, "PRAGMA synchronous = OFF");
db_query(SkinDB, "CREATE TABLE IF NOT EXISTS skins (skinid INTEGER DEFAULT -1 NOT NULL, ownerid INTEGER DEFAULT -1 NOT NULL, ownername VARCHAR(24) COLLATE NOCASE)");
}
//gamemodeexit
PHP код:
db_close(SkinDB);
//onplayerspawn
PHP код:
if(JustConnected[playerid] == true) return 1;
if(SkinInfo[playerid][sID] == -1)
{
SkinInfo[playerid][sID] = GetPlayerSkin(playerid);
SkinInfo[playerid][sOwnerID] = PlayerInfo[playerid][pID];
format(SkinInfo[playerid][sOwnerName], 24, "%s", PlayerInfo[playerid][pName]);
new Query[128];
format(Query, sizeof Query, "INSERT INTO skins (skinid, ownerid, ownername) VALUES (%d, %d, '%q')", SkinInfo[playerid][sID], SkinInfo[playerid][sOwnerID], SkinInfo[playerid][sOwnerName]);// Insert into users the name and the password. The userid gets increased automatically and the admin is by default 0 value. We don't have to escape password as the hashed output provided by Whirlpool contains only alphabet characters and numbers.
db_query(SkinDB, Query);
}
if(SkinInfo[playerid][sID] != -1)
{
SetPlayerSkin(playerid, SkinInfo[playerid][sID]);
}
// onplayerrequestspawn
PHP код:
new Query[256];
new DBResult:Result;
format(Query, sizeof(Query), "SELECT skinid FROM skins WHERE skinid = %d", GetPlayerSkin(playerid));
Result = db_query(SkinDB, Query);
if(db_num_rows(Result))
{
GameTextForPlayer(playerid,"~r~ This skin is owned!", 5000, 5);
db_free_result(Result);
return 0;
}
//in your login & register system
//register
PHP код:
SkinInfo[playerid][sID] = -1;
//login
PHP код:
LoadSkin(playerid);
JustConnected[playerid] = false;
// anywhere in script
PHP код:
stock LoadSkin(playerid)
{
new Query[82], DBResult: Result;
format(Query, sizeof Query, "SELECT * FROM skins WHERE ownername = '%q' LIMIT 1", GetName(playerid));
Result = db_query(SkinDB, Query);
if (db_num_rows(Result))
{
SkinInfo[playerid][sID] = db_get_field_assoc_int(Result, "skinid");
db_get_field_assoc(Result, "ownername", SkinInfo[playerid][sOwnerName], 24);
SkinInfo[playerid][sOwnerID] = db_get_field_assoc_int(Result, "ownerid");
}
return 1;
}
let me know if this code can be improved thanks