HELP : Y_INI SAVIN HEALTH / ARMOUR
#1

Hello..
Can anyone help me about saving and loading Health / Armour with Y_INI?
Always reset and getback to full when i relogging.
Heres the code :


Quote:

#include <a_samp>
#include <sscanf2>
#include <YSI\y_ini>
#include <zcmd>
#include <foreach>

#define DIALOG_REGISTER 1
#define DIALOG_LOGIN 2
#define DIALOG_AGE 3
#define DIALOG_SEX 4
#define DIALOG_STATS 5

#define PATH "/users/%s.ini"

#define COL_WHITE 0xFFFFFF
#define COL_RED 0xF81414
#define COL_GREEN 0x00FF22
#define COL_LIGHTBLUE 0x2ca1e4
#define COL_PURPLE 0xC2A2DAAA

#define MAX_DROP_ITEMS 1000

native WP_Hash(buffer[],len,const str[]);

enum pInfo
{
pPass,
pLevel,
pKills,
pDeaths,
pMoney,
pAge,
pSex,
pBan,
pIP[16],
pVW,
pInterior,
pAdmin,
pSkin,
Float : pHealth,
Float : pArmour,
Float : posX,
Float : posY,
Float : posZ,
Float : posA
};
new PlayerInfo[MAX_PLAYERS][pInfo];

Quote:

forward LoadUser_data(playerid,name[],value[]);
public LoadUser_data(playerid,name[],value[])
{
INI_Int("Password", PlayerInfo[playerid][pPass]);
INI_Int("Level",PlayerInfo[playerid][pLevel]);
INI_Int("Kills",PlayerInfo[playerid][pKills]);
INI_Int("Deaths",PlayerInfo[playerid][pDeaths]);
INI_Int("Money", PlayerInfo[playerid][pMoney]);
INI_Int("Age",PlayerInfo[playerid][pAge]);
INI_Int("Sex", PlayerInfo[playerid][pSex]);
INI_Int("Ban",PlayerInfo[playerid][pBan]);
INI_Int("Admin", PlayerInfo[playerid][pAdmin]);
INI_Int("IP", PlayerInfo[playerid][pIP]);
INI_Int("Interior", PlayerInfo[playerid][pInterior]);
INI_Int("VirutalWorld", PlayerInfo[playerid][pVW]);
INI_Int("Skin", PlayerInfo[playerid][pSkin]);
INI_Float("Health", PlayerInfo[playerid][pHealth]);
INI_Float("Armour", PlayerInfo[playerid][pArmour]);
INI_Float("PositionX",PlayerInfo[playerid][posX]);
INI_Float("PositionY",PlayerInfo[playerid][posY]);
INI_Float("PositionZ",PlayerInfo[playerid][posZ]);
INI_Float("PositionA",PlayerInfo[playerid][posA]);
return 1;
}

Quote:

stock SaveUser_data(playerid)
{
new INI:File = INI_Open(UserPath(playerid));
GetPlayerPos(playerid, PlayerInfo[playerid][posX], PlayerInfo[playerid][posY], PlayerInfo[playerid][posZ]);
GetPlayerFacingAngle(playerid, PlayerInfo[playerid][posA]);
PlayerInfo[playerid][pSkin] = GetPlayerSkin(playerid);
GetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
GetPlayerArmour(playerid, PlayerInfo[playerid][pArmour]);

INI_SetTag(File,"data");

INI_WriteInt(File,"Level", PlayerInfo[playerid][pLevel]);
INI_WriteInt(File,"Skin", GetPlayerSkin(playerid));
INI_WriteInt(File,"Ban", PlayerInfo[playerid][pBan]);
INI_WriteInt(File,"Money", GetPlayerMoney(playerid));
INI_WriteInt(File,"Admin", PlayerInfo[playerid][pAdmin]);
INI_WriteString(File,"IP", PlayerInfo[playerid][pIP]);
INI_WriteInt(File,"Interior", GetPlayerInterior(playerid));
INI_WriteInt(File,"VirtualWorld", GetPlayerVirtualWorld(playerid));
INI_WriteFloat(File,"Health", PlayerInfo[playerid][pHealth]);
INI_WriteFloat(File,"Armour", PlayerInfo[playerid][pArmour]);
INI_WriteFloat(File,"PositionX", PlayerInfo[playerid][posX]);
INI_WriteFloat(File,"PositionY", PlayerInfo[playerid][posY]);
INI_WriteFloat(File,"PositionZ", PlayerInfo[playerid][posZ]);
INI_WriteFloat(File,"PositionA", PlayerInfo[playerid][posA]);
INI_Close(File);
return 1;
}

