Raised This Month: $ Target: $400
 0% 

Nvault how to save models?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 03-24-2022 , 23:35   Nvault how to save models?
Reply With Quote #1

well I made a menu for knifes according to certain conditions, and it works but I would like to be able to save the chosen models in nvault so I don't have to be choosing them every new map.

and I was testing how to use nvault, at the moment I understood something reading examples of some variables, but I don't understand how to save models

i try this But it does not work:

PHP Code:

//Include the nvault file
#include <nvault>

new knife_model[33], vModel[56]
new 
g_MenuCallback;            //Create a global variable to hold our callback

new g_iVaultID
new gMemoryTableNames[64][32]                // Stores players name for a key
new g_iData[33]
//----------------------------------------------------------------------------------------------
public plugin_init()
{
     
register_plugin("plugin KnifeMenuSH""1.0""Lucas Cab Arje")

    
register_clcmd("say /knife""KnifeMenu")        // Para llamar al menu de fakas

    //Create our callback and save it to our variable
    
g_MenuCallback menu_makecallback("menuitem_callback");    //The first parameter is the public function to be called when a menu item is being shown.
    
    // Eventos
    
register_event("CurWeapon","CurWeapon","be","1=1")     // Para cambiar las fakas models
}

public 
plugin_end( )
{
    
nvault_closeg_iVaultID )
}

public 
plugin_cfg( )
{
    
g_iVaultID nvault_open"knife_vault" )
    
    if( 
g_iVaultID == INVALID_HANDLE )
    {
        
set_fail_state"Error opening Knife Nvault" )
    }
}

public 
client_putinserverPlayer )
{
    
get_user_name(PlayergMemoryTableNames[Player], charsmax(gMemoryTableNames[]) )
    
Load_StuffPlayer )
}

public 
SetKnife(idKnife
{
    if (!
sh_is_active() || !is_user_alive(id) ) return; // PLUGIN_HANDLED
    
    
knife_model[id] = Knife 
    
    
new szSelection[4]
    
    switch(
Knife) {
        
// Estas Fakas van a partir de la primera Pagina
        //-----------    Ace Of Katanas
        
case 0: {
            if ( 
gHasAceOfKatanas[id] ) {
                
gHasPower[id] = true 
                format
(vModel,55,"models/shmod/ace_v_knife.mdl")
                
switch_model(id)
                
g_iDataid ] = str_to_num(szSelection)
            }
            else {
                
gHasPower[id] = false
            
}
        }
        
//-----------    Batman
        
case 1: {
            if ( 
gHasBatman[id] ) {
                
gHasPower[id] = true 
                format
(vModel,55,"models/shmod/batmanknife_v.mdl")
                
switch_model(id)
                
g_iDataid ] = str_to_num(szSelection)
            }
            else {
                
gHasPower[id] = false
            
}
        }
        
//-----------    Chucky
        
case 2: {
            if ( 
HasChucky[id] ) {
                
gHasPower[id] = true 
                format
(vModel,55,"models/shmod/chucky_knife.mdl")
                
switch_model(id)
                
g_iDataid ] = str_to_num(szSelection)
            }
            else {
                
gHasPower[id] = false
            
}
        }
        
//-----------    Darth Maul
        
case 3: {
            if ( 
gHasDarthMaulPowers[id] ) {
                
gHasPower[id] = true 
                format
(vModel,55,"models/shmod/darthmaul_knife.mdl"
                
switch_model(id)
                
g_iDataid ] = str_to_num(szSelection)
            }
            else     {
                
gHasPower[id] = false
            
}    
        }
    }
    
    new 
gMemoryTableNames234 ]
    
formatexgMemoryTableNames2charsmaxgMemoryTableNames2 ), "%sTEST"gMemoryTableNamesid ] )
    
    
formatexszSelectioncharsmaxszSelection ), "%sTEST"g_iDataid ] ) 
    
    
nvault_setg_iVaultIDgMemoryTableNames2szSelection )    
}

Load_StuffPlayer )
{
    new 
gMemoryTableNames234 ]
    
formatexgMemoryTableNames2charsmaxgMemoryTableNames2 ), "%sTEST"gMemoryTableNamesPlayer ] )
    
    
nvault_getg_iVaultIDgMemoryTableNames2 )
}
    
