SQL help.
#5

This should save weapons on disconnect and load them when they connect again:

pawn Код:
#define FILTERSCRIPT

#include <a_samp>
#include <a_mysql>

#if defined FILTERSCRIPT

public OnFilterScriptInit()
{
    print("\n--------------------------------------");
    print(" Blank Filterscript by your name here");
    print("--------------------------------------\n");
    return 1;
}

public OnFilterScriptExit()
{
    return 1;
}

#else

main()
{
    print("\n----------------------------------");
    print(" Blank Gamemode by your name here");
    print("----------------------------------\n");
}

#endif

#define host ""
#define db ""
#define user ""
#define pwd ""

forward UpdateWeapons(playerid);

enum weapons {
weapon1,
weapon1ammo,
weapon2,
weapon2ammo,
weapon3,
weapon3ammo,
weapon4,
weapon4ammo,
weapon5,
weapon5ammo,
weapon6,
weapon6ammo,
weapon7,
weapon7ammo,
weapon8,
weapon8ammo,
weapon9,
weapon9ammo,
weapon10,
weapon10ammo,
weapon11,
weapon11ammo,
weapon12,
weapon12ammo,
weapon13,
weapon13ammo
}

new WeapData[MAX_PLAYERS][weapons];

stock LoadStoredWeapons(playerid)
{
    new ReceiveWeapModel[13],ReceiveWeapAmmo[13],pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,sizeof(pName));
    format(ReceiveWeapModel[0],256,"SELECT Weapon1 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[1],256,"SELECT Weapon2 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[2],256,"SELECT Weapon3 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[3],256,"SELECT Weapon4 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[4],256,"SELECT Weapon5 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[5],256,"SELECT Weapon6 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[6],256,"SELECT Weapon7 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[7],256,"SELECT Weapon8 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[8],256,"SELECT Weapon9 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[9],256,"SELECT Weapon10 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[10],256,"SELECT Weapon11 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[11],256,"SELECT Weapon12 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapModel[12],256,"SELECT Weapon13 FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[0],256,"SELECT Weapon1A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[1],256,"SELECT Weapon2A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[2],256,"SELECT Weapon3A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[3],256,"SELECT Weapon4A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[4],256,"SELECT Weapon5A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[5],256,"SELECT Weapon6A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[6],256,"SELECT Weapon7A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[7],256,"SELECT Weapon8A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[8],256,"SELECT Weapon9A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[9],256,"SELECT Weapon10A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[10],256,"SELECT Weapon11A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[11],256,"SELECT Weapon12A FROM Accounts WHERE Username = '%s';",pName);
    format(ReceiveWeapAmmo[12],256,"SELECT Weapon13A FROM Accounts WHERE Username = '%s';",pName);
    mysql_connect(host,user,db,pwd);
    WeapData[playerid][weapon1] = mysql_query(ReceiveWeapModel[0]);
    WeapData[playerid][weapon2] = mysql_query(ReceiveWeapModel[1]);
    WeapData[playerid][weapon3] = mysql_query(ReceiveWeapModel[2]);
    WeapData[playerid][weapon4] = mysql_query(ReceiveWeapModel[3]);
    WeapData[playerid][weapon5] = mysql_query(ReceiveWeapModel[4]);
    WeapData[playerid][weapon6] = mysql_query(ReceiveWeapModel[5]);
    WeapData[playerid][weapon7] = mysql_query(ReceiveWeapModel[6]);
    WeapData[playerid][weapon8] = mysql_query(ReceiveWeapModel[7]);
    WeapData[playerid][weapon9] = mysql_query(ReceiveWeapModel[8]);
    WeapData[playerid][weapon10] = mysql_query(ReceiveWeapModel[9]);
    WeapData[playerid][weapon11] = mysql_query(ReceiveWeapModel[10]);
    WeapData[playerid][weapon12] = mysql_query(ReceiveWeapModel[11]);
    WeapData[playerid][weapon13] = mysql_query(ReceiveWeapModel[12]);
    WeapData[playerid][weapon1ammo] = mysql_query(ReceiveWeapAmmo[0]);
    WeapData[playerid][weapon2ammo] = mysql_query(ReceiveWeapAmmo[1]);
    WeapData[playerid][weapon3ammo] = mysql_query(ReceiveWeapAmmo[2]);
    WeapData[playerid][weapon4ammo] = mysql_query(ReceiveWeapAmmo[3]);
    WeapData[playerid][weapon5ammo] = mysql_query(ReceiveWeapAmmo[4]);
    WeapData[playerid][weapon6ammo] = mysql_query(ReceiveWeapAmmo[5]);
    WeapData[playerid][weapon7ammo] = mysql_query(ReceiveWeapAmmo[6]);
    WeapData[playerid][weapon8ammo] = mysql_query(ReceiveWeapAmmo[7]);
    WeapData[playerid][weapon9ammo] = mysql_query(ReceiveWeapAmmo[8]);
    WeapData[playerid][weapon10ammo] = mysql_query(ReceiveWeapAmmo[9]);
    WeapData[playerid][weapon11ammo] = mysql_query(ReceiveWeapAmmo[10]);
    WeapData[playerid][weapon12ammo] = mysql_query(ReceiveWeapAmmo[11]);
    WeapData[playerid][weapon13ammo] = mysql_query(ReceiveWeapAmmo[12]);
    mysql_close();
}

