The code below will save every time a client kills another client. That should simplify things for you.
Code:
/*
Permanent Kills/Deaths v.1.0 by Chris/Unbonami <[email protected]>
17 Jan. 2007
This plugin saves the Kills and Deaths for each user(by steamid and mapname)
When he gets on the same map again his Kills and Deaths are loaded.
Possibles bugs: Kills or Deaths larger than an integer/float ?
*/
#include <amxmodx>
#include <nvault>
#include <fakemeta>
#define VERSION "1.0"
new const SAVE_FILE
[] = "KillsDeaths";
new Vault;
public plugin_init
()
{
register_plugin("Permanent Kills/Deaths", VERSION,
"Chris");
register_event("DeathMsg",
"Event_DeathMsg",
"a",
"1>0")
}
public Event_DeathMsg
()
{
new Killer
= read_data(1)
new Victim
= read_data(2)
SaveData
(Killer
)
if(Killer
!= Victim
)
{
SaveData
(Victim
)
}
}
public client_putinserver
(id
)
{
LoadData
(id
);
return PLUGIN_HANDLED;
}
public client_disconnect
(id
)
{
SaveData
(id
);
return PLUGIN_HANDLED;
}
stock GetSaveKey
(id, Key
[64])
{
static AuthId
[33];
get_user_authid(id,AuthId,
32);
format(Key,
63,
"%s",AuthId
);
}
public plugin_end
()
{
new iPlayers
[32],iNum;
for(new i
=0;i<iNum;i
++)
{
SaveData
(iPlayers
[i
]);
}
return PLUGIN_HANDLED;
}
public SaveData
(id
)
{
Vault
= nvault_open
(SAVE_FILE
);
if(Vault
== INVALID_HANDLE
)
{
log_amx("Error opening nVault file: %s", SAVE_FILE
);
return PLUGIN_HANDLED;
}
static Key
[64], Data
[30];
new Kills
= pev
(id, pev_frags
)
new Deaths
= get_user_deaths(id
)
GetSaveKey
(id,Key
);
format(Data,
29,
"%i %i", Kills, Deaths
);
nvault_set
(Vault, Key, Data
);
nvault_close
(Vault
);
return PLUGIN_HANDLED;
}
public LoadData
(id
)
{
Vault
= nvault_open
(SAVE_FILE
);
if(Vault
== INVALID_HANDLE
)
{
log_amx("Error opening nVault file: %s", SAVE_FILE
);
return PLUGIN_HANDLED;
}
static Key
[64], Data
[30];
new TimeStamp;
GetSaveKey
(id,Key
);
if(nvault_lookup
(Vault, Key, Data,
29, TimeStamp
))
{
new sKills
[15],sDeaths
[15];
parse(Data,sKills,
14,sDeaths,
14);
set_pev
(id, pev_frags,
str_to_float(sKills
));
set_pdata_int
(id,
290,
str_to_num(sDeaths
));
}
nvault_close
(Vault
);
return PLUGIN_HANDLED;
}