Saving Player Health and Armour Y_INI
#1

I Already have something it works but every time i register or login it saves 1.0000 so i would like to ask if someone has another idea to fix it.?
Reply
#2

Bump
Reply
#3

We are not physic. We cannot fix something we don't know. Please show us your code.
Reply
#4

pawn Код:
enum pInfo
{
    pPass,
    pCash,
    pAdmin,
    pKills,
    pDeaths,
    pJob,
    pJobRank,
    pBanned,
    pWarn,
    pBankmoney,
    pSkin,
    pMuted,
    pNewb,
    Float:Health,
    Float:Armour,
    pGun1,
    pGun2,
    pGun3,
    pAmmo1,
    pAmmo2,
    pAmmo3
}
pawn Код:
public OnPlayerDisconnect(playerid, reason)
{
    new Float:hp, Float:armour;
    new INI:File = INI_Open(UserPath(playerid));
    PlayerInfo[playerid][Health] = GetPlayerHealth(playerid, hp);
    PlayerInfo[playerid][Armour] = GetPlayerArmour(playerid, armour);
    INI_SetTag(File,"data");
    INI_WriteInt(File,"Cash",GetPlayerMoney(playerid));
    INI_WriteInt(File,"Admin",PlayerInfo[playerid][pAdmin]);
    INI_WriteInt(File,"Kills",PlayerInfo[playerid][pKills]);
    INI_WriteInt(File,"Deaths",PlayerInfo[playerid][pDeaths]);
    INI_WriteInt(File,"Job",PlayerInfo[playerid][pJob]);
    INI_WriteInt(File,"Banned",PlayerInfo[playerid][pBanned]);
    INI_WriteInt(File,"Warn",PlayerInfo[playerid][pWarn]);
    INI_WriteInt(File,"BankMoney",PlayerInfo[playerid][pBankmoney]);
    INI_WriteInt(File,"Skin",PlayerInfo[playerid][pSkin]);
    INI_WriteInt(File,"Muted",PlayerInfo[playerid][pMuted]);
    INI_WriteInt(File,"Newb",PlayerInfo[playerid][pNewb]);
    INI_WriteFloat(File, "Health", PlayerInfo[playerid][Health]);
    INI_WriteFloat(File, "Armour", PlayerInfo[playerid][Armour]);
    INI_WriteInt(File,"Gun1",PlayerInfo[playerid][pGun1]);
    INI_WriteInt(File,"Gun2",PlayerInfo[playerid][pGun2]);
    INI_WriteInt(File,"Gun3",PlayerInfo[playerid][pGun3]);
    INI_WriteInt(File,"Ammo1",PlayerInfo[playerid][pAmmo1]);
    INI_WriteInt(File,"Ammo2",PlayerInfo[playerid][pAmmo2]);
    INI_WriteInt(File,"Ammo3",PlayerInfo[playerid][pAmmo3]);
    INI_Close(File);
    GetPlayerWeaponData(playerid, 1, PlayerInfo[playerid][pGun1], PlayerInfo[playerid][pAmmo1]);
    GetPlayerWeaponData(playerid, 2, PlayerInfo[playerid][pGun2], PlayerInfo[playerid][pAmmo2]);
    GetPlayerWeaponData(playerid, 3, PlayerInfo[playerid][pGun3], PlayerInfo[playerid][pAmmo3]);
    return 1;
}
pawn Код:
public OnPlayerSpawn(playerid)
{
    //new mess[256],IP[256];
    //GetPlayerIp(playerid,IP,sizeof(IP));
    SetPlayerSkin(playerid, skins[random(13)]);
    SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
    //format(mess,sizeof(mess),"%s has joined the server. [IP Address: %s ]",GetName(playerid),IP);
    //printf(mess);
    //SendClientMessageToAll(-1,mess);
    for(new i = 0; i < MAX_PLAYERS; i++)
    {
        SetPlayerMarkerForPlayer(i,playerid,00);
    }
    SetPlayerHealth(playerid, PlayerInfo[playerid][Health]);
    SetPlayerArmour(playerid, PlayerInfo[playerid][Armour]);
    GivePlayerWeapon(playerid, PlayerInfo[playerid][pGun1], PlayerInfo[playerid][pAmmo1]);
    GivePlayerWeapon(playerid, PlayerInfo[playerid][pGun2], PlayerInfo[playerid][pAmmo2]);
    GivePlayerWeapon(playerid, PlayerInfo[playerid][pGun3], PlayerInfo[playerid][pAmmo3]);
    return 1;
}
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    switch( dialogid )
    {
        case DIALOG_REGISTER:
        {
            if (!response) return Kick(playerid);
            if(response)
            {
                if(!strlen(inputtext)) return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Registering...","You have entered an invalid password.\nType your password below to register a new account.","Register","Quit");
                new INI:File = INI_Open(UserPath(playerid));
                INI_SetTag(File,"data");
                INI_WriteInt(File,"Password",udb_hash(inputtext));
                INI_WriteInt(File,"Cash",25000);
                INI_WriteInt(File,"Admin",0);
                INI_WriteInt(File,"Kills",0);
                INI_WriteInt(File,"Deaths",0);
                INI_WriteInt(File,"Job",0);
                INI_WriteInt(File,"Banned",0);
                INI_WriteInt(File,"Warn",0);
                INI_WriteInt(File,"BankMoney",0);
                INI_WriteInt(File,"Skin",0);
                INI_WriteInt(File,"Muted",0);
                INI_WriteInt(File,"Newb",0);
                INI_WriteFloat(File,"Health",100);
                INI_WriteFloat(File,"Armour",15);
                INI_WriteInt(File,"Gun1",0);
                INI_WriteInt(File,"Gun2",0);
                INI_WriteInt(File,"Gun3",0);
                INI_WriteInt(File,"Ammo1",0);
                INI_WriteInt(File,"Ammo2",0);
                INI_WriteInt(File,"Ammo3",0);
                INI_Close(File);

                SetSpawnInfo(playerid, 0, skins[random(13)], 2127.5403, 2369.9082, 10.8203, 269.15, 0, 0, 0, 0, 0, 0);
                SetPlayerSkin(playerid, skins[random(13)]);
                SpawnPlayer(playerid);
                SetPlayerHealth(playerid, 100);
                SetPlayerArmour(playerid, 15);
                ShowPlayerDialog(playerid, DIALOG_SUCCESS_1, DIALOG_STYLE_MSGBOX,"Success!","Great! Your Y_INI system works perfectly. Relog to save your stats!","Ok","");
            }
        }

        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_2, DIALOG_STYLE_MSGBOX,"Success!","","Ok","");
                }
                else
                {
                    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login","You have entered an incorrect password.\nType your password below to login.","Login","Quit");
                }
                return 1;
            }
        }
    }
    return 1;
}
pawn Код:
forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
    INI_Int("Password",PlayerInfo[playerid][pPass]);
    INI_Int("Cash",PlayerInfo[playerid][pCash]);
    INI_Int("Admin",PlayerInfo[playerid][pAdmin]);
    INI_Int("Kills",PlayerInfo[playerid][pKills]);
    INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
    INI_Int("Job",PlayerInfo[playerid][pJob]);
    INI_Int("JobRank",PlayerInfo[playerid][pJobRank]);
    INI_Int("Banned",PlayerInfo[playerid][pBanned]);
    INI_Int("Warn",PlayerInfo[playerid][pWarn]);
    INI_Int("BankMoney",PlayerInfo[playerid][pBankmoney]);
    INI_Int("Skin",PlayerInfo[playerid][pSkin]);
    INI_Int("Muted",PlayerInfo[playerid][pMuted]);
    INI_Int("Newb",PlayerInfo[playerid][pNewb]);
    INI_Float("Health", PlayerInfo[playerid][Health]);
    INI_Float("Armour", PlayerInfo[playerid][Armour]);
    INI_Int("Gun1",PlayerInfo[playerid][pGun1]);
    INI_Int("Gun2",PlayerInfo[playerid][pGun2]);
    INI_Int("Gun3",PlayerInfo[playerid][pGun3]);
    INI_Int("Ammo1",PlayerInfo[playerid][pAmmo1]);
    INI_Int("Ammo2",PlayerInfo[playerid][pAmmo2]);
    INI_Int("Ammo3",PlayerInfo[playerid][pAmmo3]);
    return 1;

}
Here u go the code, one thing more if the player disconnects and joins it wil nout save his ammo but the guns he saves that.
Reply
#5