stock LoadStoredWeaponInfo(playerid)
{
    LoadStoredWeapons(playerid);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon1],WeapData[playerid][weapon1ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon2],WeapData[playerid][weapon2ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon3],WeapData[playerid][weapon3ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon4],WeapData[playerid][weapon4ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon5],WeapData[playerid][weapon5ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon6],WeapData[playerid][weapon6ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon7],WeapData[playerid][weapon7ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon8],WeapData[playerid][weapon8ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon9],WeapData[playerid][weapon9ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon10],WeapData[playerid][weapon10ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon11],WeapData[playerid][weapon11ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon12],WeapData[playerid][weapon12ammo]);
    GivePlayerWeapon(playerid,WeapData[playerid][weapon13],WeapData[playerid][weapon13ammo]);
}

public OnPlayerConnect(playerid)
{
    LoadStoredWeaponInfo(playerid);
}

stock GrabWeapons(playerid)
{
    GetPlayerWeaponData(playerid,0,WeapData[playerid][weapon1],WeapData[playerid][weapon1ammo]);
    GetPlayerWeaponData(playerid,1,WeapData[playerid][weapon2],WeapData[playerid][weapon2ammo]);
    GetPlayerWeaponData(playerid,2,WeapData[playerid][weapon3],WeapData[playerid][weapon3ammo]);
    GetPlayerWeaponData(playerid,3,WeapData[playerid][weapon4],WeapData[playerid][weapon4ammo]);
    GetPlayerWeaponData(playerid,4,WeapData[playerid][weapon5],WeapData[playerid][weapon5ammo]);
    GetPlayerWeaponData(playerid,5,WeapData[playerid][weapon6],WeapData[playerid][weapon6ammo]);
    GetPlayerWeaponData(playerid,6,WeapData[playerid][weapon7],WeapData[playerid][weapon7ammo]);
    GetPlayerWeaponData(playerid,7,WeapData[playerid][weapon8],WeapData[playerid][weapon8ammo]);
    GetPlayerWeaponData(playerid,8,WeapData[playerid][weapon9],WeapData[playerid][weapon9ammo]);
    GetPlayerWeaponData(playerid,9,WeapData[playerid][weapon10],WeapData[playerid][weapon10ammo]);
    GetPlayerWeaponData(playerid,10,WeapData[playerid][weapon11],WeapData[playerid][weapon11ammo]);
    GetPlayerWeaponData(playerid,11,WeapData[playerid][weapon12],WeapData[playerid][weapon12ammo]);
    GetPlayerWeaponData(playerid,12,WeapData[playerid][weapon13],WeapData[playerid][weapon13ammo]);
}