public 
CurWeapon(id
{
    if ( !
gHasPower[id] ) return
    
// Set Knife Model
    
SetKnife(idknife_model[id])  
    
    
switch_model(id
}

switch_model(id)
{
    if (!
sh_is_active() || !is_user_alive(id) ) return
    
    if (
get_user_weapon(id) == CSW_KNIFE) {
        
set_pev(idpev_viewmodel2vModel)
    }

Arje is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-24-2022 , 23:54   Re: Nvault how to save models?
Reply With Quote #2

You are sharing a global variable across all players, using this to set the model in switch_model. My commendation is to ditch this global variable and add a parameter to switch_model(), to allow you to specify the model to set.
PHP Code:
switch_model(id , const szModel[] )
{
    if (!
sh_is_active() || !is_user_alive(id) ) return
    
    if (
get_user_weapon(id) == CSW_KNIFE) {
        
set_pev(idpev_viewmodel2szModel)
    }

You should store player info based on their steam id, not name.

This is not doing anything. When retrieving a string, you must specify the string variable to store the data in.
PHP Code:
nvault_getg_iVaultIDgMemoryTableNames2 
PHP Code:
new szData64 ];
nvault_getg_iVaultIDgMemoryTableNames2 szData charsmaxszData ) );

//And then you could do
switch_model(id szData 
Try the above and see if you can make it work
__________________

Last edited by Bugsy; 03-24-2022 at 23:55.
Bugsy is offline
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 03-25-2022 , 13:53   Re: Nvault how to save models?
Reply With Quote #3

Thanks for answering, I ended up using this way and it works for me, but my next question, Is it how I store a value like if it has it, it's true, if not, it's false?

for example I want to make a buy menu, and if you buy an item, the item will be saved to be used, how would you do the latter?

This code works for me:
PHP Code:
/* Plugin generated by AMXX-Studio */

#include <superheromod> 

//Include the nvault file
#include <nvault>

// para saber que heroes tiene
new bool:gHasAceOfKatanas[SH_MAXSLOTS+1]
new 
bool:gHasBatman[SH_MAXSLOTS+1]
new 
bool:HasBlade[SH_MAXSLOTS+1]
new 
bool:HasChucky[SH_MAXSLOTS+1]
new 
bool:gHasDarthMaulPowers[SH_MAXSLOTS+1]
new 
bool:g_hasVader[SH_MAXSLOTS+1]
new 
bool:g_haspalpatinePowers[SH_MAXSLOTS+1]
new 
bool:gHasObiPower[SH_MAXSLOTS+1]
new 
bool:ghasRiddickPowers[SH_MAXSLOTS+1]
new 
bool:ghasWolvPowers[SH_MAXSLOTS+1]
new 
bool:gHasYodaPower[SH_MAXSLOTS+1]
new 
bool:gHasPower[SH_MAXSLOTS+1]

new 
aceIDbatmanIDbladeID chuckyIDdarthmaulID
new vaderIDpalpatineIDobiwanIDriddickIDwolvIDyodaID


enum Knives 

    
NoKnifeSet = -1
    
Ace
    
Batman
    
Blade
    
Chucky
    
DarthMaul,
    
Vader,
    
Palpatine,
    
Obiwan
    
Riddick,
    
Wolv,
    
Yoda


enum KnifeModels 

    
ModelName64 ],
    
ViewModel64 
}

new const 
g_ModelData[Knives][KnifeModels] =  

    { 
"Ace"     ,       "models/shmod/ace_v_knife.mdl" },  
    { 
"Batman"     ,      "models/shmod/batmanknife_v.mdl" },  
    { 
"Blade"     ,        "models/shmod/blade_knife_v.mdl" },  
    { 
"Chucky"     ,      "models/shmod/chucky_knife.mdl" },
    { 
"DarthMaul",     "models/shmod/darthmaul_knife.mdl" },
    { 
"Vader"     ,    "models/shmod/darth_saber_red_v.mdl" },
    { 
"Palpatine",    "models/shmod/darth_saber_red_v.mdl" },
    { 
"Obiwan"     ,    "models/shmod/obiwan_saber_blu_v.mdl" },  
    { 
"Riddick"     ,     "models/shmod/riddick_knife.mdl" },
    { 
"Wolv"     ,    "models/shmod/wolv_knife.mdl" },
    { 
"Yoda"     ,        "models/shmod/yoda_v.mdl" }
}

new 
Knives:knife_model[SH_MAXSLOTS1];
new 
g_MenuCallback;            //Create a global variable to hold our callback

new g_iVaultID
new g_szSteamIDMAX_PLAYERS ][ 34 ];     // steam ID
// new gMemoryTableNames[64][32]                // Stores players name for a key
//----------------------------------------------------------------------------------------------
public plugin_init()
{
     
register_plugin("plugin KnifeMenuSH""1.0""Lucas Cab Arje")

    
register_clcmd("say /knife""KnifeMenu")        // Para llamar al menu de fakas
    
register_clcmd("say /cuchi""KnifeMenu")        // Para llamar al menu de fakas
    
register_clcmd("say /faka""KnifeMenu")        // Para llamar al menu de fakas
    
register_clcmd("say /menufakas""KnifeMenu")        // Para llamar al menu de fakas

    //Create our callback and save it to our variable
    
g_MenuCallback menu_makecallback("menuitem_callback");    //The first parameter is the public function to be called when a menu item is being shown.
    
    // Eventos
    
register_event("CurWeapon","CurWeapon","be","1=1")     // Para cambiar las fakas models
    
set_task(0.2"cache_id");                   //we need to let superhero cache all the heros to avoid issues
}

public 
plugin_end( )
{
    
nvault_closeg_iVaultID )
}

public 
plugin_cfg( )
{
    
g_iVaultID nvault_open"knife_vault" )
    
    if( 
g_iVaultID == INVALID_HANDLE ) {
        
set_fail_state"Error opening Knife Nvault" )
    }
}

// public client_putinserver(Player)
public client_authorized(Player)  
{
    
//get_user_name(Player, gMemoryTableNames[Player], charsmax(gMemoryTableNames[]) )
    
get_user_authidPlayerg_szSteamID[Player], charsmax(g_szSteamID[ ]) )
    
