Help with resetting weapons on player death
#1

I am having trouble with resetting players weapons when they die so that they respawn with nothing.

OnPlayerDisconnect I have this

Код:
    new INI:File = INI_Open(UserPath(playerid));
    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]);
    GetPlayerWeaponData(playerid, 0, PlayerInfo[playerid][pWeapon0], PlayerInfo[playerid][pAmmo0]);
    GetPlayerWeaponData(playerid, 1, PlayerInfo[playerid][pWeapon1], PlayerInfo[playerid][pAmmo1]);
    GetPlayerWeaponData(playerid, 2, PlayerInfo[playerid][pWeapon2], PlayerInfo[playerid][pAmmo2]);
    GetPlayerWeaponData(playerid, 3, PlayerInfo[playerid][pWeapon3], PlayerInfo[playerid][pAmmo3]);
    GetPlayerWeaponData(playerid, 4, PlayerInfo[playerid][pWeapon4], PlayerInfo[playerid][pAmmo4]);
    GetPlayerWeaponData(playerid, 5, PlayerInfo[playerid][pWeapon5], PlayerInfo[playerid][pAmmo5]);
    GetPlayerWeaponData(playerid, 6, PlayerInfo[playerid][pWeapon6], PlayerInfo[playerid][pAmmo6]);
    GetPlayerWeaponData(playerid, 7, PlayerInfo[playerid][pWeapon7], PlayerInfo[playerid][pAmmo7]);
    GetPlayerWeaponData(playerid, 8, PlayerInfo[playerid][pWeapon8], PlayerInfo[playerid][pAmmo8]);
    GetPlayerWeaponData(playerid, 9, PlayerInfo[playerid][pWeapon9], PlayerInfo[playerid][pAmmo9]);
    GetPlayerWeaponData(playerid, 10, PlayerInfo[playerid][pWeapon10], PlayerInfo[playerid][pAmmo10]);
    GetPlayerWeaponData(playerid, 11, PlayerInfo[playerid][pWeapon11], PlayerInfo[playerid][pAmmo11]);
    GetPlayerWeaponData(playerid, 12, PlayerInfo[playerid][pWeapon12], PlayerInfo[playerid][pAmmo12]);
    INI_WriteInt(File,"Weapon0",PlayerInfo[playerid][pWeapon0]);
    INI_WriteInt(File,"Ammo0",PlayerInfo[playerid][pAmmo0]);
    INI_WriteInt(File,"Weapon1",PlayerInfo[playerid][pWeapon1]);
    INI_WriteInt(File,"Ammo1",PlayerInfo[playerid][pAmmo1]);
    INI_WriteInt(File,"Weapon2",PlayerInfo[playerid][pWeapon2]);
    INI_WriteInt(File,"Ammo2",PlayerInfo[playerid][pAmmo2]);
    INI_WriteInt(File,"Weapon3",PlayerInfo[playerid][pWeapon3]);
    INI_WriteInt(File,"Ammo3",PlayerInfo[playerid][pAmmo3]);
    INI_WriteInt(File,"Weapon4",PlayerInfo[playerid][pWeapon4]);
    INI_WriteInt(File,"Ammo4",PlayerInfo[playerid][pAmmo4]);
    INI_WriteInt(File,"Weapon5",PlayerInfo[playerid][pWeapon5]);
    INI_WriteInt(File,"Ammo5",PlayerInfo[playerid][pAmmo5]);
    INI_WriteInt(File,"Weapon6",PlayerInfo[playerid][pWeapon6]);
    INI_WriteInt(File,"Ammo6",PlayerInfo[playerid][pAmmo6]);
    INI_WriteInt(File,"Weapon7",PlayerInfo[playerid][pWeapon7]);
    INI_WriteInt(File,"Ammo7",PlayerInfo[playerid][pAmmo7]);
    INI_WriteInt(File,"Weapon8",PlayerInfo[playerid][pWeapon8]);
    INI_WriteInt(File,"Ammo8",PlayerInfo[playerid][pAmmo8]);
    INI_WriteInt(File,"Weapon9",PlayerInfo[playerid][pWeapon9]);
    INI_WriteInt(File,"Ammo9",PlayerInfo[playerid][pAmmo9]);
    INI_WriteInt(File,"Weapon10",PlayerInfo[playerid][pWeapon10]);
    INI_WriteInt(File,"Ammo10",PlayerInfo[playerid][pAmmo10]);
    INI_WriteInt(File,"Weapon11",PlayerInfo[playerid][pWeapon11]);
    INI_WriteInt(File,"Ammo11",PlayerInfo[playerid][pAmmo11]);
    INI_WriteInt(File,"Weapon12",PlayerInfo[playerid][pWeapon12]);
    INI_WriteInt(File,"Ammo12",PlayerInfo[playerid][pAmmo12]);
    INI_Close(File);
