Raised This Month: $ Target: $400
 0% 

nVault saving enum.


Post New Thread Reply   
 
Thread Tools Display Modes
Kreation
Veteran Member
Join Date: Jan 2010
Location: Illinois
Old 06-11-2012 , 22:39   Re: nVault saving enum.
Reply With Quote #11

Quote:
Originally Posted by Napoleon_be View Post
Can't figure out how to get this to work... I achieve an achievement, 5 seconds after that, i change map to de_dust2 and it isn't saved or loaded.
Check to see if you are resetting the achievement variable before you save it without knowing it.
__________________
Hi.
Kreation is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-12-2012 , 11:01   Re: nVault saving enum.
Reply With Quote #12

Quote:
Originally Posted by Kreation View Post
Check to see if you are resetting the achievement variable before you save it without knowing it.
I'm not resetting any achievement..
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-12-2012 , 11:02   Re: nVault saving enum.
Reply With Quote #13

Show your code.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-12-2012 , 11:11   Re: nVault saving enum.
Reply With Quote #14

PHP Code:
#include <amxmodx>
#include <colorchat>
#include <fakemeta>
#include <engine>
#include <xs>
#include <nvault>

#define VERSION "1.0.0"

#define MaxPlayers 33

// native get_user_achievements(id)
// native set_user_achievements(id, Achievements)

new TotalAchievements[33]
new 
iTotalAchievements 12
new gVault

new const szAchievementSound[] = "Achievements/AchievementReach.wav"

enum _:iAchCount {
    
DIES,
    
SPRAYS,
    
KILLS,
    
CONNECT,
    
HEADSHOT,
    
KNIFE,
    
DISTANCE,
    
SURVIVE,
    
GRENADE,
    
USP,
    
GLOCK,
    
SNEAKY
}

new const 
iAchPoints[iAchCount] = {
    
500,
    
1000,
    
1000,
    
500,
    
500,
    
100,
    
3,
    
100,
    
50,
    
250,
    
250,
    
100
}

new 
iAchLevel[MaxPlayers][iAchCount]


new const 
Float:vecNullOrigin[3]

new 
Float:flDistance[MaxPlayers]
new 
Float:vecOldOrigin[MaxPlayers][3]
new 
Float:g_iFeet 35.0

public plugin_init() {
    
register_plugin("JailBreak Achievements"VERSION"NapoleoN#")
    
    
// Commands
    
register_clcmd("say /achs""Cmd_ShowAchievements")
    
    
// Events
    
register_event("DeathMsg""eDeath""a")
    
register_event("23""player_spray""a""1=112")
    
register_event("SendAudio""TerrorWins""a""2=%!MRAD_terwin")
    
    
// Fakemeta
    
register_forward(FM_CmdStart"CmdStart")
    
    
// nVault
    
nvault_open("AchievementSystem")
}

/*public plugin_natives() {
    register_library("AchievementsNatives")
    
    register_native("get_user_achievements", "_get_achievements")
    register_native("set_user_achievements", "_set_achievements")
}
*/

/*public _get_achievements(id) {
    return TotalAchievements[get_param(1)]
}

public _set_achievements(id, Achievements) {
    new iPlayer = get_param(1)
    TotalAchievements[iPlayer] = max(0, get_param(2))
    return TotalAchievements[iPlayer]
}
*/

public plugin_precache() {
    
precache_sound(szAchievementSound)
}

public 
TerrorWins() {     
    new 
players[32], count
    get_players
(playerscount"ae""TERRORIST")
    if(
count == 1) {
        
        new 
id players[0]
        
iAchLevel[id][SURVIVE]++
        
        if(
iAchLevel[id][SURVIVE] == 100) {
            
TotalAchievements[id]++
            
ColorChat(idGREEN"[Achievements]^1 Congratulations! You have unclocked the achievement:^3 Survivor!")
        }
    }
}

