Raised This Month: $90 Target: $400
 22% 

How to save in nvault?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Gasior
Member
Join Date: Mar 2012
Old 11-21-2016 , 10:45   How to save in nvault?
Reply With Quote #1

Hi guys,

I try to edit my plugin in which VIP has an option of selecting one of 4 models per team, I just try to make it save the option, so with every map change he doesn't have to type /modele again.

I tried it myself but it just doesn't save the option, any suggestions?

Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine> 
#include <nvault>


#pragma semicolon 1


#define MENUITEM_DISABLED   (1<<26)


new g_Model[33];
new plik_vault;


new g_ModelFiles[][][] = {
    {"saperterro", "ctsplinter"},
    {"oranget", "camoct"},
    {"phoenixt", "urbanos"},
    {"viptt", "snowct"}
};


new g_ModelNames[][] = {
    "Model 1",
    "Model 2",
    "Model 3",
    "Model 4"
};


#if ( sizeof g_ModelNames != sizeof g_ModelFiles )
    #error You have to format the g_ModelFiles to the same size as g_ModelNames
#endif


public plugin_init() {
register_plugin("Modele VIP", "1.3", "Gasior");
    
register_event("ResetHUD", "resetModel", "b");
register_clcmd("say /modele", "modelevip");
    
plik_vault = nvault_open("g_Model");
if(plik_vault == INVALID_HANDLE)
set_fail_state("Nie moge otworzyc pliku :/");
    
return PLUGIN_CONTINUE;
}


public plugin_precache() {


    new tempfile[128];
    
    for ( new i = 0 ; i < sizeof g_ModelFiles ; i++ ) {
        for ( new j = 0 ; j < 2 ; j++ ) {
            formatex(tempfile, 127, "models/player/%s/%s.mdl", g_ModelFiles[i][j], g_ModelFiles[i][j]);
            precache_model(tempfile);
        }
    }
}


public client_connect(id) {
    g_Model[id] = 0;
    LoadData(id);
}


public modelevip(id) {
    if ( ! ( get_user_flags(id) & ADMIN_LEVEL_H ) )
        return;
    
    new menu = menu_create( "\yWybierz swoj VIP Model:", "menu_handler" );
    
    new i;
    for ( i = 0 ; i < sizeof g_ModelFiles ; i++ ) {
        new menuitem[64];
        formatex(menuitem, charsmax(menuitem), "\%c%s", g_Model[id] - 1 == i ? 'd' : 'w', g_ModelNames[i]);
        menu_additem(menu, menuitem,_, g_Model[id] - 1 == i ? MENUITEM_DISABLED : 0);
    }
    
    menu_addblank(menu, 0);
    menu_additem(menu, "Pokaz Modele");
    menu_addblank(menu, 0);
    menu_addtext(menu, "Dziekujemy za bycie VIPem na FFA ProjektSpark.pl", 0);
    
    menu_display(id, menu);
}


public menu_handler(id, menu, item) {


if ( item == MENU_EXIT ) {
menu_destroy(menu);
return PLUGIN_HANDLED;
}


if ( item == sizeof g_ModelFiles ) {
g_Model[id] = 0;
}
else {
g_Model[id] = item + 1;
}
resetModel(id);


switch(item)
{
case 4:
show_motd(id, "modele.txt", "Modele");
}


SaveData(id);
        
return PLUGIN_CONTINUE;
}


public resetModel(id) {


    if ( ! is_user_connected(id) )
        return;
    
    new userTeam2, CsTeams:userTeam = cs_get_user_team(id);
    
    switch ( userTeam ) {
        case CS_TEAM_T: userTeam2 = 1;
        case CS_TEAM_CT: userTeam2 = 2;
    }
    
    if ( g_Model[id] && userTeam2 )
        cs_set_user_model(id, g_ModelFiles[g_Model[id] - 1][userTeam2 - 1]);
    else
        cs_reset_user_model(id);


    return;
}


public SaveData(id)
{ 
new authid[32];
get_user_authid(id, authid, 31);


new vaultkey[64],vaultdata[64];
formatex(vaultkey, 63, "%s-modele", authid);
formatex(vaultdata,63,"%d", g_Model[id]);
nvault_set(plik_vault,vaultkey,vaultdata);


return PLUGIN_CONTINUE;
}


public LoadData(id) 
{ 
new authid[32];
get_user_authid(id, authid, 31);
new vaultkey[64],vaultdata[64];
formatex(vaultkey, 63, "%s-modele", authid);


g_Model[id] = str_to_num(vaultdata);


format(vaultkey, 63, "%s-modele", authid);
get_vaultdata(vaultkey, vaultdata, 63);


return PLUGIN_CONTINUE;
}
Gasior is offline
Napoleon_be
AlliedModders Donor
Join Date: Jul 2011
Location: Belgium
Old 11-21-2016 , 10:58   Re: How to save in nvault?
Reply With Quote #2

Just by saving everything doesn't mean you will still get the model...

Check your saved arrays/variables/booleans and set a model according to their values on player spawn.

https://forums.alliedmods.net/showthread.php?t=91503
__________________

Last edited by Napoleon_be; 11-21-2016 at 11:00.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Gasior
Member
Join Date: Mar 2012
Old 11-21-2016 , 19:16   Re: How to save in nvault?
Reply With Quote #3

Sorry I'm stupid, which function exactly should I use?
Gasior is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Europe (ro)
Old 11-22-2016 , 04:07   Re: How to save in nvault?
Reply With Quote #4

Code:
register_clcmd("say /modele
You're romanian? If yes, send me a private message.

Last edited by Craxor; 11-22-2016 at 10:11.
Craxor is offline
Send a message via ICQ to Craxor
Gasior
Member
Join Date: Mar 2012
Old 11-22-2016 , 09:45   Re: How to save in nvault?
Reply With Quote #5

Im Polish, sorry ;) .
I like you guys! Can I get help anyway?
Gasior is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Europe (ro)
Old 11-22-2016 , 10:09   Re: How to save in nvault?
Reply With Quote #6

this thread help you ? https://forums.alliedmods.net/showthread.php?t=290692
Craxor is offline
Send a message via ICQ to Craxor
Napoleon_be
AlliedModders Donor
Join Date: Jul 2011
Location: Belgium
Old 11-22-2016 , 11:19   Re: How to save in nvault?
Reply With Quote #7

Quote:
Originally Posted by Craxor View Post
It probably didn't cause you only explain there how to save/load data. You're not explaining him how to set the model back after he joined.

What you gotta do:

1) Create a boolean which holds true or false according to if the player has the model saved or not. You should set to true if the player has the model saved.
2) On player disconnect, you should save the data of the boolean. (Variable which holds 0/1 would work too)
3) On player connect, load that same boolean (Craxor explained pretty well on how to do it)
4) On player spawn POST, you should set this model. (Remember that this should only be done once, you can do this by creating another boolean which holds true or false according to if the player already spawned his first time or not.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Craxor
Veteran Member
Join Date: Jan 2016
Location: Europe (ro)
Old 11-22-2016 , 12:15   Re: How to save in nvault?
Reply With Quote #8

I explained how to use nvault, anyway Key and Data are Strings as default, when you save multiple numbers in data you need to parse() them and after to convert from str to num so it's more easy to save models.

Napoleon, all you ideas are dismised, just save a fucking model directly and load on spawn post ( i believe? ) without any kind of boolean.
( If he wants private models for each players to be saved ).
Craxor is offline
Send a message via ICQ to Craxor
Napoleon_be
AlliedModders Donor
Join Date: Jul 2011
Location: Belgium
Old 11-23-2016 , 10:27   Re: How to save in nvault?
Reply With Quote #9

Quote:
Originally Posted by Craxor View Post
I explained how to use nvault, anyway Key and Data are Strings as default, when you save multiple numbers in data you need to parse() them and after to convert from str to num so it's more easy to save models.

Napoleon, all you ideas are dismised, just save a fucking model directly and load on spawn post ( i believe? ) without any kind of boolean.
( If he wants private models for each players to be saved ).
Then how are you gonna check if the player want that model to be saved or not? On what conditions are you gonna set the model on spawn then?
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Craxor
Veteran Member
Join Date: Jan 2016
Location: Europe (ro)
Old 11-23-2016 , 10:29   Re: How to save in nvault?
Reply With Quote #10

Quote:
Originally Posted by Napoleon_be View Post
Then how are you gonna check if the player want that model to be saved or not? On what conditions are you gonna set the model on spawn then?
I do not know the logic/reasons of the plugin.

About the condition , is_user_alive, hihih, not always a condition is needed, depdends of the situations ... here it's better to use nvault_lookup() to check for the model, this can repleace the booleans.

Something like that should be formated your publics:
PHP Code:
public SaveData(id)

    new 
authid[32];
    
get_user_authid(idauthid31);


    
nvault_setplik_vault authid "Model_Name, bla  bbla, you knwo here .." );

}

public 
LoadModel(id)

    new 
authid[32] , GetModel[64] , iTs;
    
get_user_authid(idauthid31);

    if( 
is_user_alive id ) && nvault_lookupplik_vaultauthidGetModelcharsmaxGetModel ), iTs ) )
        
cs_set_user_modelidteam GetModel );
    

But in your case you should use nvault utility and set 2 private models for users, One if is Tero and One if is CT.

Last edited by Craxor; 11-23-2016 at 10:43.
Craxor is offline
Send a message via ICQ to Craxor
Reply


Thread Tools
Display Modes

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 04:18.


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