and OnPlayerSpawn I have this

Код:
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon0], PlayerInfo[playerid][pAmmo0]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon1], PlayerInfo[playerid][pAmmo1]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon2], PlayerInfo[playerid][pAmmo2]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon3], PlayerInfo[playerid][pAmmo3]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon4], PlayerInfo[playerid][pAmmo4]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon5], PlayerInfo[playerid][pAmmo5]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon6], PlayerInfo[playerid][pAmmo6]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon7], PlayerInfo[playerid][pAmmo7]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon8], PlayerInfo[playerid][pAmmo8]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon9], PlayerInfo[playerid][pAmmo9]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon10], PlayerInfo[playerid][pAmmo10]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon11], PlayerInfo[playerid][pAmmo11]);
	GivePlayerWeapon(playerid, PlayerInfo[playerid][pWeapon12], PlayerInfo[playerid][pAmmo12]);
	if(GetPlayerMoney(playerid) > 1) return SendClientMessage(playerid, 0xFFFFFF, "Welcome back, your money                from the last session has returned.");
and OnPlayerDeath I have this

Код:
	ResetPlayerWeapons(playerid);
	new string[64], Name[MAX_PLAYER_NAME], kName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, Name, sizeof(Name));
	GetPlayerName(killerid, kName, sizeof(Name));
	format(string, sizeof(string), "You have killed %s and have received their money.", Name);
	SendClientMessage(killerid, COLOR_LIGHTBLUE, string);
	format(string,sizeof(string), "You were killed by %s", kName);
	SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
	new money;
	money = GetPlayerMoney(playerid);
	GivePlayerMoney(killerid, money);
	GivePlayerMoney(playerid, -money);
	SendClientMessage(playerid, COLOR_BRIGHTRED, "You have died and lost all of your money.");
	PlayerInfo[killerid][pKills]++;
	PlayerInfo[playerid][pDeaths]++;
 	new INI:File = INI_Open(UserPath(playerid));
    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]);
    GetPlayerWeaponData(playerid, 0, PlayerInfo[playerid][pWeapon0], PlayerInfo[playerid][pAmmo0]);
    GetPlayerWeaponData(playerid, 1, PlayerInfo[playerid][pWeapon1], PlayerInfo[playerid][pAmmo1]);
    GetPlayerWeaponData(playerid, 2, PlayerInfo[playerid][pWeapon2], PlayerInfo[playerid][pAmmo2]);
    GetPlayerWeaponData(playerid, 3, PlayerInfo[playerid][pWeapon3], PlayerInfo[playerid][pAmmo3]);
    GetPlayerWeaponData(playerid, 4, PlayerInfo[playerid][pWeapon4], PlayerInfo[playerid][pAmmo4]);
    GetPlayerWeaponData(playerid, 5, PlayerInfo[playerid][pWeapon5], PlayerInfo[playerid][pAmmo5]);
    GetPlayerWeaponData(playerid, 6, PlayerInfo[playerid][pWeapon6], PlayerInfo[playerid][pAmmo6]);
    GetPlayerWeaponData(playerid, 7, PlayerInfo[playerid][pWeapon7], PlayerInfo[playerid][pAmmo7]);
    GetPlayerWeaponData(playerid, 8, PlayerInfo[playerid][pWeapon8], PlayerInfo[playerid][pAmmo8]);
    GetPlayerWeaponData(playerid, 9, PlayerInfo[playerid][pWeapon9], PlayerInfo[playerid][pAmmo9]);
    GetPlayerWeaponData(playerid, 10, PlayerInfo[playerid][pWeapon10], PlayerInfo[playerid][pAmmo10]);
    GetPlayerWeaponData(playerid, 11, PlayerInfo[playerid][pWeapon11], PlayerInfo[playerid][pAmmo11]);
    GetPlayerWeaponData(playerid, 12, PlayerInfo[playerid][pWeapon12], PlayerInfo[playerid][pAmmo12]);
    INI_WriteInt(File,"Weapon0",PlayerInfo[playerid][pWeapon0]);
    INI_WriteInt(File,"Ammo0",PlayerInfo[playerid][pAmmo0]);
    INI_WriteInt(File,"Weapon1",PlayerInfo[playerid][pWeapon1]);
    INI_WriteInt(File,"Ammo1",PlayerInfo[playerid][pAmmo1]);
    INI_WriteInt(File,"Weapon2",PlayerInfo[playerid][pWeapon2]);
    INI_WriteInt(File,"Ammo2",PlayerInfo[playerid][pAmmo2]);
    INI_WriteInt(File,"Weapon3",PlayerInfo[playerid][pWeapon3]);
    INI_WriteInt(File,"Ammo3",PlayerInfo[playerid][pAmmo3]);
    INI_WriteInt(File,"Weapon4",PlayerInfo[playerid][pWeapon4]);
    INI_WriteInt(File,"Ammo4",PlayerInfo[playerid][pAmmo4]);
    INI_WriteInt(File,"Weapon5",PlayerInfo[playerid][pWeapon5]);
    INI_WriteInt(File,"Ammo5",PlayerInfo[playerid][pAmmo5]);
    INI_WriteInt(File,"Weapon6",PlayerInfo[playerid][pWeapon6]);
    INI_WriteInt(File,"Ammo6",PlayerInfo[playerid][pAmmo6]);
    INI_WriteInt(File,"Weapon7",PlayerInfo[playerid][pWeapon7]);
    INI_WriteInt(File,"Ammo7",PlayerInfo[playerid][pAmmo7]);
    INI_WriteInt(File,"Weapon8",PlayerInfo[playerid][pWeapon8]);
    INI_WriteInt(File,"Ammo8",PlayerInfo[playerid][pAmmo8]);
    INI_WriteInt(File,"Weapon9",PlayerInfo[playerid][pWeapon9]);
    INI_WriteInt(File,"Ammo9",PlayerInfo[playerid][pAmmo9]);
    INI_WriteInt(File,"Weapon10",PlayerInfo[playerid][pWeapon10]);
    INI_WriteInt(File,"Ammo10",PlayerInfo[playerid][pAmmo10]);
    INI_WriteInt(File,"Weapon11",PlayerInfo[playerid][pWeapon11]);
    INI_WriteInt(File,"Ammo11",PlayerInfo[playerid][pAmmo11]);
    INI_WriteInt(File,"Weapon12",PlayerInfo[playerid][pWeapon12]);
    INI_WriteInt(File,"Ammo12",PlayerInfo[playerid][pAmmo12]);
    INI_Close(File);
