AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   How to save in nvault? (https://forums.alliedmods.net/showthread.php?t=290726)

Gasior 11-21-2016 10:45

How to save in nvault?
 
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;
}


Napoleon_be 11-21-2016 10:58

Re: How to save in nvault?
 
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

Gasior 11-21-2016 19:16

Re: How to save in nvault?
 
Sorry I'm stupid, which function exactly should I use?

Craxor 11-22-2016 04:07

Re: How to save in nvault?
 
Code:

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

Gasior 11-22-2016 09:45

Re: How to save in nvault?
 
Im Polish, sorry ;) .
I like you guys! Can I get help anyway?

Craxor 11-22-2016 10:09

Re: How to save in nvault?
 
this thread help you ? https://forums.alliedmods.net/showthread.php?t=290692

Napoleon_be 11-22-2016 11:19

Re: How to save in nvault?
 
Quote:

Originally Posted by Craxor (Post 2471916)

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.

Craxor 11-22-2016 12:15

Re: How to save in nvault?
 
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 ).

Napoleon_be 11-23-2016 10:27

Re: How to save in nvault?
 
Quote:

Originally Posted by Craxor (Post 2471945)
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?

Craxor 11-23-2016 10:29

Re: How to save in nvault?
 
Quote:

Originally Posted by Napoleon_be (Post 2472106)
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.


All times are GMT -4. The time now is 06:38.

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