ownable skins
#2

ok i have done this myself and it works ill post the code just in case anyone needs it

PHP код:
new DBSkinDB;
enum sInfo
{
    
sID,
    
sOwnerID,
    
sOwnerName[24]
}
new 
SkinInfo[MAX_PLAYERS][sInfo]; 
//gamemodeinit
PHP код:
    if ((SkinDB db_open("skins.db")) == DB0)
    {
        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(Querysizeof 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(SkinDBQuery);
    }
    if(
SkinInfo[playerid][sID] != -1)
    {
        
SetPlayerSkin(playeridSkinInfo[playerid][sID]);
    } 
// onplayerrequestspawn
PHP код:
    new Query[256];
    new 
DBResult:Result;
    
format(Querysizeof(Query), "SELECT skinid FROM skins WHERE skinid = %d"GetPlayerSkin(playerid));
    
Result db_query(SkinDBQuery);
    if(
db_num_rows(Result))
    {
        
GameTextForPlayer(playerid,"~r~ This skin is owned!"50005);
        
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], DBResultResult;
    
format(Querysizeof Query"SELECT * FROM skins WHERE ownername = '%q' LIMIT 1"GetName(playerid));
    
Result db_query(SkinDBQuery);
    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
Reply


Messages In This Thread
ownable skins - by SalmaN97 - 25.10.2018, 17:43
Re: ownable skins - by SalmaN97 - 25.10.2018, 18:51
Re: ownable skins - by AmirSavand - 25.10.2018, 21:28

Forum Jump:


Users browsing this thread: 1 Guest(s)