Raised This Month: $ Target: $400
 0% 

optimize nVault save/load?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 05-21-2013 , 19:30   optimize nVault save/load?
Reply With Quote #1

ive got this working but i know its very poor coding and i want to find a way to optimize it to use lesser lines... ive found this but unsure howto edit it to work with my current setup.

Variables


Save/Load


like i said its working the way i want... but just need example or easier explanation on howto optimize?
__________________
Blizzard_87 is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 05-21-2013 , 20:32   Re: optimize nVault save/load?
Reply With Quote #2

Thread number 3 on this subject. Maybe later when I get home.
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.
hornet is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 05-21-2013 , 20:55   Re: optimize nVault save/load?
Reply With Quote #3

Quote:
Originally Posted by hornet View Post
Thread number 3 on this subject. Maybe later when I get home.
as you can see ive attempted it and got it working just would like a better optimize. and sorry about the threads.
__________________
Blizzard_87 is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 05-21-2013 , 23:45   Re: optimize nVault save/load?
Reply With Quote #4

ok ive managed to do this in SaveData
Code:
public SavaData( id ) {     new AuthID[ 35 ];     get_user_authid( id, AuthID, charsmax( AuthID ) );     new vaultkey[ 64 ], vaultdata[ 356 ], iPos;         format( vaultkey, charsmax( vaultkey ),"%s-CS-Store",AuthID);         for( new i = 0; i < MAX_PISTOL; i++ ) {         iPos += format( vaultdata[ iPos ], charsmax( vaultdata ) - iPos, "%i ", OwnPistol[ id ][ i ] );     }     for( new i = 0; i < MAX_SHOTGUN; i++ ) {         iPos += format( vaultdata[ iPos ], charsmax( vaultdata ) - iPos, "%i ", OwnShotgun[ id ][ i ] );         //server_print( vaultdata );     }     for( new i = 0; i < MAX_SMG; i++ ) {         iPos += format( vaultdata[ iPos ], charsmax( vaultdata ) - iPos, "%i ", OwnSMG[ id ][ i ] );         //server_print( vaultdata );     }     for( new i = 0; i < MAX_RIFLE; i++ ) {         iPos += format( vaultdata[ iPos ], charsmax( vaultdata ) - iPos, "%i ", OwnRifle[ id ][ i ] );         //server_print( vaultdata );     }     for( new i = 0; i < MAX_EQUIP; i++ ) {         iPos += format( vaultdata[ iPos ], charsmax( vaultdata ) - iPos, "%i ", OwnEquip[ id ][ i ] );         //server_print( vaultdata );     }     iPos += format( vaultdata[ iPos ], charsmax( vaultdata ) - iPos, "%i %i", OwnM249[ id ], g_iCredits[ id ] );     server_print( vaultdata );         nvault_set( g_vault, vaultkey, vaultdata );     }

just trying to do the same for LoadData...

is it possible to use for loop with parse ?
__________________
Blizzard_87 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-22-2013 , 00:52   Re: optimize nVault save/load?
Reply With Quote #5

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.

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_P228CSW_ELITECSW_FIVESEVENCSW_USPCSW_GLOCK18CSW_DEAGLE, }, // PISTOLS
    
{CSW_XM1014CSW_M3}, // SHOTGUNS
    
{CSW_MAC10CSW_UMP45CSW_MP5NAVYCSW_TMPCSW_P90}, // SMGS
    
{CSW_SCOUTCSW_AUGCSW_SG550CSW_GALILCSW_FAMASCSW_AWPCSW_M4A1CSW_G3SG1CSW_SG552CSW_AK47}, // RIFFLES
    
CSW_M249// MACHINEGUN
    
{CSW_HEGRENADECSW_SMOKEGRENADECSW_FLASHBANGCSW_KNIFECSW_VESTCSW_VESTHELMCSW_DEFUSERCSW_NVGS// EQUIP
};

// Variables
new g_mPlayerStore33 ][ mSaveDatas ];

