Raised This Month: $ Target: $400
 0% 

Doesnt save right


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 01-06-2011 , 19:01   Doesnt save right
Reply With Quote #1

Propably my dumbest post but i need a fresh pear of eyes too see what I couldn't.

PHP Code:
public client_putinserver(id)
{
    new 
g_auth[64]
    
get_user_authid(id,g_auth,63)

 
LastPlaytime[id] =  nvault_get(g_vault,g_auth)
str_to_num(LastPlaytime[id])
 }

ReturnPlaytime(id)
{
szPlaytime[id] = LastPlaytime[id] + get_user_time(id,1)
return 
szPlaytime[id]
}

public 
client_disconnect(id)
{
ReturnPlaytime(id)

  new 
g_auth[64]
    
get_user_authid(id,g_auth,63)

    
nvault_set(g_vault,g_auth,szPlaytime[id])

The output is always unreadable or sometimes dont even write.

Last edited by SpeeDeeR; 01-06-2011 at 19:30.
SpeeDeeR is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 01-06-2011 , 19:27   Re: Doesnt save right
Reply With Quote #2

It doesn't make any sense for me.
you create new variables in a function, but give them the g_ prefix which points to a global variable. (g_auth)
sz points to a string value (szPlaytime[id])

I got to this, but i can't ensure it will work right, since you didn't explain what it's supposed to do.
PHP Code:
public client_putinserver(id)
{
    new 
g_auth[64]
    
get_user_authid(id,g_auth,63)

    new 
vaultdata[64];
    
nvault_get(g_vault,g_authvaultdatacharsmax(vaultdata))
    
LastPlaytime[id] = str_to_num(vaultdata)
}

ReturnPlaytime(id)
{
    
szPlaytime[id] = LastPlaytime[id] + get_user_time(id,1)
    return 
szPlaytime[id]
}

public 
client_disconnect(id)
{
    
ReturnPlaytime(id)

    new 
g_auth[64]
    
get_user_authid(id,g_auth,63)

    
// new vaultdata
    
nvault_set(g_vault,g_auth,szPlaytime[id])

__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 01-06-2011 , 19:35   Re: Doesnt save right
Reply With Quote #3

already tried
PHP Code:
 nvault_get(g_vault,g_authvaultdatacharsmax(vaultdata))   
 
LastPlaytime[id] = str_to_num(vaultdata
Its an ordinary played time plugin.
SpeeDeeR is offline
drekes
Veteran Member
Join Date: Jul 2009
Location: Vault 11
Old 01-06-2011 , 20:00   Re: Doesnt save right
Reply With Quote #4

not sure but try saving it like this:
PHP Code:
new data[64];
copy(datacharsmax(data), szPlaytime[id]);
nvault_set(g_vaultg_authdata); 
__________________

Quote:
Originally Posted by nikhilgupta345 View Post
You're retarded.
drekes is offline
Send a message via MSN to drekes
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 01-06-2011 , 20:55   Re: Doesnt save right
Reply With Quote #5

Check this thread:
http://forums.alliedmods.net/showthread.php?t=114505
__________________
Impossible is Nothing
Sylwester is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 01-10-2011 , 16:56   Re: Doesnt save right
Reply With Quote #6

When the last value is different from 0 the server crashes.
PS: I didnt want another thread.

PHP Code:
public client_putinserver(id)
{
    
get_user_authid(id,g_authid[id],63)
    
g_connect_time[id] = time()
    
    static 
data[256], timestamp;
    if( 
nvault_lookup(g_vaultg_authid[id], datasizeof(data) - 1timestamp) )
        
Load(iddata);
}

Load(iddata[256])
{
static 
num[5];
strbreak(datanumsizeof(num) - 1datasizeof(data) - 1);

g_time_played[id] = str_to_num(num);

strbreak(datanumsizeof(num) - 1datasizeof(data) - 1);
g_kills[id] = clamp(str_to_num(num), 0g_kills[id]);

strbreak(datanumsizeof(num) - 1datasizeof(data) - 1);
g_suicides[id] = clamp(str_to_num(num), 0g_suicides[id]);

strbreak(datanumsizeof(num) - 1datasizeof(data) - 1);
g_survives[id] = clamp(str_to_num(num), 0g_survives[id]);

strbreak(datanumsizeof(num) - 1datasizeof(data) - 1);
g_deaths[id] = clamp(str_to_num(num), 0g_deaths[id])

}

Save(id)
{
static 
data[256];
ReturnTime(id)

new 
len formatex(datasizeof(data) - 1"%i"g_time_played[id])
len += formatex(data[len], sizeof(data) - len 1" %i"g_kills[id])
len += formatex(data[len], sizeof(data) - len 1" %i"g_suicides[id])
len += formatex(data[len], sizeof(data) - len 1" %i"g_survives[id])
len += formatex(data[len], sizeof(data) - len 1" %i"g_deaths[id])

nvault_set(g_vaultg_authid[id], data);

}

public 
ReturnTime(id)
{
g_time_played[id] += time() - g_connect_time[id]
return 
g_time_played[id]

Nvault output:
Code:
false Tuesday, January 11, 2011 12:05:47 AM 1294697147 1 0 0 0
SpeeD Tuesday, January 11, 2011 12:05:54 AM 265 0 1 1 1

Last edited by SpeeDeeR; 01-25-2011 at 11:44.
SpeeDeeR is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 01-24-2011 , 08:27   Re: Doesnt save right
Reply With Quote #7

bump
SpeeDeeR is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-24-2011 , 18:18   Re: Doesnt save right
Reply With Quote #8

Show your full code.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
SpeeDeeR
Veteran Member
Join Date: Mar 2010
Location: Bulgaria
Old 01-25-2011 , 11:44   Re: Doesnt save right
Reply With Quote #9

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <nvault>

#define PLUGIN " x "
#define VERSION "x"
#define AUTHOR "x"

new g_deaths[33]
new 
g_survives[33]
new 
g_kills[33]
new 
g_suicides[33]
new 
g_connect_time[33]
new 
g_auth[33][64]
new 
g_time_played[33]

new 
g_vault

public plugin_init() {
    
register_plugin(PLUGINVERSIONAUTHOR)
    
register_logevent("round_end",2,"1=Round_End")
    
register_event("DeathMsg","Event_Death","a"
    
register_clcmd("say /h","show_time")
    
    
g_vault nvault_open("rank_test")
    
}

public 
plugin_end()
    
nvault_close(g_vault)

public 
round_end()
{
    new 
Players[32]
    new 
playerCountidplayer
    get_players
(PlayersplayerCount"ach")
    for (
id=0id<playerCountid++)
    {
        
player Players[id
        if(
get_user_team(player) == 1)
        {
            
g_survives[player]++
            
Save(player)
        }
    }
}

public 
Event_Death()
{
    new 
killer read_data(1)
    new 
victim read_data(2)
    
    if( 
killer != victim
    {
        
g_kills[killer]++
        
Save(killer)
        
        
g_deaths[victim]++
        
Save(victim)
    }
    else 
    {
        
g_suicides[victim]++
        
Save(victim)
    }
}

public 
client_putinserver(id)
{
    
get_user_authid(id,g_auth[id],63)
    
g_connect_time[id] = time()
    
    static 
data[256], timestamp;
    if( 
nvault_lookup(g_vaultg_auth[id], datasizeof(data) - 1timestamp) )
        
Load(iddata);
}


public 
client_disconnect(id)
{
    
Save(id)
}  

Load(iddata[256])
{
static 
num[4];
strbreak(datanumsizeof(num) - 1datasizeof(data) - 1);

g_time_played[id] = str_to_num(num);

strbreak(datanumsizeof(num) - 1datasizeof(data) - 1);
g_kills[id] = clamp(str_to_num(num), 0g_kills[id]);

strbreak(datanumsizeof(num) - 1datasizeof(data) - 1);
g_suicides[id] = clamp(str_to_num(num), 0g_suicides[id]);

strbreak(datanumsizeof(num) - 1datasizeof(data) - 1);
g_survives[id] = clamp(str_to_num(num), 0g_survives[id]);

strbreak(datanumsizeof(num) - 1datasizeof(data) - 1);
g_deaths[id] = clamp(str_to_num(num), 0g_deaths[id])

}

Save(id)
{
static 
data[256];
ReturnTime(id)

new 
len formatex(datasizeof(data) - 1"%i"g_time_played[id])
len += formatex(data[len], sizeof(data) - len 1" %i"g_kills[id])
len += formatex(data[len], sizeof(data) - len 1" %i"g_suicides[id])
len += formatex(data[len], sizeof(data) - len 1" %i"g_survives[id])
len += formatex(data[len], sizeof(data) - len 1" %i"g_deaths[id])

nvault_set(g_vaultg_auth[id], data);

}

public 
ReturnTime(id)
{
g_time_played[id] += time() - g_connect_time[id]
return 
g_time_played[id]
}

public 
show_time(id){
if(
g_time_played[id] == -1){
client_print(idprint_chat"Server was unable to retrieve your time played.")
return
}
new 
time()-g_connect_time[id]+g_time_played[id]
new 
t/3600
new t/60%60
new t%60
client_print
(idprint_chat"Your total time played is: %d hour%s %d minute%s %d second%s.",
hh==1?"":"s"mm==1?"":"s"ss==1?"":"s")

SpeeDeeR is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-25-2011 , 14:29   Re: Doesnt save right
Reply With Quote #10

Code:
Remember, saving time played:
time played = current time - connect time + previous time played

player connects
- connect time = 5
- time played = 0 (first time)

player disconnects
- time() = 120
- time played = 120 - 5 + 0 = 115
That is how it should be originally.
However, you added the saving in other places besides player disconnect.
Therefore, this happens:

Code:
Remember, saving time played:
time played = current time - connect time + previous time played

player connects
- connect time = 5
- time played = 0 (first time)

round ends
- time() = 10
- time played = 10 - 5 + 0 = 5

player dies
- time() = 50
- time played = 50 - 5 + 5 = 50

round ends
- time() = 100
- time played = 100 - 5 + 50 = 145

player disconnects
- time() = 120
- time played = 120 - 5 + 145 = 260
To fix this, you need to update the player's connect time each save.

Code:
public ReturnTime(id) {     g_time_played[id] += time() - g_connect_time[id]     return g_time_played[id] }

Code:
public ReturnTime(id) {     new _time = time()     g_time_played[id] += _time - g_connect_time[id]     g_connect_time[id] = _time     return g_time_played[id] }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 01:57.


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