|
Veteran Member
|

05-22-2013
, 09:16
Re: optimize nVault save/load?
|
#6
|
Quote:
Originally Posted by ConnorMcLeod
Because i like you, and dispite the fact you've just broken a forum rule (bump / double post), i gonna show you a smart way.
Your Code
PHP Code:
enum _:mSaveDatas
{
m_iPistols[6],
m_iShotGuns[2],
m_iSmgs[5],
m_iRiffles[10],
m_iMachineGun,
m_iEquipments[8]
}
new const g_iItemsIndexes[mSaveDatas] =
{
{CSW_P228, CSW_ELITE, CSW_FIVESEVEN, CSW_USP, CSW_GLOCK18, CSW_DEAGLE, }, // PISTOLS
{CSW_XM1014, CSW_M3}, // SHOTGUNS
{CSW_MAC10, CSW_UMP45, CSW_MP5NAVY, CSW_TMP, CSW_P90}, // SMGS
{CSW_SCOUT, CSW_AUG, CSW_SG550, CSW_GALIL, CSW_FAMAS, CSW_AWP, CSW_M4A1, CSW_G3SG1, CSW_SG552, CSW_AK47}, // RIFFLES
CSW_M249, // MACHINEGUN
{CSW_HEGRENADE, CSW_SMOKEGRENADE, CSW_FLASHBANG, CSW_KNIFE, CSW_VEST, CSW_VESTHELM, CSW_DEFUSER, CSW_NVGS} // EQUIP
};
// Variables
new g_mPlayerStore[ 33 ][ mSaveDatas + 1 ];
// Vault
new g_iVault;
public plugin_init()
{
g_iVault = nvault_open("CS-Store");
}
public plugin_end()
{
nvault_close(g_iVault);
}
public client_authorized(id)
{
if( nvault_get(g_iVault, GETPLAYERAUTHID(id, true), g_mPlayerStore[id], charsmax(g_mPlayerStore[])) )
{
for(new i; i<sizeof(g_mPlayerStore[]); i++)
{
g_mPlayerStore[id][i] -= '0'; // convert all '0' and '1' chars to ingeters 0 and 1 values
}
}
}
GETPLAYERAUTHID(id, bGet = false)
{
static szAuthid[33][32];
if( bGet )
{
get_user_authid(id, szAuthid[id], charsmax(szAuthid[]));
}
return szAuthid[id];
}
public client_disconnect(id)
{
for(new i; i<sizeof(g_mPlayerStore[]); i++)
{
g_mPlayerStore[id][i] += '0'; // convert all ingeters 0 and 1 values to '0' and '1' chars
}
nvault_set(g_iVault, GETPLAYERAUTHID(id), g_mPlayerStore[id]);
}
Edit :
And obviously :
Code:
g_mPlayerStore[id][m_iRiffles][1] = 1; // set AUG on 1
|
thanks conner and im sorry for my bump/double post donno what i was thinking.
i didnt need to use the
Code:
new const g_iItemsIndexes[mSaveDatas] =
{
{CSW_P228, CSW_ELITE, CSW_FIVESEVEN, CSW_USP, CSW_GLOCK18, CSW_DEAGLE, }, // PISTOLS
{CSW_XM1014, CSW_M3}, // SHOTGUNS
{CSW_MAC10, CSW_UMP45, CSW_MP5NAVY, CSW_TMP, CSW_P90}, // SMGS
{CSW_SCOUT, CSW_AUG, CSW_SG550, CSW_GALIL, CSW_FAMAS, CSW_AWP, CSW_M4A1, CSW_G3SG1, CSW_SG552, CSW_AK47}, // RIFFLES
CSW_M249, // MACHINEGUN
{CSW_HEGRENADE, CSW_SMOKEGRENADE, CSW_FLASHBANG, CSW_KNIFE, CSW_VEST, CSW_VESTHELM, CSW_DEFUSER, CSW_NVGS} // EQUIP
};
as i already had a setup for those. this is how i got it working
Code:
// Enum
enum _:GunItems {
GunName[ 32 ], GunWeapon[ 32 ], csw, ammo
};
enum _:SayCmds {
Say[ 32 ], Func[ 32 ]
};
enum _:mSaveDatas {
m_iPistols[6],
m_iShotGuns[2],
m_iSmgs[5],
m_iRiffles[10],
m_iMachineGun,
m_iEquipments[8]
}
// Variables
new g_mPlayerStore[ 33 ][ mSaveDatas + 1 ];
//Constants
new const g_szPistols[ MAX_PISTOL ][ GunItems ] = {
{ "USP", "weapon_usp", CSW_USP, 100 }, // = 0
{ "Glock", "weapon_glock18", CSW_GLOCK18, 120 }, // = 1
{ "Deagle", "weapon_deagle", CSW_DEAGLE, 35 }, // = 2
{ "228 Compact", "weapon_p228", CSW_P228, 52 }, // =3
{ "Dual Elites", "weapon_elite", CSW_ELITE, 120 }, // = 4
{ "Five-Seven", "weapon_fiveseven", CSW_FIVESEVEN, 100 } // = 5
};
etc etc...
thanks heaps...
__________________
|
|