AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Nvault saving more than 10 items. (https://forums.alliedmods.net/showthread.php?t=293251)

Gasior 01-26-2017 21:33

Nvault saving more than 10 items.
 
Hi there,

I have plugin in which you can pick your skin for your knife and it saves it in nvault.

So I go to the menu pick number 9 (case 10 menu_handler) and proceed to save data in nvault it saves it as STEAM_ID_knife10.

When it loads nvault it reads it as if it was STEAM_ID_knife1 and loads skin 1 rather than 10.


So basically, my plugin reads the skin based solely on the first number and doesn't even consider the second one.

Here it is how it looks:

Code:

#include <amxmodx>
#include <engine> 
#include <nvault>

#define MAX_PLAYERS    32
#define MENUITEM_DISABLED    (1<<26)
#define ADMIN_FLAG_W (1<<22)

#define PLUGIN "Noze Menu"
#define VERSION "1.0" 
#define AUTHOR "Gasior"

#define TASK_INTERVAL 4.0

enum Knives
{
    NoKnifeSet = -1,
    Utwardzony,
    FazaDopplera,
    Wypalony,
    Zabarwiony,
    KUtwardzony,
    NozGriffa,
    KDamaszkowaStal,
    MarmurowyZanik,
    GammaDoppler,
    KDoppler,
    MZloty,
    Standardowy
}

enum KnifeModels
{
    ModelName[ 64 ],
    PlayerModel[ 64 ], 
    ViewModel[ 64 ]
}

new const g_ModelData[ Knives ][ KnifeModels ] = 
{
    { "Utwardzony" ,    "models/Noze/p_utwardzony.mdl" ,    "models/Noze/v_utwardzony.mdl" }, 
    { "Faza Dopplera" ,    "models/Noze/p_faza.mdl" ,        "models/Noze/v_faza.mdl" }, 
    { "Wypalony" ,        "models/Noze/p_wypalony.mdl" ,    "models/Noze/v_wypalony.mdl" }, 
    { "Zabarwiony" ,    "models/Noze/p_zabarwiony.mdl" ,    "models/Noze/v_zabarwiony.mdl" },
    { "KUtwardzony" ,    "models/Noze/p_kutw.mdl" ,        "models/Noze/v_kutw.mdl" },
    { "Noz Griffa" ,    "models/Noze/p_griff.mdl" ,        "models/Noze/v_griff.mdl" },
    { "KDamaszkowaStal" ,    "models/Noze/p_kdam.mdl" ,        "models/Noze/v_kdam.mdl" },
    { "Marmurowy Zanik" ,    "models/Noze/p_marmurowy.mdl" ,    "models/Noze/v_marmurowy.mdl" }, 
    { "Gamma Doppler" ,    "models/Noze/p_gamma.mdl" ,        "models/Noze/v_gamma.mdl" },
    { "KDoppler" ,    "models/Noze/p_kdop.mdl" ,        "models/Noze/v_kdop.mdl" },
    { "MZloty" ,    "models/Noze/p_mzloty.mdl" ,        "models/Noze/v_mzloty.mdl" },
    { "Standardowy" ,    "models/p_knife.mdl" ,        "models/v_knife.mdl" }

};

new Knives:knife_model[ MAX_PLAYERS + 1 ];
new g_szAuthID[ MAX_PLAYERS + 1 ][ 34 ];
new zapis_vault;

public plugin_init() { 
   
    register_plugin( PLUGIN , VERSION , AUTHOR );
   
    register_event( "CurWeapon" , "CurWeapon" , "be" , "1=1" );
   
    register_clcmd( "say /noze" , "display_knife" );
    register_clcmd( "say /n" , "display_knife" );
   
    zapis_vault = nvault_open( "g_Noze" );
   
    if( zapis_vault == INVALID_HANDLE )
        set_fail_state( "Nie moge otworzyc pliku :/" );
}

public plugin_precache() 

    for ( new Knives:i = Utwardzony ; i < Knives ; i++ )
    {
        precache_model( g_ModelData[ i ][ PlayerModel ] );
        precache_model( g_ModelData[ i ][ ViewModel ] );
    }


public client_authorized( id ) 
{
    get_user_authid( id , g_szAuthID[ id ] , charsmax( g_szAuthID[] ) );
   
    LoadData( id );
}

public display_knife(id) 
{
        new g_Menu = menu_create("Wybierz swoj noz!", "knife_menu");
       
        menu_additem(g_Menu, "Utwardzony", "", 0); // case 0
        menu_additem(g_Menu, "Faza Dopplera", "", 0); // case 1
        menu_additem(g_Menu, "Wypalony", "", 0); // case 2
        menu_additem(g_Menu, "Zabarwiony", "", 0); // case 3
        menu_additem(g_Menu, "Karambit Utwardzony", "", 0); // case 4
        menu_additem(g_Menu, "Noz Griffa", "", 0); // case 5
        menu_additem(g_Menu, "Karambit Damaszkowa Stal", "", 0); // case 6
        menu_additem(g_Menu, "Marmurowy Zanik", "", 0); // case 7
        menu_additem(g_Menu, "Gamma Doppler", "", 0); // case 8
        menu_additem(g_Menu, "Karambit Doppler", "", 0); // case 9
        menu_additem(g_Menu, "Noz Motylkowy Zloty", "", 0); // case 10
        menu_additem(g_Menu, "Standardowy", "", 0); // case 11

        menu_setprop(g_Menu, MPROP_EXIT, MEXIT_ALL);
        menu_setprop(g_Menu, MPROP_BACKNAME, "Wroc");
        menu_setprop(g_Menu, MPROP_NEXTNAME, "Nastepna Strona");
        menu_setprop(g_Menu, MPROP_EXITNAME, "Wyjdz");
        menu_setprop(g_Menu, MPROP_NOCOLORS, 1);

        menu_display(id, g_Menu, 0);

        return PLUGIN_HANDLED;

}

public knife_menu(id, menu, item)
{
        if(item == MENU_EXIT)
        {
                menu_cancel(id);
                return PLUGIN_HANDLED;
        }

        new command[6], name[64], access, callback;

        menu_item_getinfo(menu, item, access, command, sizeof command - 1, name, sizeof name - 1, callback);

        switch(item)
        {
                case 0: SetKnife( id , Knives:Utwardzony );
                case 1: SetKnife( id , Knives:FazaDopplera );
                case 2: SetKnife( id , Knives:Wypalony );
                case 3: SetKnife( id , Knives:Zabarwiony );
                case 4: SetKnife( id , Knives:KUtwardzony );
                case 5: SetKnife( id , Knives:NozGriffa );
                case 6: SetKnife( id , Knives:KDamaszkowaStal );
                case 7: SetKnife( id , Knives:MarmurowyZanik );
                case 8: SetKnife( id , Knives:GammaDoppler );
                case 9: SetKnife( id , Knives:KDoppler );
                case 10: SetKnife( id , Knives:MZloty );
                case 11: SetKnife( id , Knives:Standardowy );
        }
       
        SaveData( id );
        menu_destroy(menu);
        return PLUGIN_HANDLED;
}

public SetKnife(id , Knives:Knife) 
{
    new Knives:iModelIndex = NoKnifeSet;
   
    if ( get_user_weapon( id ) != CSW_KNIFE )
        return PLUGIN_HANDLED
   
    iModelIndex = Knife;
   
    knife_model[ id ] = iModelIndex
   
    entity_set_string( id , EV_SZ_viewmodel , g_ModelData[ iModelIndex ][ ViewModel ] );
    entity_set_string( id , EV_SZ_weaponmodel , g_ModelData[ iModelIndex ][ PlayerModel ] );
   
    return PLUGIN_HANDLED; 
}

public CurWeapon(id)
{
    SetKnife(id, knife_model[id])   
   
    return PLUGIN_HANDLED   
}

public SaveData(id)

    new szKey[ 40 ] , szData[ 3 ];
   
    formatex( szKey , charsmax( szKey ) , "%s_knife" , g_szAuthID[ id ] );
    num_to_str( _:knife_model[ id ] , szData , charsmax( szData ) );
   
    nvault_set( zapis_vault , szKey , szData );
}

public LoadData(id) 

    new szKey[ 40 ] , szData[ 3 ] , iTS; 
   
    formatex( szKey , charsmax( szKey ) , "%s_knife" , g_szAuthID[ id ] );
   
    if ( nvault_lookup( zapis_vault , szKey , szData , charsmax( szData ) , iTS ) ) 
    {
        knife_model[ id ] = Knives:str_to_num( szData );
    }
}

Now how do I make plugin read STEAM_ID_knife10 as number 10 rather than number 1.


Thanks, I hope I am clear.

OciXCrom 01-27-2017 06:19

Re: Nvault saving more than 10 items.
 
szData[ 3 ] - have you tried increasing this?

Gasior 01-27-2017 07:22

Re: Nvault saving more than 10 items.
 
Increased to 4 and works, hah. What would I do without alliedmods :) .


All times are GMT -4. The time now is 20:44.

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