public UpdateWeapons(playerid)
{
    new saveweap[13],pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,sizeof(pName));
    GrabWeapons(playerid);
    format(saveweap[0],256,"UPDATE Accounts SET Weapon1 = %d, Weapon1A = %i WHERE Username = '%s';",WeapData[playerid][weapon1],WeapData[playerid][weapon1ammo],pName);
    format(saveweap[1],256,"UPDATE Accounts SET Weapon2 = %d, Weapon2A = %i WHERE Username = '%s';",WeapData[playerid][weapon2],WeapData[playerid][weapon2ammo],pName);
    format(saveweap[2],256,"UPDATE Accounts SET Weapon3 = %d, Weapon3A = %i WHERE Username = '%s';",WeapData[playerid][weapon3],WeapData[playerid][weapon3ammo],pName);
    format(saveweap[3],256,"UPDATE Accounts SET Weapon4 = %d, Weapon4A = %i WHERE Username = '%s';",WeapData[playerid][weapon4],WeapData[playerid][weapon4ammo],pName);
    format(saveweap[4],256,"UPDATE Accounts SET Weapon5 = %d, Weapon5A = %i WHERE Username = '%s';",WeapData[playerid][weapon5],WeapData[playerid][weapon5ammo],pName);
    format(saveweap[5],256,"UPDATE Accounts SET Weapon6 = %d, Weapon6A = %i WHERE Username = '%s';",WeapData[playerid][weapon6],WeapData[playerid][weapon6ammo],pName);
    format(saveweap[6],256,"UPDATE Accounts SET Weapon7 = %d, Weapon7A = %i WHERE Username = '%s';",WeapData[playerid][weapon7],WeapData[playerid][weapon7ammo],pName);
    format(saveweap[7],256,"UPDATE Accounts SET Weapon8 = %d, Weapon8A = %i WHERE Username = '%s';",WeapData[playerid][weapon8],WeapData[playerid][weapon8ammo],pName);
    format(saveweap[8],256,"UPDATE Accounts SET Weapon9 = %d, Weapon9A = %i WHERE Username = '%s';",WeapData[playerid][weapon9],WeapData[playerid][weapon9ammo],pName);
    format(saveweap[9],256,"UPDATE Accounts SET Weapon10 = %d, Weapon10A = %i WHERE Username = '%s';",WeapData[playerid][weapon10],WeapData[playerid][weapon10ammo],pName);
    format(saveweap[10],256,"UPDATE Accounts SET Weapon11 = %d, Weapon11A = %i WHERE Username = '%s';",WeapData[playerid][weapon11],WeapData[playerid][weapon11ammo],pName);
    format(saveweap[11],256,"UPDATE Accounts SET Weapon12 = %d, Weapon12A = %i WHERE Username = '%s';",WeapData[playerid][weapon12],WeapData[playerid][weapon12ammo],pName);
    format(saveweap[12],256,"UPDATE Accounts SET Weapon13 = %d, Weapon13A = %i WHERE Username = '%s';",WeapData[playerid][weapon13],WeapData[playerid][weapon13ammo],pName);
    mysql_connect(host,user,db,pwd);
    mysql_query(saveweap[0]);
    mysql_query(saveweap[1]);
    mysql_query(saveweap[2]);
    mysql_query(saveweap[3]);
    mysql_query(saveweap[4]);
    mysql_query(saveweap[5]);
    mysql_query(saveweap[6]);
    mysql_query(saveweap[7]);
    mysql_query(saveweap[8]);
    mysql_query(saveweap[9]);
    mysql_query(saveweap[10]);
    mysql_query(saveweap[11]);
    mysql_query(saveweap[12]);
    mysql_close();
}

public OnPlayerDisconnect(playerid)
{
    UpdateWeapons(playerid);
}
Hope you find this useful.
Reply


Messages In This Thread
SQL help. - by iGetty - 24.06.2012, 01:24
Re: SQL help. - by SuperViper - 24.06.2012, 02:11
Re: SQL help. - by iGetty - 24.06.2012, 02:41
Re: SQL help. - by phillip875 - 24.06.2012, 05:59
Re: SQL help. - by phillip875 - 24.06.2012, 06:20
Re: SQL help. - by iGetty - 29.06.2012, 16:52

Forum Jump:


Users browsing this thread: 1 Guest(s)