I'm working on COD. I having trouble withe the xp saving and loading and the showhud function. the xp doesn't save so therefore it wont load. And i've tried to make the showhud stay visible permanently but it dissapears randomnly sometimes. I get this in the console :
Sorry the script is very messy. can you please help me do this?
PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <cstrike>
#include <fakemeta>
#include <nvault>
#define PLUGIN "COD4"
#define VERSION "2.4"
#define AUTHOR "FreeStylez`"
new const RANK[55] =
{
0,
300,
1200,
2700,
4800,
7500,
10800,
14700,
19200,
24300,
30000,
36500,
43800,
51900,
60800,
70500,
81000,
92300,
104400,
117300,
131000,
145500,
160800,
176900,
193800,
211500,
230000,
249300,
269400,
290300,
312400,
335700,
360200,
385900,
412800,
440900,
470200,
500700,
532400,
565300,
599400,
634700,
671200,
708900,
747800,
829200,
871700,
915400,
960300,
1006400,
1053700,
1102200,
1151900,
1202800
}
new const RANKNAMES[55][] =
{
"Private First Class",
"Private First Class I",
"Private First Class II",
"Lance Corporal",
"Lance Corporal I",
"Lance Corporal II",
"Corporal",
"Corporal I",
"Corporal II",
"Sargeant",
"Sargeant I",
"Sargeant II",
"Staff Sargeant",
"Staff Sargeant I",
"Straff Sargeant II",
"Gunnery Sargeant",
"Gunnery Sargeant I",
"Gunnery Sargeant II",
"Master Sargeant",
"Master Sargeant I",
"Master Sargeant II",
"Master Gunnery Sergeant",
"Master Gunnery Sergeant I",
"Master Gunnery Sergeant II",
"2nd Lieutenant",
"2nd Lieutenant I",
"2nd Lieutenant II",
"1st Lieutenant",
"1st Lieutenant I",
"1st Lieutenant II",
"Captain",
"Captain I",
"Captain II",
"Major",
"Major I",
"Major II",
"Lt. Colonel",
"Lt. Colonel I",
"Lt. Colonel II",
"Colonel",
"Colonel I",
"Colonel II",
"Brigadier General",
"Brigadier General I",
"Brigadier General II",
"Major General",
"Major General I",
"Major General II",
"Lieutenant General",
"Lieutenant General I",
"Lieutenant General II",
"General",
"General I",
"General II",
"Commander"
}
new gXP[33], gLevel[33];
new XP_Kill, XP_Hs;
new g_vault;
new g_status_sync;
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_cvar("cod4_version", VERSION, FCVAR_SERVER);
set_cvar_string("cod4version", VERSION);
register_event("DeathMsg", "eDeath", "a");
register_event("RoundTime", "on_round", "b")
XP_Kill = register_cvar("cod_kill", "100");
XP_Hs = register_cvar("cod_hs","200");
g_vault = nvault_open("CODRANK");
register_clcmd( "say /class", "ClassMenu" );
}
public eDeath()
{
new attacker = read_data(1);
new victim = read_data(2);
new headshot = read_data(3);
new gPrintMSG[100];
new gXPKill = get_pcvar_num(XP_Kill);
new gXPHs = get_pcvar_num(XP_Hs);
if( victim == attacker )
return PLUGIN_HANDLED;
if( !headshot && victim != attacker )
{
gXP[attacker] += gXPKill
formatex(gPrintMSG, charsmax(gPrintMSG), "You gained %d XP!", gXPKill);
}
else if( headshot && victim != attacker )
{
gXP[attacker] += (gXPKill + gXPHs);
formatex(gPrintMSG, charsmax(gPrintMSG), "You gained %d XP!^x01 (Headshot)", (gXPHs + gXPKill));
}
Print(attacker, gPrintMSG);
CheckLevel(attacker)
SaveData(attacker)
ShowHud(attacker)
return PLUGIN_CONTINUE
}
public CheckLevel(id)
{
if( gXP[id] >= RANK[gLevel[id]] )
{
Print(id, "[COD:MW2] Congratulations! You have been promoted to:^x01 %s^x03!", RANKNAMES[gLevel[id]]);
gLevel[id]++;
}
}
public on_round(id)
{
LoadData(id)
CheckLevel(id)
ShowHud(id)
}
public ShowHud(id)
{
if(is_user_connected(id) && id>0 && !is_user_bot(id))
{
new message[56]
new next_level = gLevel[id]+1
if(next_level>49)
next_level = 49
format(message, 55,"[COD:MW2] Title: %s | Kills: %d/%d ", RANKNAMES[gLevel[id]], gXP[id], RANK[gLevel[id]])
message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("StatusText"), {0, 0, 0}, id);
write_byte(0);
write_string(message);
message_end();
}
set_task(0.3, "showhud", id)
}
public client_connect(id)
{
LoadData(id);
}
public client_disconnect(id)
{
SaveData(id);
gXP[id] = 0;
gLevel[id] = 0;
}
public SaveData(id)
{
new authid[32];
get_user_authid(id, authid, 31);
new key[64], data[101];
format(key, 63, "CODRANK-%s", authid);
format(data, 100, "%i , %i", gXP[id],gLevel[id]);
nvault_set(nvault_open("CODRANK"), key, data);
}
public LoadData(id)
{
new AuthID[35];
get_user_authid(id,AuthID,34);
new vaultkey[64],vaultdata[256];
format(vaultkey,63,"%s-Mod",AuthID);
format(vaultdata,255,"%i#%i#",gXP[id],gLevel[id]);
nvault_get(g_vault,vaultkey,vaultdata,255);
replace_all(vaultdata, 255, "#", " ");
new gXP[32], gLevel[32];
parse(vaultdata, gXP, 31, gLevel, 31);
gXP[id] = str_to_num(gXP);
gLevel[id] = str_to_num(gLevel);
return PLUGIN_CONTINUE;
}
public Load(id) {
new authid[32];
get_user_authid(id, authid, 31);
new key[64], data[101];
new gexperience[8]
format(key, 63, "CODRANK-%s", authid);
format(data, 100, "%i , %i", gXP[id], gLevel[id]);
nvault_get(nvault_open("CODRANK"), key, data, 81);
replace_all(data, 100, "#", " ");
parse(data, gexperience, 7);
gXP[id] = str_to_num(gexperience);
}
public ClassMenu(id)
{
new menu = menu_create("\yChoose a class:", "menu_handler")
menu_additem(menu, "\w Grenadier [Assault]", "1", 0);
menu_additem(menu, "\w First Recon [Sub Machine]", "2", 0);
menu_additem(menu, "\w Overwatch [Light Machine Gun]", "3", 0);
menu_additem(menu, "\w Scout Sniper", "4", 0);
menu_additem(menu, "\w Riot Squad ", "5", 0);
menu_setprop(menu, MPROP_EXIT, MEXIT_ALL);
menu_display(id, menu, 0);
}
public menu_handler(id, menu, item)
{
if( item == MENU_EXIT )
{
menu_destroy(menu);
return PLUGIN_HANDLED;
}
new data[6], szName[64];
new access, callback;
menu_item_getinfo(menu, item, access, data,charsmax(data), szName,charsmax(szName), callback);
new key = str_to_num(data);
switch(key)
{
case 1: //grenadier
{
give_item(id, "weapon_knife");
give_item(id, "weapon_flashbang");
give_item(id, "weapon_flashbang");
give_item(id, "weapon_aug");
give_item(id, "ammo_556nato");
give_item(id, "ammo_556nato");
give_item(id, "ammo_556nato");
give_item(id, "weapon_glock18");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
client_print(id, print_chat, "You are now a Grenadier");
}
case 2: // First Recon
{
strip_user_weapons(id);
give_item(id, "weapon_knife");
give_item(id, "weapon_ump45");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "weapon_glock18");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
client_print(id, print_chat, "You are now an Assault");
}
case 3: //Overwatch
{
strip_user_weapons(id);
give_item(id, "weapon_knife");
give_item(id, "weapon_hegrenade");
give_item(id, "weapon_glock18");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
give_item(id, "weapon_m3");
give_item(id, "ammo_buckshot");
give_item(id, "ammo_buckshot");
give_item(id, "ammo_buckshot");
give_item(id, "ammo_buckshot");
give_item(id, "ammo_buckshot");
client_print(id, print_chat, "You are now a Overwatch");
}
case 4: //Scout Snipist
{
give_item(id, "weapon_knife");
give_item(id, "weapon_hegrenade");
give_item(id, "weapon_flashbang");
give_item(id, "weapon_flashbang");
give_item(id, "weapon_scout");
give_item(id, "ammo_762nato");
give_item(id, "weapon_deagle");
give_item(id, "ammo_50ae");
give_item(id, "ammo_50ae");
give_item(id, "ammo_50ae");
give_item(id, "ammo_50ae");
give_item(id, "ammo_50ae");
client_print(id, print_chat, "You are now a Scout Snipist");
}
case 5: //Riot Control
{
give_item(id, "weapon_knife");
give_item(id, "weapon_hegrenade");
give_item(id, "weapon_flashbang");
give_item(id, "weapon_flashbang");
give_item(id, "weapon_knife");
give_item(id, "weapon_shield");
give_item(id, "weapon_deagle");
give_item(id, "ammo_50ae");
give_item(id, "ammo_50ae");
give_item(id, "ammo_50ae");
give_item(id, "ammo_50ae");
give_item(id, "ammo_50ae");
give_item(id, "weapon_glock18");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
give_item(id, "ammo_9mm");
give_item(id, "weapon_usp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
give_item(id, "ammo_45acp");
client_print(id, print_chat, "You are now a Riot Controller");
}
}
menu_destroy(menu);
return PLUGIN_HANDLED;
}
Print(iPlayer, const sMsg[], any:...)
{
static i; i = iPlayer ? iPlayer : get_Player();
if ( !i ) return;
new sMessage[256];
new len = formatex(sMessage, sizeof(sMessage) - 1, "^x04[HNS Ranks]^x03 ");
vformat(sMessage[len], sizeof(sMessage) - 1 - len, sMsg, 3);
sMessage[192] = '^0';
static msgid_SayText;
if ( !msgid_SayText ) msgid_SayText = get_user_msgid("SayText");
new const team_Names[][] =
{
"",
"TERRORIST",
"CT",
"SPECTATOR"
};
new sTeam = get_user_team(i);
team_Info(i, iPlayer, team_Names[0]);
message_begin(iPlayer ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgid_SayText, _, iPlayer);
write_byte(i);
write_string(sMessage);
message_end();
team_Info(i, iPlayer, team_Names[sTeam]);
}
team_Info(receiver, sender, sTeam[])
{
static msgid_TeamInfo;
if ( !msgid_TeamInfo ) msgid_TeamInfo = get_user_msgid("TeamInfo");
message_begin(sender ? MSG_ONE_UNRELIABLE : MSG_BROADCAST, msgid_TeamInfo, _, sender);
write_byte(receiver);
write_string(sTeam);
message_end();
}
get_Player()
{
for ( new iPlayer = 1; iPlayer <= get_maxplayers(); iPlayer++ )
{
return iPlayer;
}
return 0;
}
//////////FROM BF2 RANK MOD//////////
public on_ShowStatus(id) //called when id looks at someone
{
new name[32], pid = read_data(2);
new pidrank = gLevel[pid];
get_user_name(pid, name, 31);
new color1 = 0, color2 = 0;
if (get_user_team(pid) == 1)
color1 = 255;
else
color2 = 255
set_hudmessage(color1, 100, color2, -1.0, 0.35, 0, 0.01, 20.0);
ShowSyncHudMsg(id, g_status_sync, "%s^nLevel: %d", name, gLevel[pidrank]+1);
}
public on_HideStatus(id)
{
ClearSyncHud(id, g_status_sync);
}