PDA

View Full Version : Saving PlayerHealth and Armour will kill them.


Mey6155
17/11/2013, 02:37 PM
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
}
new PlayerInfo[MAX_PLAYERS][pInfo];



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;
}


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;
}


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;
}


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;

}


If a new player joins the server and register and spawns he got killd but i have when he register health = 100 armour = 15 but it just kill him ;(

And if you change it at scriptfiles to 100 and play it works when you logout its 1.0000 again :(
Please help me

Voxel
17/11/2013, 02:41 PM
Under OnPlayerConnect, set his hp to 100, and also under OnPlayerSpawn to be sure that his HP value is set properly.

Mey6155
17/11/2013, 02:50 PM
No, not that it is'ny logic in a Roleplay server to start always with 100hp another way?