ownable skins
#1

hi everyone i want to make a skin buying system it is like no one can use the skin another player bought so on class selection i would not be able to spawn if i am trying to spawn with someone elses purchased skin i am planning to make this with sqlite i know it is possible but i have no idea how to do it
Reply
#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
#3

First, you need the list of available skins in a table.

Then you will make another table to reference players and their skins (player: 1, skin: 1 (which means, player 1 owns the skin 1 (id in database)))

Then if a player wants to spawn with a class, you'd simply check if player owns it buy hitting database (or store all skins in an array when user connects)

This system can be used for almost anything that players can own (weapon, houses, businesses, vehicles, skins, items, etc...)
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)