// 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_iVaultGETPLAYERAUTHID(idtrue), g_mPlayerStore[id], charsmax(g_mPlayerStore[])) )
    {
        for(new 
ii<sizeof(g_mPlayerStore[]); i++)
        {
            
g_mPlayerStore[id][i] -= '0'// convert all '0' and '1' chars to ingeters 0 and 1 values
        
}
    }
}

GETPLAYERAUTHID(idbGet false)
{
    static 
szAuthid[33][32];
    if( 
bGet )
    {
        
get_user_authid(idszAuthid[id], charsmax(szAuthid[]));
    }
    return 
szAuthid[id];
}

public 
client_disconnect(id)
{
    for(new 
ii<sizeof(g_mPlayerStore[]); i++)
    {
        
g_mPlayerStore[id][i] += '0'// convert all ingeters 0 and 1 values to '0' and '1' chars
    
}
    
nvault_set(g_iVaultGETPLAYERAUTHID(id), g_mPlayerStore[id]);


Edit :
And obviously :
Code:
g_mPlayerStore[id][m_iRiffles][1] = 1; // set AUG on 1
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 05-22-2013 at 00:58.
ConnorMcLeod is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 05-22-2013 , 09:16   Re: optimize nVault save/load?
Reply With Quote #6

Quote:
Originally Posted by ConnorMcLeod View Post
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


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...
__________________
Blizzard_87 is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-22-2013 , 11:13   Re: optimize nVault save/load?
Reply With Quote #7

Then you can do something like this :

PHP Code:
//Constants
new const g_mItemsmSaveDatas ][ GunItems ] =
{
    
// Pistols
    
{
        { 
"USP""weapon_usp"CSW_USP100 }, // = 0
        
"Glock""weapon_glock18"CSW_GLOCK18120 }, // = 1
        
"Deagle""weapon_deagle"CSW_DEAGLE35 }, // = 2
        
"228 Compact""weapon_p228"CSW_P22852 }, // =3
        
"Dual Elites""weapon_elite"CSW_ELITE120 }, // = 4
        
"Five-Seven""weapon_fiveseven"CSW_FIVESEVEN100 // = 5
    
},
    
// ShotGuns
    
{
        
}
// 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
// }; 
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Blizzard_87
Veteran Member
Join Date: Oct 2012
Old 05-22-2013 , 17:45   Re: optimize nVault save/load?
Reply With Quote #8

Quote:
Originally Posted by ConnorMcLeod View Post
Then you can do something like this :

PHP Code:
//Constants
new const g_mItemsmSaveDatas ][ GunItems ] =
{
    
// Pistols
    
{
        { 
"USP""weapon_usp"CSW_USP100 }, // = 0
        
"Glock""weapon_glock18"CSW_GLOCK18120 }, // = 1
        
"Deagle""weapon_deagle"CSW_DEAGLE35 }, // = 2
        
"228 Compact""weapon_p228"CSW_P22852 }, // =3
        
"Dual Elites""weapon_elite"CSW_ELITE120 }, // = 4
        
"Five-Seven""weapon_fiveseven"CSW_FIVESEVEN100 // = 5
    
},
    
// ShotGuns
    
{
        
}
// 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
// }; 
ah i see then i can use something like this in rest of code...

Code:
g_mItems[ m_iPistols ][ GunName ][ item ]
? havent tried yet only mobile.

