Saving Player Weapons With Y_INI??
#1

Hello forum members,
Recently i have switched from the DINI file system to the YINI system after much convincing. So far i have found this system very similar and easy to use and i have decided to experiment. I have a player info enum in my gamemode,

Code:
enum Info
{
	pPass,
	pMoney,
	pHealth,
	pArmour,
	pScore,
	pKills,
	pDeaths,
	pWep1,
	pWep1a,
	pWep2,
	pWep2a,
	pWep3,
	pWep3a,
	pWep4,
	pWep4a,
	pWep5,
	pWep5a,
	pWep6,
	pWep6a,
	pWep7,
	pWep7a,
	pWep8,
	pWep8a,
	pWep9,
	pWep9a,
	pWep10,
	pWep10a,
	pWep11,
	pWep11a,
	pWep12,
	pWep12a
}
new PlayerInfo[MAX_PLAYERS][Info];
I have successfully set up the saving and loading of the first 5 items in the Info enum, however i want to include a way of saving a players weapons aswell. Enum Description: pWep1 is the weapon id and pWep1a is the ammo of weapon 1. I have never set up a way of saving and loading a players weapons and i am hoping that someone can help me to create a way. If anyone can help i would appreciate it.
Reply
#2

use GetPlayerWeaponData to get the weapons and ammo info into the enum

use GivePlayerWeapon to give them their weapons, I dont think you can give weapons in OnPlayerConnect,

I generally do it in OnPlayerSpawn,
but account for OnPlayerDeath, and Class Selection/spectating
as all of them cause a respawn.


save / load the data same way as you do the other vars.

all the functions can be found on the wiki with examples.
Reply
#3

I just recently did something like this, and it writes it properly, I am still having issues with the loading of weapons though, but I use this code everywhere I want to save... may be a little clunky, but I like seeing what the code is :P
pawn Code:
//Save Weapons and Ammo
    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]);
Reply
#4

//DELETED
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)