Load_StuffPlayer )
}
//----------------------------------------------------------------------------------------------
public cache_id() 
{
    
// Primera Pagin Menu
    
aceID         sh_get_hero_id("Ace of Katanas");
    
batmanID     sh_get_hero_id("Batman");
    
bladeID     sh_get_hero_id("Blade");
    
chuckyID     sh_get_hero_id("Chucky");
    
darthmaulID     sh_get_hero_id("Darth Maul");
    
palpatineID     sh_get_hero_id("Emperador Palpatine");
    
vaderID     sh_get_hero_id("Darth Vader");
    
// Segunda Pagina Menu 
    
obiwanID     sh_get_hero_id("Obi Wan Kenobi");
    
riddickID     sh_get_hero_id("Riddick");
    
wolvID         sh_get_hero_id("Wolverine");
    
yodaID         sh_get_hero_id("Yoda");
}
//----------------------------------------------------------------------------------------------
public sh_hero_init(idheroIDmode)
{
    
// Ace Of Katanas
    
if ( aceID == heroID )
        
gHasAceOfKatanas[id] = mode true false
    
// Batman
    
else if ( batmanID == heroID )
        
gHasBatman[id] = mode true false 
    
// Blade
    
else if ( bladeID == heroID )
        
HasBlade[id] = mode true false
    
// Chucky
    
else if ( chuckyID == heroID )
        
HasChucky[id] = mode true false
    
// Darth Maul    
    
else if ( darthmaulID == heroID )
        
gHasDarthMaulPowers[id] = mode true false
    
// Darth Vader    
    
else if ( vaderID == heroID )
        
g_hasVader[id] = mode true false
    
// Emperador Palpatine
    
else if ( palpatineID == heroID )
        
g_haspalpatinePowers[id] = mode true false
    
// Obi wan Kenobi
    
else if ( obiwanID == heroID )
        
gHasObiPower[id] = mode true false
    
// Riddick    
    
else if ( riddickID == heroID )
        
ghasRiddickPowers[id] = mode true false
    
// Wolverine    
    
else if ( wolvID == heroID )
        
ghasWolvPowers[id] = mode true false
    
// Yoda    
    
else if ( yodaID == heroID )
        
gHasYodaPower[id] = mode true false
}
//----------------------------------------------------------------------------------------------
public KnifeMenu(id)
{
    new 
menu menu_create"\rRevive Player Menu!:""menu_handler" );

    
// Esto son de la Primera pagina del menu                    //    Item    Key
    
menu_additemmenu"\wAce Katanas."""0g_MenuCallback );            //    0    1
    
menu_additemmenu"\wBatman."""0g_MenuCallback );            //    1    2
    
menu_additemmenu"\wBlade."""0g_MenuCallback );                //    2    3
    
menu_additemmenu"\wChucky."""0g_MenuCallback );            //    3    4
    
menu_additemmenu"\wDarth Maul."""0g_MenuCallback );            //    4    5
    
menu_additemmenu"\wDarth Vader."""0g_MenuCallback );            //    5    6
    
menu_additemmenu"\wEmperador Palpatine."""0g_MenuCallback );        //    6    7
    
    // Esto son de la Segunda pagina del menu    
    
menu_additemmenu"\wObi Wan Kenobi."""0g_MenuCallback );        //    7    1    
    
menu_additemmenu"\wRiddick."""0g_MenuCallback );            //    8    2
    
menu_additemmenu"\wWolverine."""0g_MenuCallback );            //    9    3
    
menu_additemmenu"\wYoda."""0g_MenuCallback );                //    10    4
    
    // El Key 8 reservado para Back Menu -- Y el Key 9 Para el More Menu -- esto es automatico no lo controlo
    
menu_display(idmenu0);
}

public 
menu_handler(idmenuitem)
{
    if ( 
item == MENU_EXIT ) {
        
menu_destroymenu );
        return 
PLUGIN_HANDLED;
    }
    
    new 
szData[6], szName[64];
    new 
item_accessitem_callback;
    
menu_item_getinfomenuitemitem_accessszDatacharsmax(szData), szName,charsmax(szName), item_callback );
    
    switch(
item) {
        
// Estas Fakas van a partir de la Primera Pagina del Menu
        //-----------    Ace Of Katanas
        
case 0: {
            
SetKnifeidKnives:Ace);
            
sh_chat_message(id, -1"Seleccionaste las Katanas Dobles de Ace of Katana.")
        }
        
//-----------    Batman
        
case 1: {
            
SetKnifeidKnives:Batman);
            
sh_chat_message(id, -1"Seleccionaste la Faka de Batman.")
        }
        
//-----------    Blade
        
case 2: {
            
SetKnifeidKnives:Blade);
            
sh_chat_message(id, -1"Seleccionaste el Hacha de Blade.")
        }
        
//-----------    Chucky
        
case 3: {
            
SetKnifeidKnives:Chucky);
            
sh_chat_message(id, -1"Seleccionaste la Faka de Chucky.")    
        }
        
//-----------    Darth Maul
        
case 4: {
            
SetKnifeidKnives:DarthMaul);
            
sh_chat_message(id, -1"Seleccionaste el Sable de Luz Doble de Darth Maul.")
        }
        
//-----------    Darth Vader
        
case 5: {
            
SetKnifeidKnives:Vader);
            
sh_chat_message(id, -1"Seleccionaste el Sable de Luz de Darth Vader.")
        }
        
//-----------    Emperador Palpatine
        
case 6: {
            
SetKnifeidKnives:Palpatine);
            
sh_chat_message(id, -1"Seleccionaste el Sable de Luz del Emperador Palpatine.")
        }
        
// Estas Fakas van a partir de la Segunda Pagina del Menu
        //-----------    Obi wan
        
case 7: {
            
SetKnifeidKnives:Obiwan);
            
sh_chat_message(id, -1"Seleccionaste el Sable de Luz de Obi Wan Kenobi.")
        }
        
//-----------    Ridicck
        
case 8: {
            
SetKnifeidKnives:Riddick);
            
sh_chat_message(id, -1"Seleccionaste la Faka de Riddick.")
        }
        
//-----------    Wolverine
        
case 9: {
            
SetKnifeidKnives:Wolv);
            
sh_chat_message(id, -1"Seleccionaste las Garras de Wolverine.")
        }
        
//-----------    Yoda - Yoda Wisdom's
        
case 10: {
            
SetKnifeidKnives:Yoda);
            
sh_chat_message(id, -1"Seleccionaste el Sable de Luz de Yoda.")
        }
        case 
MENU_EXIT: {
            
sh_chat_message(id, -1"No Seleccionaste Ninguna Faka.")
        }
    }
    
    
SaveData(id);
    
//lets finish up this function by destroying the menu with menu_destroy, and a return
    
menu_destroy(menu);
    return 
PLUGIN_HANDLED;
}

public 
SetKnife(id Knives:Knife)  

    if (!
sh_is_active() || !is_user_alive(id) ) return PLUGIN_HANDLED;
    
    new 
Knives:iModelIndex NoKnifeSet;

    
iModelIndex Knife;
    
knife_model[id] = iModelIndex;
    
    if ( 
get_user_weapon(id) == CSW_KNIFE ) { 
        
entity_set_stringid EV_SZ_viewmodel g_ModelData[iModelIndex][ViewModel] );
    }
    
    return 
PLUGIN_HANDLED;    
}

public 
CurWeapon(id

    if ( 
is_user_alive(id) ) 
        
SetKnife(idknife_model[id])
        
    return 
PLUGIN_HANDLED    


public 
SaveData(id
{  
    new 
szKey40 ] , szData]; 
     
    
//formatex( szKey , charsmax( szKey ) , "%s_knife" ,  gMemoryTableNames[id] );
    
formatexszKey charsmaxszKey ) , "%s_knife" ,  g_szSteamID[id] );

    
num_to_str_:knife_modelid ] , szData charsmaxszData ) ); 
     
    
nvault_setg_iVaultID szKey szData ); 


public 
Load_Stuff(id)  
{  
    new 
szKey[40] , szData[4] , iTS;  
    
    
// formatex( szKey , charsmax( szKey ) , "%s_knife" , gMemoryTableNames[id] ); 
    
formatexszKey charsmaxszKey ) , "%s_knife" g_szSteamID[id] ); 
     
    if ( 
nvault_lookupg_iVaultID szKey szData charsmaxszData ) , iTS ) ) { 
        
knife_modelid ] = Knives:str_to_numszData ); 
    }
}
// This is our callback function. Return ITEM_ENABLED, ITEM_DISABLED, or ITEM_IGNORE.
public menuitem_callback(idmenuitem)
{
    
// Ace Katanas
    
if ( item == && !gHasAceOfKatanas[id] ) {
        
menu_item_setname(menuitem"\dAce Katanas.");
        return 
ITEM_DISABLED;
    }
    
// Batman
    
if ( item == && !gHasBatman[id] ) {
        
menu_item_setname(menuitem"\dBatman.");
        return 
ITEM_DISABLED;
    }
    
// Blade
    
if ( item == && !HasBlade[id]) {
        
menu_item_setname(menuitem"\dBlade.");
        return 
ITEM_DISABLED;
    }
    
// Chucky
    
if ( item == && !HasChucky[id] ) {
        
menu_item_setname(menuitem"\dChucky.");
        return 
ITEM_DISABLED;
    }
    
// Darth Maul
    
if ( item == && !gHasDarthMaulPowers[id] ) {
        
menu_item_setname(menuitem"\dDarth Maul.");
        return 
ITEM_DISABLED;
    }
    
// Darth Vader
    
if ( item == && !g_hasVader[id] ) {
        
menu_item_setname(menuitem"\dDarth Vader.");
        return 
ITEM_DISABLED;
    }
    
// Emperador Palpatine
    
if ( item == && !g_haspalpatinePowers[id] ) {
        
menu_item_setname(menuitem"\dEmperador Palpatine.");
        return 
ITEM_DISABLED;
    }
    
// Obi Wan Kenobi
    
if ( item == && !gHasObiPower[id] ) {
        
menu_item_setname(menuitem"\dObi Wan Kenobi.");
        return 
ITEM_DISABLED;
    }
    
// Riddick
    
if ( item == && !ghasRiddickPowers[id] )
    {
        
menu_item_setname(menuitem"\dRiddick.");
        return 
ITEM_DISABLED;
    }
    
// Wolverine
    
if ( item == && !ghasWolvPowers[id] ) {
        
menu_item_setname(menuitem"\dWolverine.");
        return 
ITEM_DISABLED;
    }
    
// Yoda - Yoda wisdow's
    
if ( item == 10 && !gHasYodaPower[id] ) {
        
menu_item_setname(menuitem"\dYoda.");
        return 
ITEM_DISABLED
    }
    
    
//Otherwise we can just ignore the return value
    
return ITEM_IGNORE;     //Note that returning ITEM_ENABLED will override the admin flag check from menu_additem    

Arje is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-25-2022 , 16:23   Re: Nvault how to save models?
Reply With Quote #4

When an item is bought, write it to nvault. If you want to know if an item exists in nvault, use nvault_lookup().
__________________
Bugsy is offline
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 03-25-2022 , 23:04   Re: Nvault how to save models?
Reply With Quote #5

I have no idea how to do it, do u have a example?

I'm try to find some examples but i can't find

should I keep the option to enable that I can choose the skin option in the menu?

i mean, for example when he buy item save data or condition to enable item, maybe like this?
PHP Code:
new szKey40 ] , szData] , iTS;  
   
    
formatexszKey charsmaxszKey ) , "%s_knife" g_szAuthIDid ] ); 
    if ( 
item == && !nvault_lookupg_iVaultIDszKey szData charsmaxszData ) , iTS ) { 
       return 
ITEM_DISABLED;
    } 
, and if he bought the item enabled and he can put the skin?

but i dont know how to code that condition
Arje is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-26-2022 , 00:50   Re: Nvault how to save models?
Reply With Quote #6

If you want help, you need to post your full code that can be compiled. I was not even going to spend time on this but I figured I'd do what I can with what was provided. Take from it what you can.

PHP Code:
#include <amxmodx>
#include <nvault>
#include <fakemeta>

enum Knives
{
    
NoKnife,
    
AceOfKatanas,
    
Batman,
    
Chucky,
    
DarthMaul
}
new const 
KnifeModelsKnives ][] = 
{
    
"",
    
"models/shmod/ace_v_knife.mdl",
    
"models/shmod/batmanknife_v.mdl",
    
"models/shmod/chucky_knife.mdl",
    
"models/shmod/darthmaul_knife.mdl"
};

enum PlayerData
{
    
AuthID34 ],
    
Knives:KnifeID
}
new 
g_pdDataMAX_PLAYERS ][ PlayerData ];

new 
knife_model[33], vModel[56]
new 
g_MenuCallback;            //Create a global variable to hold our callback

new g_iVaultID
new gMemoryTableNames[64][32]                // Stores players name for a key
new g_iData[33]
//----------------------------------------------------------------------------------------------
public plugin_init()
{
     
register_plugin("plugin KnifeMenuSH""1.0""Lucas Cab Arje")

    
register_clcmd("say /knife""KnifeMenu")        // Para llamar al menu de fakas

    //Create our callback and save it to our variable
    
g_MenuCallback menu_makecallback("menuitem_callback");    //The first parameter is the public function to be called when a menu item is being shown.
    
    // Eventos
    
register_event("CurWeapon","CurWeapon","be","1=1")     // Para cambiar las fakas models
}

public 
plugin_end( )
{
    
nvault_closeg_iVaultID )
}

public 
plugin_cfg( )
{
    
g_iVaultID nvault_open"knife_vault" )
    
    if( 
g_iVaultID == INVALID_HANDLE )
    {
        
set_fail_state"Error opening Knife Nvault" )
    }
}

public 
client_authorizedPlayer )
{
    
get_user_authidPlayerg_pdDataPlayer ][ AuthID ] , charsmaxg_pdData[][ AuthID ] ) );
    
Load_StuffPlayer );
}

public 
SetKnifeid Knives:Knife 
{
    if (!
sh_is_active() || !is_user_alive(id) ) return; // PLUGIN_HANDLED
    
    
new szKnifeID];
    if ( 
AceOfKatanas <= Knife <= DarthMaul )
    {
        
switch_modelid  )
        
g_pdDataid ][ KnifeID ] = Knife;
    }
    else 
    {
        
g_pdDataid ][ KnifeID ] = NoKnife;
    }
    
    
num_to_str_:Knife szKnifeID charsmaxszKnifeID ) );
    
nvault_setg_iVaultIDg_pdDataid ][ AuthID ] , szKnifeID )    
}

Load_StuffPlayer )
{
    new 
szKnifeID] , iTS;
    if ( 
nvault_lookupg_iVaultID g_pdDataPlayer ][ AuthID ] , szKnifeID charsmaxszKnifeID ) , iTS ) )
    {
        
g_pdDataPlayer ][ KnifeID ] = str_to_numszKnifeID );
    }
    else
    {
        
g_pdDataPlayer ][ KnifeID ] = NoKnife;
    }
    
}
    
public 
CurWeaponid 
{
    if ( 
g_pdDataid ][ KnifeID ] != NoKnife  
    {
        
switch_modelid 
    }
}

switch_modelid )
{
    if (!
sh_is_active() || !is_user_alive(id) ) return
    
    if (
get_user_weaponid ) == CSW_KNIFE
    {
        
set_pevid pev_viewmodel2 KnifeModelsg_pdDataid ][ KnifeID ] ] )
    }

__________________
Bugsy is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-26-2022 , 02:16   Re: Nvault how to save models?
Reply With Quote #7

Short: you have to save selected model by its index. Then if player reconnects, you just get his authid, then nvault_lookup() for saved index and set knife depending on index

look at this as at reference, adjust for yourself
PHP Code:
enum Knives 

    
NoKnifeSet 0,  // first entry should be the default knife
    
...


new const 
g_ModelData[Knives][KnifeModels] = { ... } // first entry should be the default knife

save_to_vault(player)
{
    new 
tempKey[...], tempValue[...]
    
    
get_user_authid(playertempKeycharsmax(tempKey)) // or u can use formatex() instead of this if u have authid saved somewhere else in your plugin
    
formatex(tempValuecharsmax(tempValue), "%i"g_selectedKnifeId[player])
    
    
nvault_set(g_vaulttempKeytempValue)
}

get_from_vault(player)
{
    new 
tempKey[...], tempValue[...], timestamp
    
    get_user_authid
(playertempKeycharsmax(tempKey))
    
    new 
found nvault_lookup(g_vaulttempKeytempValuecharsmax(tempValue), timestamp)
    
    if(
found)
    {
        new 
iKnife str_to_num(tempValue)
        
setKnifeById(playeriKnife// use here your function for knife change
    
}
    else
    {
        
setKnifeById(player0// if player's authid was not found then guve him defaut knife
    
}

__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 03-26-2022 at 02:21.
kww is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 03-26-2022 , 11:20   Re: Nvault how to save models?
Reply With Quote #8

You are pretty much reiterating what I posted.
__________________
Bugsy is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-26-2022 , 17:03   Re: Nvault how to save models?
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
You are pretty much reiterating what I posted.
I read anything but 1st post
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 03-26-2022 at 17:03.
kww is offline
Arje
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
Old 03-30-2022 , 22:17   Re: Nvault how to save models?
Reply With Quote #10

Thanks for the help, i make this for the skin menu taking another example, and works correctly to save the player models:

but I want to put that you can buy skins, and that the object(skins) be saved, in case at some point you change the skin or want to use another, still keep the option of being able to use it, without having to buy it again

this is the code:
PHP Code:
#include <amxmisc>
#include <superheromod>
#include <nvault>

#pragma semicolon 1

#define MAX_PLAYERS    32

#define DATA_FLAG "q" 

// How to know the power he has
new bool:gHasBlackwidow[SH_MAXSLOTS+1];
new 
bool:gHasBroly[SH_MAXSLOTS+1];
new 
bool:gHasNeo[SH_MAXSLOTS+1];
new 
bool:gHasObiPower[SH_MAXSLOTS+1];

new 
blackwidowIDbrolyIDneoIDobiwanID;
// ==================================

const NoModelSet = -1;

new const 
g_ModelFiles[][][] = 
{
    { 
"blackwidow" "blackwidow" },
    { 
"broly" "broly" },
    { 
"neo" "neo" },
    { 
"obiwan" "obiwan" },
    { 
"termo" "termo" },
    { 
"thanos" "thanos" },
    { 
"thanosendg" "thanosendg" }
};

new 
g_ModelMAX_PLAYERS ];
new 
CsTeams:g_csTeamMAX_PLAYERS ];

new 
g_szAuthIDMAX_PLAYERS ][ 34 ];     // steam ID

new g_pExpireDays;                     //CVar pointer for expiredays cvar
new g_MenuCallback;                //Create a global variable to hold our callback
new g_iVaultID;                    //Global variable from File Name vault

//------------------------------------------------------------------------------------------------
//                Plugint Init n Precache                        //
//------------------------------------------------------------------------------------------------
public plugin_init() 
{
    
register_plugin"Skins Models" "1.4" "Bugsy / Lucas" );
    
    
register_event"ResetHUD" "resetModel" "b" );
    
register_event"TeamInfo" "teamInfo" "a" "2=TERRORIST" "2=CT" ); 
    
    
register_clcmd("say /skin""SkinMenu");    // Para llamar al menu de skins
    
register_clcmd("say /skins""SkinMenu");    // Para llamar al menu de skins
    
register_clcmd("say /menuskin""SkinMenu");    // Para llamar al menu de skins
    
    
g_pExpireDays register_cvar"skinmenu_expiredays" "15" );    // For clear nvault?
    
    //Create our callback and save it to our variable
    
g_MenuCallback menu_makecallback("menuitem_callback");    //The first parameter is the public function to be called when a menu item is being shown.
    
    // Events
    
set_task(0.2"cache_id_skin");                //we need to let superhero cache all the heros to avoid issues
}

public 
plugin_precache() 
{
    new 
tempfile128 ];
    
    for ( new 
iModelIndex iModelIndex sizeofg_ModelFiles ) ; iModelIndex++ ) {
        
formatextempfile charsmaxtempfile ) , "models/player/%s/%s.mdl" g_ModelFilesiModelIndex ][ ] , g_ModelFilesiModelIndex ][ ] );
        
precache_modeltempfile );
        
        
formatextempfile charsmaxtempfile ) , "models/player/%s/%s.mdl" g_ModelFilesiModelIndex ][ ] , g_ModelFilesiModelIndex ][ ] );
        
precache_modeltempfile );
    }
}
//------------------------------------------------------------------------------------------------
//                    Hero Confirms                        //
//------------------------------------------------------------------------------------------------
public cache_id_skin() 
{
    
// First Page of Menu
    
blackwidowID     sh_get_hero_id("Blackwidow");
    
brolyID     sh_get_hero_id("Broly");
    
neoID         sh_get_hero_id("Neo");
    
obiwanID     sh_get_hero_id("Obi Wan Kenobi");
}

public 
sh_hero_init(idheroIDmode)
{
    
// blackwidowID
    
if ( blackwidowID == heroID )
        
gHasBlackwidow[id] = mode true false;
    
// brolyID
    
else if ( brolyID == heroID )
        
gHasBroly[id] = mode true false;
    
// neoID
    
else if ( neoID == heroID )
        
gHasNeo[id] = mode true false;
    
// obiwanID
    
else if ( obiwanID == heroID )
        
gHasObiPower[id] = mode true false;
}
//------------------------------------------------------------------------------------------------
//                    Nvault Open n Init                    //
//------------------------------------------------------------------------------------------------
public plugin_end( )
{
    
nvault_closeg_iVaultID );
}