No one?
Reply
#6

Here's the problem.
pawn Код:
PlayerInfo[playerid][Health] = GetPlayerHealth(playerid, hp);
PlayerInfo[playerid][Armour] = GetPlayerArmour(playerid, armour);
Change this to.
pawn Код:
GetPlayerHealth(playerid, hp);
GetPlayerArmour(playerid, armour);

PlayerInfo[playerid][Health] = hp;
PlayerInfo[playerid][Armour] = armour;
Don't forgot to change your health value on user file.
Reply
#7

That skin is still DYING GODD*M every time i relog or create a new acount it die! please help me
Reply
#8

Quote:
Originally Posted by Skimmer
Посмотреть сообщение
Here's the problem.
pawn Код:
PlayerInfo[playerid][Health] = GetPlayerHealth(playerid, hp);
PlayerInfo[playerid][Armour] = GetPlayerArmour(playerid, armour);
Change this to.
pawn Код:
GetPlayerHealth(playerid, hp);
GetPlayerArmour(playerid, armour);

PlayerInfo[playerid][Health] = hp;
PlayerInfo[playerid][Armour] = armour;
Don't forgot to change your health value on user file.
Why bother doing two useless steps?

pawn Код:
GetPlayerHealth(playerid, PlayerInfo[playerid][Health]);
GetPlayerArmour(playerid, PlayerInfo[playerid][Armour]);
You will also want to check if the player has spawned/dead.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)