AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [SOLVED][nVault] Loading problems (https://forums.alliedmods.net/showthread.php?t=159902)

Excalibur.007 06-23-2011 07:51

[SOLVED][nVault] Loading problems
 
PHP Code:

SaveData(id)
{
    new 
vaultkey[64],vaultdata[256]
    
    
formatex(vaultkey63"%s"iUserSavedPassword[id])
    
formatex(vaultdata255"%i %i"iRank[id], iXP[id])
    
    
nvault_set(nVaultvaultkeyvaultdata)
    
    return 
PLUGIN_CONTINUE
}

LoadData(id)
{
    new 
vaultkey[64],vaultdata[256]
    
    
formatex(vaultkey63"%s"iUserSavedPassword[id])
    
formatex(vaultdata255"%i %i"iRank[id], iXP[id])
    
    
nvault_get(nVaultvaultkeyvaultdata255)
    
    new 
Rank[32], XP[32]
    
parse(vaultdataRank31XP31)
    
    
iRank[id] = str_to_num(Rank)
    
iXP[id] = str_to_num(XP)
    
    return 
PLUGIN_CONTINUE


Saving is not a problem. But loading it is a problem.

What is the problem?
- Loading works but it loads the wrong thing.
- E.g. You are Colonel rank but when it loads, it changes to Private rank.
- Same goes for EXP. They get resetted to 0.

Description
- Private is the default rank when they login.

nVault Editor view

Key: test
Value: 14 204800

Where key is the password for login, 14 is the rank number and 204800 is the EXP.

Extra information
PHP Code:

new const RANKS[][]=
{
    
"Unranked"// 0
    
"Private"// 1
    
"Private 1st Class"// 2
    
"Corporal"// 3
    
"Sergeant"// 4
    
"Staff Sergeant"// 5
    
"Sergeant 1st Class"// 6
    
"Master Sergeant"// 7
    
"Sergeant Major"// 8
    
"2nd Lieutenant"// 9
    
"1st Lieutenant"// 10
    
"Captain"// 11
    
"Major"// 12
    
"Lieutenant Colonel"// 13
    
"Colonel"// 14
    
"Brigadier General"// 15
    
"Major General"// 16
    
"Lieutenant General"// 17
    
"General"// 18
    
"General of the Army" // 19
}

new const 
EXP[] =
{
    
0// 0
    
0// 1
    
50// 2
    
100// 3
    
200// 4
    
400// 5
    
800// 6
    
1600// 7
    
3200// 8
    
6400// 9
    
12800// 10
    
25600// 11
    
51200// 12
    
102400// 13
    
204800// 14
    
409600// 15
    
819200// 16
    
1638400// 17
    
3276800// 18
    
6553600 // 19



drekes 06-23-2011 08:29

Re: [nVault] Loading problems
 
According to your notation, iUserSavedPassword[id] is an integer value.
So you have to use %i or %d when formatting.

PHP Code:

formatex(vaultkey63"%d"iUserSavedPassword[id]) 

Also you don't have to format the vaultdata in the LoadData() function.
And the returns aren't needed, but they shouldn't cause any problems.

Excalibur.007 06-23-2011 08:30

Re: [nVault] Loading problems
 
iUserSavedPassword is a string not a integer. Sorry for not adding that. And can you show an example of it. This is my first time doing nVault.

As you can see

Code:

nVault Editor view

Key: test
Value: 14 204800

test is the password which is a string. Login system works. Just that it loads incorrectly

EDIT: I tried drekes method. It still loads incorrectly.

EDIT2: Stupid me. It was the login problem. I setted the rank to 0 after it loads the data when it should be the opposite. OMG. I spent 2 hour fixing this...

Exolent[jNr] 06-23-2011 08:55

Re: [nVault] Loading problems
 
Quote:

Originally Posted by Excalibur.007 (Post 1494101)
PHP Code:

SaveData(id)
{
    new 
vaultkey[64],vaultdata[256]
    
    
formatex(vaultkey63"%s"iUserSavedPassword[id])
    
formatex(vaultdata255"%i %i"iRank[id], iXP[id])
    
    
nvault_set(nVaultvaultkeyvaultdata)
    
    return 
PLUGIN_CONTINUE
}

LoadData(id)
{
    new 
vaultkey[64],vaultdata[256]
    
    
formatex(vaultkey63"%s"iUserSavedPassword[id])
    
formatex(vaultdata255"%i %i"iRank[id], iXP[id])
    
    
nvault_get(nVaultvaultkeyvaultdata255)
    
    new 
Rank[32], XP[32]
    
parse(vaultdataRank31XP31)
    
    
iRank[id] = str_to_num(Rank)
    
iXP[id] = str_to_num(XP)
    
    return 
PLUGIN_CONTINUE


Saving is not a problem. But loading it is a problem.

What is the problem?
- Loading works but it loads the wrong thing.
- E.g. You are Colonel rank but when it loads, it changes to Private rank.
- Same goes for EXP. They get resetted to 0.

Description
- Private is the default rank when they login.

nVault Editor view

Key: test
Value: 14 204800

Where key is the password for login, 14 is the rank number and 204800 is the EXP.

Extra information
PHP Code:

new const RANKS[][]=
{
    
"Unranked"// 0
    
"Private"// 1
    
"Private 1st Class"// 2
    
"Corporal"// 3
    
"Sergeant"// 4
    
"Staff Sergeant"// 5
    
"Sergeant 1st Class"// 6
    
"Master Sergeant"// 7
    
"Sergeant Major"// 8
    
"2nd Lieutenant"// 9
    
"1st Lieutenant"// 10
    
"Captain"// 11
    
"Major"// 12
    
"Lieutenant Colonel"// 13
    
"Colonel"// 14
    
"Brigadier General"// 15
    
"Major General"// 16
    
"Lieutenant General"// 17
    
"General"// 18
    
"General of the Army" // 19
}

new const 
EXP[] =
{
    
0// 0
    
0// 1
    
50// 2
    
100// 3
    
200// 4
    
400// 5
    
800// 6
    
1600// 7
    
3200// 8
    
6400// 9
    
12800// 10
    
25600// 11
    
51200// 12
    
102400// 13
    
204800// 14
    
409600// 15
    
819200// 16
    
1638400// 17
    
3276800// 18
    
6553600 // 19



Try logging the value of iUserSavedPassword inside of the load function.

Excalibur.007 06-23-2011 09:04

Re: [nVault] Loading problems
 
Yeah. I found out that the function automatically sets the iRank to 0. My bad. I wasted 2 hour finding the problem. Thanks drekes for removing some of the LoadData code.

and exolent sorry to bother you but it's fixed now. really sorry :X.


All times are GMT -4. The time now is 23:24.

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