public 
plugin_cfg( )
{
    
g_iVaultID nvault_open"g_Model2" );
    
    if( 
g_iVaultID == INVALID_HANDLE ) {
        
set_fail_state"Error opening Skin Nvault" );
    }
    
    
// This will remove all entries in the vault that are 5+ (or cvar+) days old at server-start or map-change
    
nvault_pruneg_iVaultID get_systime() - ( 86400 get_pcvar_numg_pExpireDays ) ) );
}

public 
client_authorized(Player)  
{
    
set_task(0.1"cache_id_skin");        // idk remember why, but i need this i think
    
get_user_authidPlayer g_szAuthIDPlayer ] , charsmaxg_szAuthID[] ) );
    
g_ModelPlayer ] = NoModelSet;
    
LoadDataPlayer );
}
//------------------------------------------------------------------------------------------------
//            Team Info Event    (idk about this function)                //
//------------------------------------------------------------------------------------------------
public teamInfo()
{
    new 
id read_data);
    new 
szTeam];
    new 
CsTeams:csNewTeam;

    
read_dataszTeam charsmaxszTeam ) );
    
    
csNewTeam = ( szTeam] == 'T' ) ? CS_TEAM_T CS_TEAM_CT;

    if ( 
g_csTeamid ] != csNewTeam ) {
        if ( 
g_Modelid ] != NoModelSet ) {
            
resetModelid );    // resetModel( id );
        
}
        
g_csTeamid ] = csNewTeam;
    }    
}
//------------------------------------------------------------------------------------------------
//                    Create Menu                        //
//------------------------------------------------------------------------------------------------
public SkinMenu(id)     // SkinMenu    //modelvip
{
    new 
menu menu_create"\yModel Player Menu:""menu_handler" );

    
// this is from the first page of the menu                    //    Item    Key
    
menu_additemmenu"\wBlackwidow."""0g_MenuCallback );            //    0    1
    
menu_additemmenu"\wBroly."""0g_MenuCallback );                //    1    2
    
menu_additemmenu"\wNeo."""0g_MenuCallback );                //    2    3
    
menu_additemmenu"\wObi Wan Kenobi."""0g_MenuCallback );        //    3    4
    
menu_additemmenu"\wTermo \r(Only Admin)."""0g_MenuCallback );        //    4    5
    
menu_additemmenu"\wThanos (Level)."""0g_MenuCallback );        //    5    6
    
    
menu_addblank(menu0);
    
menu_additemmenu"\wInfo Skin."""0);                    //    6    7
                                            //        8    back
                                            //        9    more                
    // this is from the second page of the menu                    //    Item    Key
    
menu_additemmenu"\wThanos End \r(1,000,000) XP.."""0g_MenuCallback );    //    7    1
    
    
menu_addblank(menu0);
    
menu_additem(menu"\wInfo Skin."""0);                    //    8    2
    
    
menu_addblank(menu0);
    
menu_addtext(menu"Antes de Elegir Algo, Leer Info en say: /skin."0);            //    8    1
    
                                            //        8    back
                                            //        9    more
    
menu_display(idmenu);
    
    return 
PLUGIN_HANDLED;
}

public 
menu_handlerid menu item )
{
    if ( 
item == MENU_EXIT ) {
        
menu_destroy(menu);
        return 
PLUGIN_HANDLED;
    }
    
    new 
szData[6], szName[64];
    new 
item_accessitem_callback;
    
menu_item_getinfomenuitemitem_accessszDatacharsmax(szData), szName,charsmax(szName), item_callback );
    
    
g_Model[id] = item;
    
    switch(
item) {
        
// This Skins is from First Page of the Menu
        //-----------    Blackwidow
        
case 0: {
            
resetModelid );
            
sh_chat_message(id, -1"Seleccionaste la Skin de Blackwidow .");
        }
        
//-----------    Broly
        
case 1: {
            
resetModelid );
            
sh_chat_message(id, -1"Seleccionaste la Skin de Broly.");
        }
        
//-----------    Neo
        
case 2: {
            
resetModelid );
            
sh_chat_message(id, -1"Seleccionaste la Skin de Neo.");
        }
        
//-----------    Obi wan
        
case 3: {
            
resetModelid );
            
sh_chat_message(id, -1"Seleccionaste la Skin de Obi Wan Kenobi.");
        }
        
//-----------    Termo
        
case 4: {
            
resetModelid );
            
sh_chat_message(id, -1"Seleccionaste la Skin de Termo solo por nivel.");
        }
        
//-----------    Thanos
        
case 5: {
            
resetModelid );
            
sh_chat_message(id, -1"Seleccionaste la Skin de Thanos Solo de Admin.");
        }
        
//-----------
        //     SECOND PAGE
        //-----------
        //-----------    Thanos End Game
        
case 7: {
            
resetModelid );
            new 
iXPToAdd = ( -5000 );
            
sh_set_user_xp(idiXPToAddtrue);
            
sh_chat_message(id, -1"Compraste la Skin de Thanos End Game.");
        }
        case 
MENU_EXIT: {
            
sh_chat_message(id, -1"No Seleccionaste Ninguna Skin.");
        }
        
//-----------    Show Motd Info
        
default: {
            
show_motdid "Info Skins.txt" "Info Skins." );
        }
    }
    
    