Okay so when you disconnect and reconnect you spawn with the weapons you disconnected with, that's working fine. But the problem I am having is that when you die you respawn with the weapons you disconnected with, instead of respawning with no weapons (which is what I want to happen). I also want it to write to the file when you die so that you can't just reconnect after getting killed to get your guns back. I've gone over it again and again but I can't put my finger on whats wrong (I am new to this so I'm sure you guys will be able to see whats wrong right away). Please help and thanks in advance.
Reply
#2

Show your OnPlayerSpawn Callback
Reply
#3

Quote:
Originally Posted by Yashas
Посмотреть сообщение
Show your OnPlayerSpawn Callback
Oh sorry I don't know why I didn't include that I had meant to. Updated.
Reply
#4

Writing files in OnPlayerDeath() is a really bad idea but if you must use it why bother getting the weapon data when you know all values will be 0 why not just write the default values to file there is absolutely no need to do what your doing. This way you can eliminate some code as well.
Reply
#5

Quote:
Originally Posted by [uL]Pottus
Посмотреть сообщение
Writing files in OnPlayerDeath() is a really bad idea but if you must use it why bother getting the weapon data when you know all values will be 0 why not just write the default values to file there is absolutely no need to do what your doing. This way you can eliminate some code as well.
You mean like this?

Код:
	ResetPlayerWeapons(playerid);
	new string[64], Name[MAX_PLAYER_NAME], kName[MAX_PLAYER_NAME];
	GetPlayerName(playerid, Name, sizeof(Name));
	GetPlayerName(killerid, kName, sizeof(Name));
	format(string, sizeof(string), "You have killed %s and have received their money.", Name);
	SendClientMessage(killerid, COLOR_LIGHTBLUE, string);
	format(string,sizeof(string), "You were killed by %s", kName);
	SendClientMessage(playerid, COLOR_LIGHTBLUE, string);
	new money;
	money = GetPlayerMoney(playerid);
	GivePlayerMoney(killerid, money);
	GivePlayerMoney(playerid, -money);
	SendClientMessage(playerid, COLOR_BRIGHTRED, "You have died and lost all of your money.");
	PlayerInfo[killerid][pKills]++;
	PlayerInfo[playerid][pDeaths]++;
 	new INI:File = INI_Open(UserPath(playerid));
    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,"Weapon0",0);
    INI_WriteInt(File,"Ammo0",0);
    INI_WriteInt(File,"Weapon1",0);
    INI_WriteInt(File,"Ammo1",0);
    INI_WriteInt(File,"Weapon2",0);
    INI_WriteInt(File,"Ammo2",0);
    INI_WriteInt(File,"Weapon3",0);
    INI_WriteInt(File,"Ammo3",0);
    INI_WriteInt(File,"Weapon4",0);
    INI_WriteInt(File,"Ammo4",0);
    INI_WriteInt(File,"Weapon5",0);
    INI_WriteInt(File,"Ammo5",0);
    INI_WriteInt(File,"Weapon6",0);
    INI_WriteInt(File,"Ammo6",0);
    INI_WriteInt(File,"Weapon7",0);
    INI_WriteInt(File,"Ammo7",0);
    INI_WriteInt(File,"Weapon8",0);
    INI_WriteInt(File,"Ammo8",0);
    INI_WriteInt(File,"Weapon9",0);
    INI_WriteInt(File,"Ammo9",0);
    INI_WriteInt(File,"Weapon10",0);
    INI_WriteInt(File,"Ammo10",0);
    INI_WriteInt(File,"Weapon11",0);
    INI_WriteInt(File,"Ammo11",0);
    INI_WriteInt(File,"Weapon12",0);
    INI_WriteInt(File,"Ammo12",0);
    INI_Close(File);
