Raised This Month: $32 Target: $400
 8% 

Solved nvault save


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Veteran Member
Join Date: Nov 2020
Old 11-30-2020 , 02:58   nvault save
Reply With Quote #1

i have problem with saving and getting info from nvault with this plugin, but i don t know why.

PHP Code:
/* Plugin generated by AMXX-Studio */

#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <hamsandwich>
#include <ColorChat>
#include <engine>
#include <fakemeta>
#include <nvault>


#define PLUGIN "SkinMenu"
#define VERSION "3.0"
#define AUTHOR "lexzor"

new key MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6|MENU_KEY_7|MENU_KEY_8|MENU_KEY_9|MENU_KEY_0;
new const 
tag[ ]= "JoiNET"
new iTeam;

new 
checkCT[32]
new 
checkT[32]
new 
checkPS[32]


new 
name[32]
new 
vaultdata[256]
new 
nVault
new camera
new cam
new const nVaultName[ ] = "menuskin";




new 
playerskins[][] = {
    
"sias",
    
"fbi",
    
"isis",
    
"alqaeda"
}

public 
plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
register_clcmd("amx_vskin""menuVIP")
    
register_clcmd("amx_show""show")
    
register_clcmd("amx_try""client_disconnected")
    
    
register_menu("menuVIP"key"menuVIP_handler")
    
register_menu("playerskin"key"playerskin_handler")
    
register_event"ResetHUD""taskdo""be" );
    
    
    
nVault nvault_open(nVaultName)
    
    if (
nVault == INVALID_HANDLE)
        
set_fail_state("[SKINMENU] Plugin can't open nVault file!")
}

public 
plugin_precache(){
    static 
playermodels[256]
    
    for (new 
0sizeof(playerskins) -1i++){
        
        
formatex(playermodelscharsmax(playermodels), "models/player/%s/%s.mdl"playerskins[i], playerskins[i])
        
        
precache_model(playermodels)
        
    } 
    
}

public 
cmdSave(id){
    
    
formatexvaultdatacharsmax(vaultdata), "%i#%i#%i#"checkPS[id], checkT[id], checkCT[id] )
    
    
nvault_set(nVaultnamevaultdata)
    
}

public 
cmdGet(id){
    
    
get_user_name(idnamecharsmax(name))
    
    new 
checkps[10], checkt[10], checkct[10]
    
    
nvault_get(nVaultnamevaultdatacharsmax(vaultdata))
    
    
replace_all(vaultdatacharsmax(vaultdata), "#"" ")
    
    
parse(vaultdatacheckpscharsmax(checkps), checktcharsmax(checkt), checkctcharsmax(checkct))
    
    
checkPS[id] = str_to_num(checkps)
    
    
checkT[id] = str_to_num(checkt)
    
    
checkCT[id] = str_to_num(checkct)
    
}

public 
menuVIP(id){
    static 
szMenu[650], ilen
    
    ilen 
0
    
    ilen 
+= formatex(szMenu[ilen], charsmax(szMenu), "\r[%s]\y VIP MENU^n^n"tag)
    
    
    
ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r1.\w Player Skins^n")
    
    
    
ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r2.\w Camera View - %s^n^n"camera "\r[3RD Person View]" "\r[Normal View]" )
    
    
    
ilen += formatex(szMenu[ilen], charsmax(szMenu), "\r0.\y Exit")
    
    
show_menu(idkeyszMenu, -1"menuVIP")
}


public 
menuVIP_handler(idkey){
    
    if (!(
is_user_alive(id))){
        
        
ColorChat(idGREEN"^x04[%s]^x01 You must be^x04 alive^x01 to use this menu!"tag)
        
        return 
0
        
    
}
    
    switch(
key){
        
        case 
0:{
            
            
playerskin(id)
            
        }
        
        
        case 
1:{
            
            if (
camera && !cam){
                
                
camera false;
                
                if(
is_user_alive(id))
                    
                
ColorChat(idGREEN"^x04[%s]^x01 You changed camera to^x04 Normal View^x01."tag);
                
                
client_cmd(id"cam")
                
                } else if (!
camera  && !cam){
                
                
camera true;
                
                if(
is_user_alive(id))
                    
                
ColorChat(idGREEN"^x04[%s]^x01 You changed camera to^x04 3RD Person View^x01."tag);
                
                
client_cmd(id"cam")
                
                } else if ( 
cam ){
                
                
ColorChat(idGREEN"^x04[%s]^x01 You can set^x04 view^x01 just in first^x04 15 seconds^x01 of every round!"tag)
                
            } 
            
menuVIP(id)
            
        }
        
        case 
9:{
            
            
ColorChat(idGREEN"^x04[%s]^x01 You left^x04 VIP SKIN MENU^x01."tag)
            
        }
        
    }
    
}