EDIT:

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_mItems[ mSaveDatas ][ GunItems ] = {     // Pistols     {         { "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     },     // ShotGuns     {         { "Pump Shotgun", "weapon_m3", CSW_M3, 32 }, // = 0         { "Auto Shotgun", "weapon_xm1014", CSW_XM1014, 32 } // = 1     },     // SMGs     {         { "MP5", "weapon_mp5navy", CSW_MP5NAVY, 120 }, // = 0         { "TMP", "weapon_tmp", CSW_TMP, 120 }, // = 1         { "P90", "weapon_p90", CSW_P90, 100 }, // = 2         { "Mac10", "weapon_mac10", CSW_MAC10, 100 }, // = 3         { "UMP", "weapon_ump45", CSW_UMP45, 100 } // = 4     },     // Rifles     {         { "Clarion", "weapon_famas", CSW_FAMAS, 90 }, // = 0         { "Krieg SG552", "weapon_sg552", CSW_SG552, 90 }, // = 1         { "AK47", "weapon_ak47", CSW_AK47, 90 }, // = 2         { "M4A1", "weapon_m4a1", CSW_M4A1, 90 }, // = 3         { "Bullpup", "weapon_aug", CSW_AUG, 90 }, // = 4         { "Scout", "weapon_scout", CSW_SCOUT, 90 }, // = 5         { "AWP", "weapon_awp", CSW_AWP, 90 }, // = 6         { "CT AutoSniper", "weapon_g3sg1", CSW_G3SG1, 90 }, // = 7         { "T AutoSniper", "weapon_sg550", CSW_SG550, 90 }, // = 8         { "Galil", "weapon_galil", CSW_GALIL, 90 } // = 9     },     // MachineGun ( Para )     {         { "M249 ( Para )", "weapon_m249", CSW_M249, 200 } // = 0     },     // Equipment     {         { "Kevlar", "item_kevlar" }, // 0         { "Kevlar + Helmet", "item_assaultsuit" }, // = 1         { "Flashbang Grenade", "weapon_flashbang", CSW_FLASHBANG, 2 }, // = 2         { "HE Grenade", "weapon_hegrenade", CSW_HEGRENADE, 1 }, // = 3         { "Smoke Grenade", "weapon_smokegrenade", CSW_SMOKEGRENADE, 1 }, // = 4         { "Defusal Kit", "item_thighpack" }, // = 5         { "Nighvision Goggles" }, // = 6         { "Shield", "weapon_shield" } // = 7        }};

and im getting these errors

Code:
Welcome to the AMX Mod X 1.8.1-300 Compiler.
Copyright (c) 1997-2013 ITB CompuPhase, AMX Mod X Team

Error: Invalid symbol name "" on line 96
Error: Start of function body without function header on line 101
Error: Start of function body without function header on line 109
Error: Start of function body without function header on line 122
Error: Start of function body without function header on line 126
Error: Invalid function or declaration on line 136
__________________

Last edited by Blizzard_87; 05-22-2013 at 18:14.
Blizzard_87 is offline
Jhob94
AMX Mod X Donor
Join Date: Jul 2012
Old 05-22-2013 , 12:32   Re: optimize nVault save/load?
Reply With Quote #9

Quote:
Originally Posted by Blizzard_87 View Post
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] = { &nbsp;&nbsp;&nbsp;&nbsp;{CSW_P228, CSW_ELITE, CSW_FIVESEVEN, CSW_USP, CSW_GLOCK18, CSW_DEAGLE, }, // PISTOLS &nbsp;&nbsp;&nbsp;&nbsp;{CSW_XM1014, CSW_M3}, // SHOTGUNS &nbsp;&nbsp;&nbsp;&nbsp;{CSW_MAC10, CSW_UMP45, CSW_MP5NAVY, CSW_TMP, CSW_P90}, // SMGS &nbsp;&nbsp;&nbsp;&nbsp;{CSW_SCOUT, CSW_AUG, CSW_SG550, CSW_GALIL, CSW_FAMAS, CSW_AWP, CSW_M4A1, CSW_G3SG1, CSW_SG552, CSW_AK47}, // RIFFLES &nbsp;&nbsp;&nbsp;&nbsp;CSW_M249, // MACHINEGUN &nbsp;&nbsp;&nbsp;&nbsp;{CSW_HEGRENADE, CSW_SMOKEGRENADE, CSW_FLASHBANG, CSW_KNIFE, CSW_VEST, CSW_VESTHELM, CSW_DEFUSER, CSW_NVGS} // EQUIP };
Connor said that likes you and gave you a code and you recuse part of code?
Omfg I am jealous of my retarded friend
__________________
Jhob94 is offline
wickedd
Veteran Member
Join Date: Nov 2009
Old 05-22-2013 , 23:28   Re: optimize nVault save/load?
Reply With Quote #10

Do you really think csstore.inc is necessary?

Edit: It would help if you attach it.
__________________
Just buy the fucking game!!!!
I hate No-Steamers and lazy ass people.

Last edited by wickedd; 05-22-2013 at 23:28.
wickedd is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:17.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode