26.04.2014, 17:53
How to load the saved weapon when the player spawns/connects?
OnDialog..
pawn Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
new weapons[13][2];
for (new i = 0; i < 13; i++)
{
GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
}
INI_Int( "weaponSlot0", weapons[0][0]);
INI_Int( "weaponSlot0Ammo", weapons[0][1]);
INI_Int( "weaponSlot1", weapons[1][0]);
INI_Int( "weaponSlot1Ammo", weapons[1][1]);
INI_Int( "weaponSlot2", weapons[2][0]);
INI_Int( "weaponSlot2Ammo", weapons[2][1]);
INI_Int( "weaponSlot3", weapons[3][0]);
INI_Int( "weaponSlot3Ammo", weapons[3][1]);
INI_Int( "weaponSlot4", weapons[4][0]);
INI_Int( "weaponSlot4Ammo", weapons[4][1]);
INI_Int( "weaponSlot5", weapons[5][0]);
INI_Int( "weaponSlot5Ammo", weapons[5][1]);
INI_Int( "weaponSlot6", weapons[6][0]);
INI_Int( "weaponSlot6Ammo", weapons[6][1]);
INI_Int( "weaponSlot7", weapons[7][0]);
INI_Int( "weaponSlot7Ammo", weapons[7][1]);
INI_Int( "weaponSlot8", weapons[8][0]);
INI_Int( "weaponSlot8Ammo", weapons[8][1]);
INI_Int( "weaponSlot9", weapons[9][0]);
INI_Int( "weaponSlot8Ammo", weapons[9][1]);
INI_Int( "weaponSlot10", weapons[10][0]);
INI_Int( "weaponSlot10Ammo", weapons[10][1]);
INI_Int( "weaponSlot11", weapons[11][0]);
INI_Int( "weaponSlot11Ammo", weapons[11][1]);
INI_Int( "weaponSlot12", weapons[12][0]);
INI_Int( "weaponSlot12Ammo", weapons[12][1]);
return 1;
}
pawn Код:
forward SavePlayer(playerid);
SavePlayer(playerid)
{
new weapons[13][2];
new INI:File = INI_Open(UserPath(playerid));
for (new i = 0; i < 13; i++) GetPlayerWeaponData(playerid, i, weapons[i][0], weapons[i][1]);
INI_SetTag(File,"Player Data");
INI_WriteInt(File, "weaponSlot0", weapons[0][0]);
INI_WriteInt(File, "weaponSlot0Ammo", weapons[0][1]);
INI_WriteInt(File, "weaponSlot1", weapons[1][0]);
INI_WriteInt(File, "weaponSlot1Ammo", weapons[1][1]);
INI_WriteInt(File, "weaponSlot2", weapons[2][0]);
INI_WriteInt(File, "weaponSlot2Ammo", weapons[2][1]);
INI_WriteInt(File, "weaponSlot3", weapons[3][0]);
INI_WriteInt(File, "weaponSlot3Ammo", weapons[3][1]);
INI_WriteInt(File, "weaponSlot4", weapons[4][0]);
INI_WriteInt(File, "weaponSlot4Ammo", weapons[4][1]);
INI_WriteInt(File, "weaponSlot5", weapons[5][0]);
INI_WriteInt(File, "weaponSlot5Ammo", weapons[5][1]);
INI_WriteInt(File, "weaponSlot6", weapons[6][0]);
INI_WriteInt(File, "weaponSlot6Ammo", weapons[6][1]);
INI_WriteInt(File, "weaponSlot7", weapons[7][0]);
INI_WriteInt(File, "weaponSlot7Ammo", weapons[7][1]);
INI_WriteInt(File, "weaponSlot8", weapons[8][0]);
INI_WriteInt(File, "weaponSlot8Ammo", weapons[8][1]);
INI_WriteInt(File, "weaponSlot9", weapons[9][0]);
INI_WriteInt(File, "weaponSlot8Ammo", weapons[9][1]);
INI_WriteInt(File, "weaponSlot10", weapons[10][0]);
INI_WriteInt(File, "weaponSlot10Ammo", weapons[10][1]);
INI_WriteInt(File, "weaponSlot11", weapons[11][0]);
INI_WriteInt(File, "weaponSlot11Ammo", weapons[11][1]);
INI_WriteInt(File, "weaponSlot12", weapons[12][0]);
INI_WriteInt(File, "weaponSlot12Ammo", weapons[12][1]);
INI_Close(File);
}
pawn Код:
case DIALOG_LOGIN:
{
if ( !response ) return Kick ( playerid );
if( response )
{
if(udb_hash(inputtext) == PlayerInfo[playerid][pPass])
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
GivePlayerMoney(playerid, PlayerInfo[playerid][pCash]);
ShowPlayerDialog(playerid, DIALOG_SUCCESS, DIALOG_STYLE_MSGBOX,""CLW"Success!",""CLG"You have successfully logged in!","Ok","");
}
else
{
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,""CLW"Login",""CLR"You have entered an incorrect password.\n"CLW"Type your password below to login.","Login","Quit");
}
return 1;
}
}