Raised This Month: $ Target: $400
 0% 

Nvault how to save models?


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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