AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   optimize nVault save/load? (https://forums.alliedmods.net/showthread.php?t=216498)

Blizzard_87 05-21-2013 19:30

optimize nVault save/load?
 
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?

hornet 05-21-2013 20:32

Re: optimize nVault save/load?
 
Thread number 3 on this subject. Maybe later when I get home.

Blizzard_87 05-21-2013 20:55

Re: optimize nVault save/load?
 
Quote:

Originally Posted by hornet (Post 1956078)
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 05-21-2013 23:45

Re: optimize nVault save/load?
 
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 ?

ConnorMcLeod 05-22-2013 00:52

Re: optimize nVault save/load?
 
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

Blizzard_87 05-22-2013 09:16

Re: optimize nVault save/load?
 
Quote:

Originally Posted by ConnorMcLeod (Post 1956140)
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...

ConnorMcLeod 05-22-2013 11:13

Re: optimize nVault save/load?
 
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
// }; 


Jhob94 05-22-2013 12:32

Re: optimize nVault save/load?
 
Quote:

Originally Posted by Blizzard_87 (Post 1956273)
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 :wink:

Blizzard_87 05-22-2013 17:45

Re: optimize nVault save/load?
 
Quote:

Originally Posted by ConnorMcLeod (Post 1956308)
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


ConnorMcLeod 05-22-2013 18:14

Re: optimize nVault save/load?
 
g_mItems[ m_iPistols ][ item ][ GunName ]


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

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