public 
playerskin(id){
    static 
szMenu2[650], ilen
    ilen 
0
    
    iTeam 
get_user_team(id)
    
    
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r[%s]\y PLAYER SKIN MENU^n^n"tag)
    
    
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r1.\y Default Skin - %s^n^n",  checkPS[id] == "\y[ON]" "\r[OFF]")
    
    if (
iTeam == 1){
        
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r2.\w ISIS Killer - %s^n"checkPS[id] == "\y[ON]" "\r[OFF]")
        
        
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r3.\w aL-Qaeda Hitman - %s^n^n"checkPS[id] == "\y[ON]" "\r[OFF]")
        
        
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r4.\w FBI Agent -\d [CT ONLY]^n")
        
        
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r5.\w SIAS Specialist -\d [CT ONLY]^n^n")
        
        }else if ( 
iTeam == ){
        
        
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r2.\w ISIS Killer -\d [T ONLY]^n")
        
        
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r3.\w aL-Qaeda Hitman -\d [T ONLY]^n^n")
        
        
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r4.\w FBI Agent - %s^n"checkPS[id] == "\y[ON]" "\r[OFF]")
        
        
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r5.\w SIAS Specialist - %s^n^n"checkPS[id] == "\y[ON]" "\r[OFF]")
    }
    
    
ilen += formatex(szMenu2[ilen], charsmax(szMenu2), "\r0.\y Back")
    
    
show_menu(idkeyszMenu2, -1"playerskin")
}

public 
playerskin_handler(idkey){
    
    if (!(
is_user_alive(id))){
        
        
ColorChat(idGREEN"^x04[%s]^x01 You must be^x04 alive^x01 to use this menu!"tag)
        
        return 
0
        
    
}
    
    
iTeam get_user_team(id)
    
    switch(
key){
        
        case 
0: {
            
            
checkPS[id] = 0;
            
            
checkCT[id] = 0;
            
            
checkT[id] = 0;
            
            
cs_reset_user_model(id)
            
            
ColorChat(idGREEN"^x04[%s]^x01 You choose^x04 default^x01 skin!"tag)
            
        }
        
        case 
1:{
            
            if (
iTeam == 1){
                
                
checkT[id] = 1
                
                checkPS
[id] = 1
                
                cs_reset_user_model
(id)
                
                
cs_set_user_model(id"isis")
                
                
ColorChat(idGREEN"^x04[%s]^x01 You choose^x04 ISIS Killer^x01 skin!"tag)
                
                
            }
            if (
iTeam == 2){
                
                
ColorChat(idGREEN"^x04[%s]^x01 You can't choose this skin!"tag)
                
                
            }
            
            
playerskin(id)
            
        }
        
        case 
2:{
            
            if (
iTeam == 1){
                
                
checkT[id] = 2
                
                checkPS
[id] = 2
                
                cs_reset_user_model
(id)
                
                
cs_set_user_model(id"alqaeda")
                
                
ColorChat(idGREEN"^x04[%s]^x01 You choose^x04 aL-Qaeda Hitman^x01 skin!"tag)
                
                
playerskin(id)
                
            }
            if (
iTeam == 2){
                
                
ColorChat(idGREEN"^x04[%s]^x01 You can't choose this skin!"tag)
                
                
playerskin(id)
                
            }
            
        }
        
        case 
3:{
            
            if (
iTeam == 2){
                
                
checkCT[id] = 1
                
                checkPS
[id] = 3
                
                cs_reset_user_model
(id)
                
                
cs_set_user_model(id"fbi")
                
                
ColorChat(idGREEN"^x04[%s]^x01 You choose^x04 FBI Agent^x01 skin!"tag)
                
                
playerskin(id)
                
            }
            if (
iTeam == 1){
                
                
ColorChat(idGREEN"^x04[%s]^x01 You can't choose this skin!"tag)
                
                
playerskin(id)
                
            }
            
        }
        
        case 
4:{
            
            if (
iTeam == 2){
                
                
checkCT[id] = 2
                
                checkPS
[id] = 4
                
                cs_reset_user_model
(id)
                
                
cs_set_user_model(id"sias")
                
                
ColorChat(idGREEN"^x04[%s]^x01 You choose^x04 SIAS Specialist^x01 skin!"tag)
                
                
playerskin(id)
                
            }
            if (
iTeam == 1){
                
                
ColorChat(idGREEN"^x04[%s]^x01 You can't choose this skin!"tag)
                
                
playerskin(id)
                
            }
            
        }
        
        case 
9:{
            
            
menuVIP(id)
            
        }
        
    }
}