public 
client_putinserver(id) {
    
iAchLevel[id][CONNECT]++
    switch(
iAchLevel[id][CONNECT]) {
        case 
500: {
            
set_task(2.0"ReachAddict"id// Avoid playing the sound and printing the message to early.
        
}
    }
    
LoadData(id)
}

public 
ReachAddict(id) {
    
TotalAchievements[id]++
    
ColorChat(idGREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Addict!")
    
emit_sound(idCHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM)
}

public 
eDeath() {
    new 
iClipiAmmoiWeapon get_user_weapon(read_data(1), iClipiAmmo)
    
    if(
is_user_alive(read_data(1))) {
        
iAchLevel[read_data(1)][KILLS]++
    }
    
    if(
read_data(3)) {
        
iAchLevel[read_data(1)][HEADSHOT]++
    }
    
    if(
iWeapon == CSW_KNIFE) {
        
iAchLevel[read_data(1)][KNIFE]++
    }
    
    if(
iWeapon == CSW_HEGRENADE) {
        
iAchLevel[read_data(1)][GRENADE]++
    }
    
    if(
iWeapon == CSW_USP) {
        
iAchLevel[read_data(1)][USP]++
    }
    
    if(
iWeapon == CSW_GLOCK18) {
        
iAchLevel[read_data(1)][GLOCK]++
    }
    
    if(
get_user_weapon(read_data(2)) == CSW_AWP && iWeapon == CSW_KNIFE) {
        
iAchLevel[read_data(1)][SNEAKY]++
    }
    
    
iAchLevel[read_data(2)][DIES]++
    
    switch(
iAchLevel[read_data(2)][DIES]) {
        case 
500: {
            
TotalAchievements[read_data(2)]++
            
ColorChat(read_data(2), GREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Anti-GodMode!")
            
emit_sound(read_data(2), CHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM)
        }
    }
    
    switch(
iAchLevel[read_data(1)][KILLS]) {
        case 
1000: {
            
TotalAchievements[read_data(1)]++
            
ColorChat(read_data(1), GREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Prison Breaker!")
            
emit_sound(read_data(1), CHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM)
        }
    }
    
    switch(
iAchLevel[read_data(1)][HEADSHOT]) {
        case 
500: {
            
TotalAchievements[read_data(1)]++
            
ColorChat(read_data(1), GREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 HeadzHunterz!")
            
emit_sound(read_data(1), CHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM)
        }
    }
    
    switch(
iAchLevel[read_data(1)][KNIFE]) {
        case 
100: {
            
TotalAchievements[read_data(1)]++
            
ColorChat(read_data(1), GREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 The Butcher!")
            
emit_sound(read_data(1), CHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM)
        }
    }
    
    switch(
iAchLevel[read_data(1)][GRENADE]) {
        case 
50: {
            
TotalAchievements[read_data(1)]++
            
ColorChat(read_data(1), GREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Grenadier!")
            
emit_sound(read_data(1), CHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM)
        }
    }
    
    switch(
iAchLevel[read_data(1)][USP]) {
        case 
250: {
            
TotalAchievements[read_data(1)]++
            
ColorChat(read_data(1), GREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Officer!")
            
emit_sound(read_data(1), CHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM)
        }
    }
    
    switch(
iAchLevel[read_data(1)][GLOCK]) {
        case 
250: {
            
TotalAchievements[read_data(1)]++
            
ColorChat(read_data(1), GREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Glocker!")
            
emit_sound(read_data(1), CHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM)
        }
    }
    
    switch(
iAchLevel[read_data(1)][SNEAKY]) {
        case 
100: {
            
TotalAchievements[read_data(1)]++
            
ColorChat(read_data(1), GREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Sneaky...")
            
emit_sound(read_data(1), CHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM)
        }
    }
}

public 
player_spray() {
    
iAchLevel[read_data(2)][SPRAYS]++
    
    switch(
iAchLevel[read_data(2)][SPRAYS]) {
        case 
1000: {
            
TotalAchievements[read_data(2)]++
            
ColorChat(read_data(2), GREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Graffity Gangster!")
            
emit_sound(read_data(2), CHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM)
        }
    }
}

public 
Cmd_ShowAchievements(id) {
    new 
szTemp[500 char]
    
formatex(szTempcharsmax(szTemp), "JailBreak Achievements Menu^nTotal Achievements: \r%i/%i"TotalAchievements[id], iTotalAchievements)
    
    new 
menu menu_create(szTemp"Ach_Handler")
    
    
formatex(szTempcharsmax(szTemp), "Anti-GodMode! \r%i/%i"iAchLevel[id][DIES], iAchPoints[DIES])
    
menu_additem(menuszTemp"1")
    
    
formatex(szTempcharsmax(szTemp), "Graffity Gangster! \r%i/%i"iAchLevel[id][SPRAYS], iAchPoints[SPRAYS])
    
menu_additem(menuszTemp"2")
    
    
formatex(szTempcharsmax(szTemp), "Prison Breaker! \r%i/%i"iAchLevel[id][KILLS], iAchPoints[KILLS])
    
menu_additem(menuszTemp"3")
    
    
formatex(szTempcharsmax(szTemp), "Addict! \r%i/%i"iAchLevel[id][CONNECT], iAchPoints[CONNECT])
    
menu_additem(menuszTemp"4")
    
    
formatex(szTempcharsmax(szTemp), "HeadzHunterz! \r%i/%i"iAchLevel[id][HEADSHOT], iAchPoints[HEADSHOT])
    
menu_additem(menuszTemp"5")
    
    
formatex(szTempcharsmax(szTemp), "The Butcher! \r%i/%i"iAchLevel[id][KNIFE], iAchPoints[KNIFE])
    
menu_additem(menuszTemp"6")
    
    
formatex(szTempcharsmax(szTemp), "Sprinter! \r%i/%i"iAchLevel[id][DISTANCE], iAchPoints[DISTANCE])
    
menu_additem(menuszTemp"7")
    
    
formatex(szTempcharsmax(szTemp), "Survivor! \r%i/%i"iAchLevel[id][SURVIVE], iAchPoints[SURVIVE])
    
menu_additem(menuszTemp"8")
    
    
formatex(szTempcharsmax(szTemp), "Grenadier! \r%i/%i"iAchLevel[id][GRENADE], iAchPoints[GRENADE])
    
menu_additem(menuszTemp"9")
    
    
formatex(szTempcharsmax(szTemp), "Officer! \r%i/%i"iAchLevel[id][USP], iAchPoints[USP])
    
menu_additem(menuszTemp"10")
    
    
formatex(szTempcharsmax(szTemp), "Glocker! \r%i/%i"iAchLevel[id][GLOCK], iAchPoints[GLOCK])
    
menu_additem(menuszTemp"11")
    
    
formatex(szTempcharsmax(szTemp), "Sneaky... \r%i/%i"iAchLevel[id][SNEAKY], iAchPoints[SNEAKY])
    
menu_additem(menuszTemp"12")
    
    
menu_display(idmenu)
}

public 
Ach_Handler(idmenuitem) {
    if(
item == MENU_EXIT) {
        
menu_destroy(menu)
        return 
PLUGIN_HANDLED
    
}
    
    switch(
item) {
        case 
0: {
            
ColorChat(idGREEN"[Achievements]^1 Reach^3 %i^1 deaths to unlock this^4 Achievement!"iAchPoints[DIES])
            
ColorChat(idGREEN"[Achievements]^3 %i/%i."iAchLevel[id][DIES], iAchPoints[DIES])
        }
        case 
1: {
            
ColorChat(idGREEN"[Achievements]^1 Reach^3 %i^1 sprays to unlock this^4 Achievement!"iAchPoints[SPRAYS])
            
ColorChat(idGREEN"[Achievements]^3 %i/%i."iAchLevel[id][SPRAYS], iAchPoints[SPRAYS])
        }
        case 
2: {
            
ColorChat(idGREEN"[Achievements]^1 Reach^3 %i^1 kills to unlock this^4 Achievement!"iAchPoints[KILLS])
            
ColorChat(idGREEN"[Achievements]^3 %i/%i."iAchLevel[id][KILLS], iAchPoints[KILLS])
        }
        case 
3: {
            
ColorChat(idGREEN"[Achievements]^1 Reach^3 %i^1 connects to unlock this^4 Achievement!"iAchPoints[CONNECT])
            
ColorChat(idGREEN"[Achievements]^3 %i/%i."iAchLevel[id][CONNECT], iAchPoints[CONNECT])
        }
        case 
4: {
            
ColorChat(idGREEN"[Achievements]^1 Reach^3 %i^1 headshots to unlock this^4 Achievement!"iAchPoints[HEADSHOT])
            
ColorChat(idGREEN"[Achievements]^3 %i/%i."iAchLevel[id][HEADSHOT], iAchPoints[HEADSHOT])
        }
        case 
5: {
            
ColorChat(idGREEN"[Achievements]^1 Reach^3 %i^1 knife kills to unlock this^4 Achievement!"iAchPoints[KNIFE])
            
ColorChat(idGREEN"[Achievements]^3 %i/%i."iAchLevel[id][KNIFE], iAchPoints[KNIFE])
        }
        case 
6: {
            new 
Float:footsteps flDistance[id] / g_iFeet
            
            ColorChat
(idGREEN"[Achievements]^1 Reach^3 52800^1 footsteps to unlock this achievement!")
            
ColorChat(idGREEN"[Achievements]^3 %f/52800."footsteps)
        }
        case 
7: {
            
ColorChat(idGREEN"[Achievements]^1 Survive^3 %i^1 rounds to unlock this achievement!"iAchPoints[SURVIVE])
            
ColorChat(idGREEN"[Achievements]^1 %i/%i."iAchLevel[id][SURVIVE], iAchPoints[SURVIVE])
        }
        case 
8: {
            
ColorChat(idGREEN"[Achievements]^1 Kill^3 %i^1 players with a he grende to unlock this achievement!"iAchPoints[GRENADE])
            
ColorChat(idGREEN"[Achievements]^1 %i/%i."iAchLevel[id][GRENADE], iAchPoints[GRENADE])
        }
        case 
9: {
            
ColorChat(idGREEN"[Achievements]^1 Kill^3 %i^1 players with a USP to unlock this achievement!"iAchPoints[USP])
            
ColorChat(idGREEN"[Achievements]^1 %i/%i."iAchLevel[id][USP], iAchPoints[USP])
        }
        case 
10: {
            
ColorChat(idGREEN"[Achievements]^1 Kill^3 %i^1 players with a Glock18 to unlock this achievement!"iAchPoints[GLOCK])
            
ColorChat(idGREEN"[Achievements]^1 %i/%i."iAchLevel[id][GLOCK], iAchPoints[GLOCK])
        }
        case 
11: {
            
ColorChat(idGREEN"[Achievements]^1 Kill^3 %i^1 players with a knife while they carry an AWP to unlock this achievement!"iAchPoints[SNEAKY])
            
ColorChat(idGREEN"[Achievements]^1 %i/%i."iAchLevel[id][SNEAKY], iAchPoints[SNEAKY])
        }
    }
    return 
PLUGIN_HANDLED
}

public 
CmdStart(id) {
    if(!
is_user_alive(id)) {
        return 
FMRES_IGNORED
    
}
    
    if(
iAchLevel[id][DISTANCE] <= 2) {
        
        new 
Float:vecOrigin]
        
entity_get_vectoridEV_VEC_originvecOrigin )
    
        if(!
xs_vec_equal(vecOldOrigin[id], vecNullOrigin)) {
            
flDistance[id] += get_distance_f(vecOriginvecOldOrigin[id])
        }
        
        
xs_vec_copy(vecOriginvecOldOrigin[id])
        
        switch(
iAchLevel[id][DISTANCE]) {
            case 
0: {
                if(
flDistance[id] / g_iFeet >= 1)
                {
                    
iAchLevel[id][DISTANCE]++
                    
ColorChat(idGREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Baby Footsteps!")
                    
emit_sound(idCHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM )
                }
            }
            case 
1: {
                if(
flDistance[id] / g_iFeet >= 5280) {
                    
iAchLevel[id][DISTANCE]++
                    
ColorChat(idGREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Walk Away!")
                    
emit_sound(idCHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM )
                }
            }
            case 
2: {
                if(
flDistance[id] / g_iFeet >= 52800) {
                    
iAchLevel[id][DISTANCE]++
                    
TotalAchievements[id]++
                    
ColorChat(idGREEN"[Achievements]^1 Congratulations! You have unlocked the achievement:^3 Sprinter!")
                    
emit_sound(idCHAN_STATICszAchievementSound1.0ATTN_NORM0PITCH_NORM )
                }
            }
        }
    }
    return 
FMRES_IGNORED
}

public 
client_disconnect(id) {
    
SaveData(id)
}

public 
SaveData(id
{
    new 
SteamID[32]; get_user_authid(idSteamIDcharsmax(SteamID))
    new 
vaultkey[64], vaultdata[256] , iPos 
    
    formatex
(vaultkeycharsmax(vaultkey), "%s-AchievementSystem"SteamID)
    
    
iPos num_to_str(TotalAchievements[id], vaultdatacharsmax(vaultdata))
    
vaultdata[iPos++] = ' '
    
    
for(new iiAchCounti++) {
        
iPos += formatex(vaultdata[iPos], charsmax(vaultdata) - iPos"%i "iAchLevel[id][i])
    }
    
nvault_set(gVaultvaultkeyvaultdata)
}  

public 
LoadData(id
{
    new 
SteamID[35]; get_user_authid(idSteamIDcharsmax(SteamID)) 
    new 
vaultkey[64], vaultdata[256], szVal[6]
    
    
formatex(vaultkeycharsmax(vaultkey), "%s-AchievementSystem"SteamID
    
    
nvault_get(gVaultvaultkeyvaultdatacharsmax(vaultdata))
    
    
strbreak(vaultdataszValcharsmax(szVal), vaultdatacharsmax(vaultdata ))
    
    
TotalAchievements[id] = str_to_num(szVal)
    
    for(new 
iiAchCounti++) {
        
strbreak(vaultdataszVal charsmax(szVal) , vaultdata charsmax(vaultdata)) 
        
iAchLevel[id][i] = str_to_num(szVal)
    }

__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 06-12-2012 , 12:38   Re: nVault saving enum.
Reply With Quote #15

You should close the vault on plugin end.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-12-2012 , 16:16   Re: nVault saving enum.
Reply With Quote #16

Try doing some debugging to see why it isn't working. Put a client\console\server_print\log_amx where values are set for a player to make sure it is actually happening. Use nvault editor (see my sig) to view your nvault file to see if\how data is being saved. Make sure you shutdown\map-change after values are set so the data will be written to your .vault file.

Why are you using a switch for only one value?
PHP Code:
public client_putinserver(id) {
    
iAchLevel[id][CONNECT]++
    switch(
iAchLevel[id][CONNECT]) {
        case 
500: {
            
set_task(2.0"ReachAddict"id// Avoid playing the sound and printing the message to early.
        
}
    }
    
LoadData(id)


PHP Code:
public client_putinserver(id
{
    if ( ++
iAchLevel[id][CONNECT] == 500 
            
set_task(2.0"ReachAddict"id// Avoid playing the sound and printing the message to 
 
    
LoadData(id)

__________________

Last edited by Bugsy; 06-12-2012 at 16:16.
Bugsy is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 06-13-2012 , 08:31   Re: nVault saving enum.
Reply With Quote #17

Thanks everyone for the help.
Thanks Exolent, it's working
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Reply



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 05:23.


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