|
Senior Member
Join Date: Apr 2020
Location: Córdoba, Argentina
|

03-30-2022
, 22:17
Re: Nvault how to save models?
|
#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 blackwidowID, brolyID, neoID, obiwanID;
// ==================================
const NoModelSet = -1;
new const g_ModelFiles[][][] =
{
{ "blackwidow" , "blackwidow" },
{ "broly" , "broly" },
{ "neo" , "neo" },
{ "obiwan" , "obiwan" },
{ "termo" , "termo" },
{ "thanos" , "thanos" },
{ "thanosendg" , "thanosendg" }
};
new g_Model[ MAX_PLAYERS + 1 ];
new CsTeams:g_csTeam[ MAX_PLAYERS + 1 ];
new g_szAuthID[ MAX_PLAYERS + 1 ][ 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 tempfile[ 128 ];
for ( new iModelIndex = 0 ; iModelIndex < sizeof( g_ModelFiles ) ; iModelIndex++ ) {
formatex( tempfile , charsmax( tempfile ) , "models/player/%s/%s.mdl" , g_ModelFiles[ iModelIndex ][ 0 ] , g_ModelFiles[ iModelIndex ][ 0 ] );
precache_model( tempfile );
formatex( tempfile , charsmax( tempfile ) , "models/player/%s/%s.mdl" , g_ModelFiles[ iModelIndex ][ 1 ] , g_ModelFiles[ iModelIndex ][ 1 ] );
precache_model( tempfile );
}
}
//------------------------------------------------------------------------------------------------
// 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(id, heroID, mode)
{
// 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_close( g_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_prune( g_iVaultID , 0 , get_systime() - ( 86400 * get_pcvar_num( g_pExpireDays ) ) );
}
public client_authorized(Player)
{
set_task(0.1, "cache_id_skin"); // idk remember why, but i need this i think
get_user_authid( Player , g_szAuthID[ Player ] , charsmax( g_szAuthID[] ) );
g_Model[ Player ] = NoModelSet;
LoadData( Player );
}
//------------------------------------------------------------------------------------------------
// Team Info Event (idk about this function) //
//------------------------------------------------------------------------------------------------
public teamInfo()
{
new id = read_data( 1 );
new szTeam[ 2 ];
new CsTeams:csNewTeam;
read_data( 2 , szTeam , charsmax( szTeam ) );
csNewTeam = ( szTeam[ 0 ] == 'T' ) ? CS_TEAM_T : CS_TEAM_CT;
if ( g_csTeam[ id ] != csNewTeam ) {
if ( g_Model[ id ] != NoModelSet ) {
resetModel( id ); // resetModel( id );
}
g_csTeam[ id ] = 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_additem( menu, "\wBlackwidow.", "", 0, g_MenuCallback ); // 0 1
menu_additem( menu, "\wBroly.", "", 0, g_MenuCallback ); // 1 2
menu_additem( menu, "\wNeo.", "", 0, g_MenuCallback ); // 2 3
menu_additem( menu, "\wObi Wan Kenobi.", "", 0, g_MenuCallback ); // 3 4
menu_additem( menu, "\wTermo \r(Only Admin).", "", 0, g_MenuCallback ); // 4 5
menu_additem( menu, "\wThanos (Level).", "", 0, g_MenuCallback ); // 5 6
menu_addblank(menu, 0);
menu_additem( menu, "\wInfo Skin.", "", 0); // 6 7
// 8 back
// 9 more
// this is from the second page of the menu // Item Key
menu_additem( menu, "\wThanos End \r(1,000,000) XP..", "", 0, g_MenuCallback ); // 7 1
menu_addblank(menu, 0);
menu_additem(menu, "\wInfo Skin.", "", 0); // 8 2
menu_addblank(menu, 0);
menu_addtext(menu, "Antes de Elegir Algo, Leer Info en say: /skin.", 0); // 8 1
// 8 back
// 9 more
menu_display(id, menu);
return PLUGIN_HANDLED;
}
public menu_handler( id , menu , item )
{
if ( item == MENU_EXIT ) {
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new szData[6], szName[64];
new item_access, item_callback;
menu_item_getinfo( menu, item, item_access, szData, charsmax(szData), szName,charsmax(szName), item_callback );
g_Model[id] = item;
switch(item) {
// This Skins is from First Page of the Menu
//----------- Blackwidow
case 0: {
resetModel( id );
sh_chat_message(id, -1, "Seleccionaste la Skin de Blackwidow .");
}
//----------- Broly
case 1: {
resetModel( id );
sh_chat_message(id, -1, "Seleccionaste la Skin de Broly.");
}
//----------- Neo
case 2: {
resetModel( id );
sh_chat_message(id, -1, "Seleccionaste la Skin de Neo.");
}
//----------- Obi wan
case 3: {
resetModel( id );
sh_chat_message(id, -1, "Seleccionaste la Skin de Obi Wan Kenobi.");
}
//----------- Termo
case 4: {
resetModel( id );
sh_chat_message(id, -1, "Seleccionaste la Skin de Termo solo por nivel.");
}
//----------- Thanos
case 5: {
resetModel( id );
sh_chat_message(id, -1, "Seleccionaste la Skin de Thanos Solo de Admin.");
}
//-----------
// SECOND PAGE
//-----------
//----------- Thanos End Game
case 7: {
resetModel( id );
new iXPToAdd = ( -5000 );
sh_set_user_xp(id, iXPToAdd, true);
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_motd( id , "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_Model[ id ] != NoModelSet ) && ( CS_TEAM_T <= ( userTeam = cs_get_user_team( id ) ) <= CS_TEAM_CT ) )
cs_set_user_model( id , g_ModelFiles[ g_Model[ id ] ][ _:userTeam - 1 ]);
else
cs_reset_user_model( id );
}
//------------------------------------------------------------------------------------------------
// Save and Load Data from Nvault. //
//------------------------------------------------------------------------------------------------
public SaveData(id)
{
new szKey[ 40 ] , szData[ 4 ];
formatex( szKey , charsmax( szKey ) , "%s_skin" , g_szAuthID[id] );
num_to_str( g_Model[ id ] , szData , charsmax( szData ) );
nvault_set( g_iVaultID , g_szAuthID[ id ] , szData );
}
public LoadData(id)
{
new szKey[40] , szData[4] , iTS;
formatex( szKey , charsmax( szKey ) , "%s_skin" , g_szAuthID[id] );
if ( nvault_lookup( g_iVaultID , g_szAuthID[ id ] , szData , charsmax( szData ) , iTS ) ) {
g_Model[ id ] = str_to_num( szData );
}
}
//------------------------------------------------------------------------------------------------
// MENU DISABLE THINGS //
//------------------------------------------------------------------------------------------------
public menuitem_callback(id, menu, item) // This is our callback function. Return ITEM_ENABLED, ITEM_DISABLED, or ITEM_IGNORE.
{
new level = sh_get_user_lvl(id);
// gHasBlackwidow
if ( item == 0 && !gHasBlackwidow[id] ) {
menu_item_setname(menu, item, "\dBlackwidow.");
return ITEM_DISABLED;
}
// gHasBroly
if ( item == 1 && !gHasBroly[id] ) {
menu_item_setname(menu, item, "\dBroly.");
return ITEM_DISABLED;
}
// gHasNeo
if ( item == 2 && !gHasNeo[id]) {
menu_item_setname(menu, item, "\dNeo.");
return ITEM_DISABLED;
}
// gHasObiPower
if ( item == 3 && !gHasObiPower[id] ) {
menu_item_setname(menu, item, "\dObi Wan Kenobi.");
return ITEM_DISABLED;
}
// Termo - Level
if ( item == 4 && level <= 30 ) {
menu_item_setname(menu, item, "\dTermo.");
return ITEM_DISABLED;
}
// Thanos
if ( item == 5 && !has_flag(id, DATA_FLAG) ) {
menu_item_setname(menu, item, "\dThanos. \r(Only Admin!)");
return ITEM_DISABLED;
}
// Thanos End Game
if ( item == 7 && level < 40) {
menu_item_setname(menu, item, "\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(menu, 0);
menu_additem( menu, "\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_additem( menu, "\wBlackwidow.", "", 0, g_MenuCallback ); // 0 1
menu_additem( menu, "\wBroly.", "", 0, g_MenuCallback ); // 1 2
menu_additem( menu, "\wNeo.", "", 0, g_MenuCallback ); // 2 3
menu_additem( menu, "\wObi Wan Kenobi.", "", 0, g_MenuCallback ); // 3 4
menu_additem( menu, "\wTermo \r(Only Admin).", "", 0, g_MenuCallback ); // 4 5
menu_additem( menu, "\wThanos (Level).", "", 0, g_MenuCallback ); // 5 6
menu_addblank(menu, 0);
menu_additem( menu, "\wInfo Skin.", "", 0); // 6 7
// 8 back
// 9 more
// this is from the second page of the menu // Item Key
menu_additem( menu, "\wThanos End \r(1,000,000) XP..", "", 0, g_MenuCallback ); // 7 1
menu_addblank(menu, 0);
menu_additem(menu, "\wInfo Skin.", "", 0); // 8 2
menu_addblank(menu, 0);
menu_addtext(menu, "Antes de Elegir Algo, Leer Info en say: /skin.", 0); // 8 1
// 8 back
// 9 more
menu_display(id, menu);
return PLUGIN_HANDLED;
}
|
|