public 
show(id){
        
    
ColorChat(idGREEN"^x04[%s]^x01 SkinCT %i, SkinT %i!"tagcheckCT[id], checkT[id])
    
}

public 
client_disconnected(id){
    
    
cmdSave(id)
        
}

public 
client_connect(id){
    
    
cmdGet(id)
    
}

public 
skincheck(id){
    
    
cmdSave(id)
    
    
cam false
    
    iTeam 
get_user_team(id)
    
    if(
is_user_alive(id)) cs_reset_user_model(id)
    
    if(
is_user_alive(id) && checkPS[id] != 0){
        
        if ( 
iTeam == ){
            
            switch(
checkT[id]){
                
                case 
1:{
                    
                    
cs_set_user_model(id"isis")
                    
                }
                
                case 
2:{
                    
                    
cs_set_user_model(id"alqaeda")
                    
                }
                
            }
            
            
            } else if ( 
iTeam == ){
            
            switch(
checkCT[id]){
                
                case 
1:{
                    
                    
cs_set_user_model(id"fbi")
                    
                }
                
                case 
2:{
                    
                    
cs_set_user_model(id"sias")
                    
                }
                
            }
            
        }
        
    }
    
}

public 
camset(id){
    
    
//if(!(get_user_flags(id) & VIP_FLAG)) return 0
    
    
set_view(idCAMERA_NONE)
    
    
cam true
    
    camera 
false
    
}

public 
taskdo(id){
    
    
set_task(0.1"skincheck"id)
    
    
set_task(15.0"camset"id)
    


Last edited by lexzor; 12-02-2020 at 08:07.
lexzor is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 11-30-2020 , 08:11   Re: nvault save
Reply With Quote #2

ok i get this
Code:
L 11/30/2020 - 15:09:54: [AMXX] Displaying debug trace (plugin "menuvip.amxx", version "3.0")
L 11/30/2020 - 15:09:54: [AMXX] Run time error 4: index out of bounds
L 11/30/2020 - 15:09:54: [AMXX] [0] menuvip.sma::cmdSave (line 75)
L 11/30/2020 - 15:09:54: [AMXX] [1] menuvip.sma::skincheck (line 389)
lexzor is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-30-2020 , 08:20   Re: nvault save
Reply With Quote #3

This error will happen when your server is full based on how you currently have it coded.

Change
PHP Code:
new checkCT[32]
new 
checkT[32]
new 
checkPS[32
to
PHP Code:
#define MAX_PLAYERS 32
new checkCTMAX_PLAYERS ]
new 
checkTMAX_PLAYERS ]
new 
checkPSMAX_PLAYERS 
__________________

Last edited by Bugsy; 11-30-2020 at 08:20.
Bugsy is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 11-30-2020 , 13:20   Re: nvault save
Reply With Quote #4

@Bugsy, he also do cmdSave( id ) on client_disconnected( id ), maybe im dumb but adding is_user_connected( id ) there will be also a good solution together with [ MAX_PLAYERS + 1 ] ?
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 11-30-2020 , 21:47   Re: nvault save
Reply With Quote #5

What I've identified is the issue as he has the variables sized at 32, meaning when there are 32 players on the server, the player with id=32 would cause index out of bounds since the array upper boundary is 31 when sized 32 (0 to 31).

Even if this was not the issue, his current save command would be fine to call at disconnect considering he is not calling any natives on the player in the save function. Looking closer, his logic is flawed for the key value used to save player data.

He has a single global variable to hold the key value, which is the players name retrieved in cmdGet(). There are 2 issues with this.
1. The key value is the players name. Keep in mind that multiple players can use the same name, resulting in multiple players sharing the same data. You should always use the players steam id as the key since this is unique.
2. You cannot use a single variable this way. You are getting the name value for player A when loading his data, but meanwhile multiple players will connect and disconnect while player A is playing. When he disconnects, you are storing his data under the name of the player that most recently connected.

To fix this:
PHP Code:
//Replace
new name32 
//with
new g_szAuthIDMAX_PLAYERS ][ 34 ]  

//If you are using an older version of AMX-X you may need this:
#define MAX_PLAYERS 32 
Everywhere you use the name variable, replace it with g_szAuthID[ id ]

At client_authorized(), call
PHP Code:
get_user_authidid g_szAuthIDid ] , charsmaxg_zAuthID[] ) ); 
__________________
Bugsy is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 12-01-2020 , 09:07   Re: nvault save
Reply With Quote #6

worked, thanks a lot.
lexzor is offline
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 02:22.


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