Reply
#6

Yes and you can also remove ResetPlayerWeapons(playerid);
Reply
#7

LOL!I thought your aim was to reset all weapons on death and you told it.Then why are you try to GivePlayerWeapon on OnPlayerSpawn?? -_-

Quote:

instead of respawning with no weapons (which is what I want to happen)

Please tell once again what are trying to accomplish by that code?

And as Plottus said, don't save the weapon data to INI on OnPlayerDeath(You'll end up irritating players)

1st Reason:You have reset ,there is no need of fetching those variables .
2nd Reason:Instead declare a weapon enum or variables to hold the weapon data.

When player disconnects save the data.

This will optimize the code very much.
Reply
#8

Quote:
Originally Posted by Yashas
Посмотреть сообщение
LOL!I thought your aim was to reset all weapons on death and you told it.Then why are you try to GivePlayerWeapon on OnPlayerSpawn?? -_-

Please tell once again what are trying to accomplish by that code?
No my aim is to make sure when you connect you connect with the weapons that you disconnected with. But I put this in OnPlayerSpawn not OnPlayerConnect as when you connect your first taken to a log in screen and then a character selection menu so it would make things complicated. But I also want to make sure that when you die you loose all your guns so that when you spawn again you have no guns but also so players cant just disconnect after dieing so that when they log back in they have there guns again.

But the problem I am having is that when you spawn it reads your weapon data from the INI file and gives you the weapons that you last disconnected with, why aren't these values changed to 0 when you die so that when you spawn you get nothing?
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)