SaveData(id);
    
//lets finish up this function by destroying the menu with menu_destroy, and a return
    
menu_destroy(menu);
    return 
PLUGIN_CONTINUE;
}
//------------------------------------------------------------------------------------------------
//                New Spawn Event    "ResetHUD"                    //
//------------------------------------------------------------------------------------------------
public resetModel(id)
{
    new 
CsTeams:userTeam;
    
    if ( ( 
g_Modelid ] != NoModelSet ) && ( CS_TEAM_T <= ( userTeam cs_get_user_teamid ) ) <= CS_TEAM_CT ) )
        
cs_set_user_modelid g_ModelFilesg_Modelid ] ][ _:userTeam ]);
    else
        
cs_reset_user_modelid );
}
//------------------------------------------------------------------------------------------------
//                Save and Load Data from Nvault.                    //
//------------------------------------------------------------------------------------------------
public SaveData(id)

    new 
szKey40 ] , szData]; 
     
    
formatexszKey charsmaxszKey ) , "%s_skin" ,  g_szAuthID[id] );
    
    
num_to_strg_Modelid ] , szData charsmaxszData ) );

    
nvault_setg_iVaultID g_szAuthIDid ] , szData );
}

public 
LoadData(id

    new 
szKey[40] , szData[4] , iTS;  
    
    
formatexszKey charsmaxszKey ) , "%s_skin" g_szAuthID[id] ); 
    
    if ( 
nvault_lookupg_iVaultID g_szAuthIDid ] , szData charsmaxszData ) , iTS ) ) {
    
        
g_Modelid ] = str_to_numszData );
    }
}
//------------------------------------------------------------------------------------------------
//                    MENU DISABLE THINGS                    //
//------------------------------------------------------------------------------------------------
public menuitem_callback(idmenuitem)        // This is our callback function. Return ITEM_ENABLED, ITEM_DISABLED, or ITEM_IGNORE.
{
    new 
level sh_get_user_lvl(id);
    
    
// gHasBlackwidow
    
if ( item == && !gHasBlackwidow[id] ) {
        
menu_item_setname(menuitem"\dBlackwidow.");
        return 
ITEM_DISABLED;
    }
    
// gHasBroly
    
if ( item == && !gHasBroly[id] ) {
        
menu_item_setname(menuitem"\dBroly.");
        return 
ITEM_DISABLED;
    }
    
// gHasNeo
    
if ( item == && !gHasNeo[id]) {
        
menu_item_setname(menuitem"\dNeo.");
        return 
ITEM_DISABLED;
    }
    
// gHasObiPower
    
if ( item == && !gHasObiPower[id] ) {
        
menu_item_setname(menuitem"\dObi Wan Kenobi.");
        return 
ITEM_DISABLED;
    }
    
// Termo - Level
    
if ( item == && level <= 30 ) {
        
menu_item_setname(menuitem"\dTermo.");
        return 
ITEM_DISABLED;
    }
    
// Thanos
    
if ( item == && !has_flag(idDATA_FLAG) ) {
        
menu_item_setname(menuitem"\dThanos. \r(Only Admin!)");
        return 
ITEM_DISABLED;
    }
    
// Thanos End Game
    
if ( item == && level 40) {
        
menu_item_setname(menuitem"\dThanos End Game. \r(1,000,000) XP.");
        return 
ITEM_DISABLED;
    }
    
//Otherwise we can just ignore the return value
    
return ITEM_IGNORE;     //Note that returning ITEM_ENABLED will override the admin flag check from menu_additem    

and another question about the menu, is it possible to make this item an option on every page?
without having to repeat it on every page?
PHP Code:
menu_addblank(menu0);
    
menu_additemmenu"\wInfo Skin."""0);                    //    6    7 
menu function:
PHP Code:
//------------------------------------------------------------------------------------------------
//                    Create Menu                        //
//------------------------------------------------------------------------------------------------
public SkinMenu(id)     // SkinMenu    //modelvip
{
    new 
menu menu_create"\yModel Player Menu:""menu_handler" );

    
// this is from the first page of the menu                    //    Item    Key
    
menu_additemmenu"\wBlackwidow."""0g_MenuCallback );            //    0    1
    
menu_additemmenu"\wBroly."""0g_MenuCallback );                //    1    2
    
menu_additemmenu"\wNeo."""0g_MenuCallback );                //    2    3
    
menu_additemmenu"\wObi Wan Kenobi."""0g_MenuCallback );        //    3    4
    
menu_additemmenu"\wTermo \r(Only Admin)."""0g_MenuCallback );        //    4    5
    
menu_additemmenu"\wThanos (Level)."""0g_MenuCallback );        //    5    6
    
    
menu_addblank(menu0);
    
menu_additemmenu"\wInfo Skin."""0);                    //    6    7
                                            //        8    back
                                            //        9    more                
    // this is from the second page of the menu                    //    Item    Key
    
menu_additemmenu"\wThanos End \r(1,000,000) XP.."""0g_MenuCallback );    //    7    1
    
    
menu_addblank(menu0);
    
menu_additem(menu"\wInfo Skin."""0);                    //    8    2
    
    
menu_addblank(menu0);
    
menu_addtext(menu"Antes de Elegir Algo, Leer Info en say: /skin."0);            //    8    1
    
                                            //        8    back
                                            //        9    more
    
menu_display(idmenu);
    
    return 
PLUGIN_HANDLED;

Arje 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 07:37.


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