Quote:

case DIALOG_REGISTER:
{
if (!response) return Kick(playerid);
if(response)
{
if(!strlen(inputtext))
return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", "You have entered an invalid password.\n\nType your password below to register a new account.","Register","Quit");

new Hpass[129];
WP_Hash(Hpass,sizeof(Hpass), inputtext);

new INI:File = INI_Open(UserPath(playerid));
INI_SetTag(File,"data");
INI_WriteString(File,"Password", Hpass);
INI_WriteInt(File,"Money",500);
INI_WriteInt(File,"Skin",0);
INI_WriteInt(File,"Money",500);
INI_WriteInt(File,"Admin",0);
INI_WriteFloat(File,"Health",0);
INI_WriteFloat(File,"Armour",0);
INI_Close(File);

PlayerInfo[playerid][posX] = 176.4699;
PlayerInfo[playerid][posY] = -107.5863;
PlayerInfo[playerid][posZ] = 1.5436;
PlayerInfo[playerid][pVW] = 0;
PlayerInfo[playerid][pInterior] = 0;
PlayerInfo[playerid][pHealth] = 100;
PlayerInfo[playerid][pArmour] = 0;
ShowPlayerDialog(playerid, DIALOG_AGE, DIALOG_STYLE_INPUT,"Age","Please put your age to process.","Ok","");

}
}

Reply
#2

Quote:
Originally Posted by hatcis
Посмотреть сообщение
Hello..
Can anyone help me about saving and loading Health / Armour with Y_INI?
Always reset and getback to full when i relogging.
Heres the code :
you have to put something like this method

PHP код:

/*this is not that importent just for clearness do 
INI_WriteFloat(File,"Health",0.0);
INI_WriteFloat(File,"Armour",0.0);
if you want
*/
// Global value new FirstSpawn[MAX_PLAYERS];
OnPlayerConnect(playerid)
{
    
FirstSpawn[playerid] = 1// to avoid setting player health each time they spawn
    
return 1;
}
OnPlayerSpawn(playerid)
{
    if(
FirstSpawn[playerid] == 1// to avoid setting player health each time they spawn
    
{
        
FirstSpawn[playerid] = 0// to avoid setting player health each time they spawn
        
SetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
        
SetPlayerArmour(playerid,PlayerInfo[playerid][pArmour]);
    }
    return 
1;

Reply
#3

Quote:
Originally Posted by khRamin78
Посмотреть сообщение
you have to put something like this method

PHP код:

/*this is not that importent just for clearness do 
INI_WriteFloat(File,"Health",0.0);
INI_WriteFloat(File,"Armour",0.0);
if you want
*/
// Global value new FirstSpawn[MAX_PLAYERS];
OnPlayerConnect(playerid)
{
    
FirstSpawn[playerid] = 1// to avoid setting player health each time they spawn
    
return 1;
}
OnPlayerSpawn(playerid)
{
    if(
FirstSpawn[playerid] == 1// to avoid setting player health each time they spawn
    
{
        
FirstSpawn[playerid] = 0// to avoid setting player health each time they spawn
        
SetPlayerHealth(playerid,PlayerInfo[playerid][pHealth]);
        
SetPlayerArmour(playerid,PlayerInfo[playerid][pArmour]);
    }
    return 
1;


I've tried that code but didnt work (ERROR). so what must i do?

Quote:

public OnPlayerConnect(playerid)
{
new sdialog[128], rdialog[128];

if(!IsValidName(playerid)) return Kick(playerid);

SetPlayerColor(playerid, -1);

GetPlayerIp(playerid, PlayerInfo[playerid][pIP], 16);

if(fexist(UserPath(playerid)))
{
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
format(sdialog, sizeof(sdialog), "Welcome back, %s\n\n If you wish to login, please enter your password below.", GetName(playerid));
ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_INPUT,"Login", sdialog, "Login","Quit");
}
else
{
FirstSpawn[playerid] = 1;
format(rdialog, sizeof(rdialog), "Name: %s\n\n Enter your desired password below to register!", GetName(playerid));
ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, "Register", rdialog ,"Register","Quit");
}
return 1;
}

Quote:

public OnPlayerSpawn(playerid)
{
if(FirstSpawn[playerid] == 1)
{
FirstSpawn[playerid] = 0;
SetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
SetPlayerArmour(playerid, PlayerInfo[playerid][pArmour]);
}
else
{
SetPlayerPos(playerid, PlayerInfo[playerid][posX], PlayerInfo[playerid][posY], PlayerInfo[playerid][posZ]);
SetPlayerSkin(playerid, PlayerInfo[playerid][pSkin]);
SetPlayerFacingAngle(playerid, PlayerInfo[playerid][posA]);
SetPlayerInterior(playerid, PlayerInfo[playerid][pInterior]);
SetPlayerVirtualWorld(playerid, PlayerInfo[playerid][pVW]);
SetPlayerHealth(playerid, PlayerInfo[playerid][pHealth]);
SetPlayerArmour(playerid, PlayerInfo[playerid][pArmour]);
GivePlayerMoney(playerid, PlayerInfo[playerid][pMoney]);
}
return 1;
}

Reply
#4

Quote:
Originally Posted by hatcis
Посмотреть сообщение
I've tried that code but didnt work (ERROR). so what must i do?
dude just put FirstSpawn[playerid] = 1; in your top of OnPlayerConnect Not in the else statment

PHP код:
public OnPlayerConnect(playerid)
{
new 
sdialog[128], rdialog[128];
if(!
IsValidName(playerid)) return Kick(playerid);
SetPlayerColor(playerid, -1);
GetPlayerIp(playeridPlayerInfo[playerid][pIP], 16);
if(
fexist(UserPath(playerid)))
{
FirstSpawn[playerid] = 1;
INI_ParseFile(UserPath(playerid), "LoadUser_%s", .bExtra true, .extra playerid);
format(sdialogsizeof(sdialog), "Welcome back, %s\n\n If you wish to login, please enter your password below."GetName(playerid));
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_INPUT,"Login"sdialog"Login","Quit");
}
else
{
FirstSpawn[playerid] = 1;
format(rdialogsizeof(rdialog), "Name: %s\n\n Enter your desired password below to register!"GetName(playerid));
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_INPUT"Register"rdialog ,"Register","Quit");
}
return 
1;

Reply
#5

and this needs to be something like tihs
PHP код:
public OnPlayerSpawn(playerid)
{
if(
FirstSpawn[playerid] == 1)
{
 
FirstSpawn[playerid] = 0;
 
SetPlayerHealth(playeridPlayerInfo[playerid][pHealth]);
 
SetPlayerArmour(playeridPlayerInfo[playerid][pArmour]);
}
SetPlayerPos(playeridPlayerInfo[playerid][posX], PlayerInfo[playerid][posY], PlayerInfo[playerid][posZ]);
SetPlayerSkin(playeridPlayerInfo[playerid][pSkin]);
SetPlayerFacingAngle(playeridPlayerInfo[playerid][posA]);
SetPlayerInterior(playeridPlayerInfo[playerid][pInterior]);
SetPlayerVirtualWorld(playeridPlayerInfo[playerid][pVW]);
GivePlayerMoney(playeridPlayerInfo[playerid][pMoney]);
return 
1;

no need for else statement
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)