Load player weapons
#1

How to load the saved weapon when the player spawns/connects?

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);
}
OnDialog..
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;
            }
        }
Reply
#2

pawn Код:
for (new i = 0; i < 13; i++)
{
     GivePlayerWeapon(playerid, weapons[i][0][playerid], weapons[i][1][playerid]);
}
did you tried this ?
Reply
#3

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
U need to add a player array to the weapons[13][2];
new weapons[MAX_PLAYERS][13][2];

And under OnPlayerSpawn
pawn Код:
for (new w = 1; w < 13; w++)
{
    GivePlayerWeapon(playerid, weapons[playerid][w][0], weapons[playerid][w][1]);
}
It isn't giving me the weapons. Don't I have to load it or something?
Reply
#4

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
You did load it from this function public LoadUser_data(playerid,name[],value[]) didnt you?

NOTE THAT: Please change the weapons variable to the one i gave you.
It's same as you told
pawn Код:
new weapons[MAX_PLAYERS][13][2];
    for (new w = 1; w < 13; w++)
    {
        GivePlayerWeapon(playerid, weapons[playerid][w][0], weapons[playerid][w][1]);
    }
And yes i'm loading from
pawn Код:
forward LoadUser_data(playerid,name[],value[]);
Reply
#5

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
pawn Код:
//global variable
new weapons[MAX_PLAYERS][13][2];

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    for (new i = 0; i < 13; i++)
    {
        GetPlayerWeaponData(playerid, i, weapons[playerid][i][0], weapons[playerid][i][1]);
    }
    INI_Int( "weaponSlot0", weapons[playerid][0][0]);
    INI_Int( "weaponSlot0Ammo", weapons[playerid][0][1]);
    INI_Int( "weaponSlot1", weapons[playerid][1][0]);
    INI_Int( "weaponSlot1Ammo", weapons[playerid][1][1]);
    INI_Int( "weaponSlot2", weapons[playerid][2][0]);
    INI_Int( "weaponSlot2Ammo", weapons[playerid][2][1]);
    INI_Int( "weaponSlot3", weapons[playerid][3][0]);
    INI_Int( "weaponSlot3Ammo", weapons[playerid][3][1]);
    INI_Int( "weaponSlot4", weapons[playerid][4][0]);
    INI_Int( "weaponSlot4Ammo", weapons[playerid][4][1]);
    INI_Int( "weaponSlot5", weapons[playerid][5][0]);
    INI_Int( "weaponSlot5Ammo", weapons[playerid][5][1]);
    INI_Int( "weaponSlot6", weapons[playerid][6][0]);
    INI_Int( "weaponSlot6Ammo", weapons[playerid][6][1]);
    INI_Int( "weaponSlot7", weapons[playerid][7][0]);
    INI_Int( "weaponSlot7Ammo", weapons[playerid][7][1]);
    INI_Int( "weaponSlot8", weapons[playerid][8][0]);
    INI_Int( "weaponSlot8Ammo", weapons[playerid][8][1]);
    INI_Int( "weaponSlot9", weapons[playerid][9][0]);
    INI_Int( "weaponSlot8Ammo", weapons[playerid][9][1]);
    INI_Int( "weaponSlot10", weapons[playerid][10][0]);
    INI_Int( "weaponSlot10Ammo", weapons[playerid][10][1]);
    INI_Int( "weaponSlot11", weapons[playerid][11][0]);
    INI_Int( "weaponSlot11Ammo", weapons[playerid][11][1]);
    INI_Int( "weaponSlot12", weapons[playerid][12][0]);
    INI_Int( "weaponSlot12Ammo", weapons[playerid][12][1]);
    return 1;
}

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[playerid][0][0]);
    INI_WriteInt(File, "weaponSlot0Ammo", weapons[playerid][0][1]);
    INI_WriteInt(File, "weaponSlot1", weapons[playerid][1][0]);
    INI_WriteInt(File, "weaponSlot1Ammo", weapons[playerid][1][1]);
    INI_WriteInt(File, "weaponSlot2", weapons[playerid][2][0]);
    INI_WriteInt(File, "weaponSlot2Ammo", weapons[playerid][2][1]);
    INI_WriteInt(File, "weaponSlot3", weapons[playerid][3][0]);
    INI_WriteInt(File, "weaponSlot3Ammo", weapons[playerid][3][1]);
    INI_WriteInt(File, "weaponSlot4", weapons[playerid][4][0]);
    INI_WriteInt(File, "weaponSlot4Ammo", weapons[playerid][4][1]);
    INI_WriteInt(File, "weaponSlot5", weapons[playerid][5][0]);
    INI_WriteInt(File, "weaponSlot5Ammo", weapons[playerid][5][1]);
    INI_WriteInt(File, "weaponSlot6", weapons[playerid][6][0]);
    INI_WriteInt(File, "weaponSlot6Ammo", weapons[playerid][6][1]);
    INI_WriteInt(File, "weaponSlot7", weapons[playerid][7][0]);
    INI_WriteInt(File, "weaponSlot7Ammo", weapons[playerid][7][1]);
    INI_WriteInt(File, "weaponSlot8", weapons[playerid][8][0]);
    INI_WriteInt(File, "weaponSlot8Ammo", weapons[playerid][8][1]);
    INI_WriteInt(File, "weaponSlot9", weapons[playerid][9][0]);
    INI_WriteInt(File, "weaponSlot8Ammo", weapons[playerid][9][1]);
    INI_WriteInt(File, "weaponSlot10", weapons[playerid][10][0]);
    INI_WriteInt(File, "weaponSlot10Ammo", weapons[playerid][10][1]);
    INI_WriteInt(File, "weaponSlot11", weapons[playerid][11][0]);
    INI_WriteInt(File, "weaponSlot11Ammo", weapons[playerid][11][1]);
    INI_WriteInt(File, "weaponSlot12", weapons[playerid][12][0]);
    INI_WriteInt(File, "weaponSlot12Ammo", weapons[playerid][12][1]);
    INI_Close(File);
}

//under OnPlayerSpawn(playerid)
for (new w = 1; w < 13; w++)
{
        GivePlayerWeapon(playerid, weapons[playerid][w][0], weapons[playerid][w][1]);
}
I can't put
pawn Код:
[610] INI_WriteInt(File, "weaponSlot0", weapons[playerid][0][0]);
pawn Код:
(610) : error 001: expected token: ",", but found "["
(610) : error 029: invalid expression, assumed zero
(610) : warning 215: expression has no effect
(610) : error 001: expected token: ";", but found "]"
(610) : fatal error 107: too many error messages on one line
It has to be
pawn Код:
INI_WriteInt(File, "weaponSlot0", weapons[0][0]);
Reply
#6

Quote:
Originally Posted by Ralfie
Посмотреть сообщение
No, i compiled it and it gave me no errors.

Do what i posted
Don't know what happened, but it worked, thanks. +REP
Edit: need to rep around xD
Reply
#7

I hate using loops on loaduser data with Y_INI
you could try rather than using provided functions with Y_INI, you could use name[],value[] and comparing them.
Since as I used to say, Y_INI spams the hell out of that callback.
I used that to load 400 lines from file, otherwise it wouldn't load at all.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)