| natkemon |
03-17-2011 03:43 |
[help] new variable? Check level?
At the bottom of this function i made it so that it checks that your XP must make be 1251900/1251900 to get prestige. How do i make it so that when it reaches prestige it resets back to "Private First class" and count prestige as 1?
For example
I reach prestige... it resets to Private First class.. Prestige count = 1
I reach prestige again ... it resets to Private First class again.. Prestige count = 2
I reach prestige again... it resets to Private First class again.. Prestige count = 3
PHP Code:
public CheckLevel(id) { if( gXP[id] >= RANK[gLevel[id]] ) { client_cmd(id, "spk cod4/levelup.wav") ColorChat(id, GREEN, "^x04[COD:MW2]^x01 Congratulations! You have been promoted to:^x04 %s^x01.", RANKNAMES[gLevel[id]+1]); gLevel[id]++; } // Commander is Rank 54 if( gLevel[id] == 55 ) gLevel[id] = 0 }
PHP Code:
#include <amxmodx> #include <amxmisc> #include <fun> #include <cstrike> #include <fakemeta> #include <nvault>
#define PLUGIN "COD4" #define VERSION "2.4" #define AUTHOR "FreeStylez`" #define MAXCLASSES 7
#define CLASS_NOTHING 0 #define CLASS_GRENADIER 1 #define CLASS_FIRSTRECON 2 #define CLASS_OVERWATCH 3 #define CLASS_SCOUTSNIPER 4 #define CLASS_RIOTCONTROL 5 #define CLASS_SPECTATE 6
#if cellbits == 32 #define OFFSET_CSMONEY 115 #else #define OFFSET_CSMONEY 140 #endif
#define OFFSET_LINUX 5
enum Color { NORMAL = 1, // clients scr_concolor cvar color GREEN, // Green Color TEAM_COLOR, // Red, grey, blue GREY, // grey RED, // Red BLUE, // Blue }
new const CLASSES[MAXCLASSES][] = { "None", "Grenadier", "First Recon", "Overwatch", "Scout Sniper", "Riot Control", "Spectate" }
new const RANK[56] = { 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, 1251900 } new const RANKNAMES[55][] = { "Private First Class", // 0 "Private First Class I", // 1 "Private First Class II", // 2 "Lance Corporal", // 3 "Lance Corporal I", // 4 "Lance Corporal II", // 5 "Corporal", // 6 "Corporal I", // 7 "Corporal II", // 8 "Sargeant", // 9 "Sargeant I", // 10 "Sargeant II", // 11 "Staff Sargeant", // 12 "Staff Sargeant I", // 13 "Straff Sargeant II", // 14 "Gunnery Sargeant", // 15 "Gunnery Sargeant I", // 16 "Gunnery Sargeant II", // 17 "Master Sargeant", // 18 "Master Sargeant I", // 19 "Master Sargeant II", // 20 "Master Gunnery Sergeant", // 21 "Master Gunnery Sergeant I", // 22 "Master Gunnery Sergeant II", // 23 "2nd Lieutenant", // 25 "2nd Lieutenant I", // 25 "2nd Lieutenant II", // 26 "1st Lieutenant", // 27 "1st Lieutenant I", // 28 "1st Lieutenant II", // 29 "Captain", // 30 "Captain I", // 31 "Captain II", // 32 "Major", // 33 "Major I", // 34 "Major II", // 35 "Lt. Colonel", // 36 "Lt. Colonel I", // 37 "Lt. Colonel II", // 38 "Colonel", // 39 "Colonel I", // 40 "Colonel II", // 41 "Brigadier General", // 42 "Brigadier General I", // 43 "Brigadier General II", // 44 "Major General", // 45 "Major General I", // 46 "Major General II", // 47 "Lieutenant General", // 48 "Lieutenant General I", // 49 "Lieutenant General II", // 50 "General", // 51 "General I", // 52 "General II", // 53 "Commander", // 54 "Prestige" // 55 }
new gXP[33], gLevel[33]; new XP_Kill, XP_Hs; new g_vault; new g_status_sync;
new PlayerClass[33]; new PlayerTClass[33];
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", "100000"); XP_Hs = register_cvar("cod_hs","200000"); g_vault = nvault_open("CODRANK"); register_menucmd(register_menuid("menu_ChooseClass"),1023,"DoChooseClass"); register_event("ResetHUD", "ResetHud", "b")
register_clcmd("say /class", "ChooseClass") register_clcmd("say_team /class", "ChooseClass") register_clcmd("say /class", "ShowClass") register_clcmd("say /rank", "ShowRank") g_vault = nvault_open("cod4") } public plugin_precache() { precache_sound("cod4/levelup.wav"); precache_sound("cod4/start.wav"); }
public eDeath() { new attacker = read_data(1); new victim = read_data(2); new headshot = read_data(3); 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 set_hudmessage(255, 255, 0, -1.0, -0.57) show_hudmessage(attacker, "+%d", gXPKill) } else if( headshot && victim != attacker ) { gXP[attacker] += gXPHs set_hudmessage(255, 255, 0, -1.0, -0.57) show_hudmessage(attacker, "+%d", gXPHs) } CheckLevel(attacker) SaveData(attacker) return PLUGIN_CONTINUE }
public CheckLevel(id) { if( gXP[id] >= RANK[gLevel[id]] ) { client_cmd(id, "spk cod4/levelup.wav") ColorChat(id, GREEN, "^x04[COD:MW2]^x01 Congratulations! You have been promoted to:^x04 %s^x01.", RANKNAMES[gLevel[id]+1]); gLevel[id]++; } // Commander is Rank 54 if( gLevel[id] == 55 ) gLevel[id] = 0 }
public on_round(id) { client_cmd(id, "spk cod4/start.wav") 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 | XP: %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 key[32], data[101]; get_user_authid(id, key, 31); format(data, 100, "%d %d", gXP[id], gLevel[id]); nvault_set(g_vault, key, data); }
public LoadData(id) { new key[32], data[101]; get_user_authid(id, key, 31); nvault_get(g_vault, key, data, 100);
new szXP[32], szLevel[32]; parse(data, szXP, 31, szLevel, 31); gXP[id] = str_to_num(szXP); gLevel[id] = str_to_num(szLevel); }
public plugin_end() { nvault_close(g_vault); }
public ChooseClass(id) { new menu[] = "\rCall Of Duty 4 Class Menu^n \yChoose Class^n\w^n1. Grenadier [Assualt]^n2. First Recon [Sub Machine Gun]^n3. Overwatch [Shotgun]^n4. Scout Sniper^n5. Riot Squad^n^n6. Custom Class 1"; new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|MENU_KEY_4|MENU_KEY_5|MENU_KEY_6; show_menu(id, keys, menu, -1, "menu_ChooseClass") }
public DoChooseClass(id, key) { key+= 1 if(PlayerClass[id] == key) { client_print(id, print_chat, "^x04[COD:MW2]^x01 You are already a ^x04%s!^x01 Choose something else!",CLASSES[key]) ChooseClass(id) return PLUGIN_CONTINUE }
PlayerTClass[id] = key ColorChat(id, GREEN, "^x04[COD:MW2]^x01 Changes will take place after you die.") ShowHud(id) return PLUGIN_CONTINUE
}
public ResetHud(id) { PlayerClass[id] = PlayerTClass[id] if(PlayerClass[id] != CLASS_NOTHING)set_task(2.0,"Equip",id) else ChooseClass(id) }
public Equip(id) { fm_strip_user_weapons(id) fm_give_item(id, "weapon_knife") switch(PlayerClass[id]) { case 1: // grenadier { fm_give_item(id, "weapon_flashbang"); fm_give_item(id, "weapon_flashbang"); fm_give_item(id, "weapon_aug"); fm_give_item(id, "ammo_556nato"); fm_give_item(id, "ammo_556nato"); fm_give_item(id, "ammo_556nato"); fm_give_item(id, "weapon_glock18"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); ColorChat(id, GREEN, "^x04[COD:MW2]^x01 You are now ^x04Grenadier^x01") } case 2: // First Recon { fm_give_item(id, "weapon_ump45"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "weapon_glock18"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); ColorChat(id, GREEN, "^x04[COD:MW2]^x01 You are now ^x04First Recon^x01") } case 3: // Overwatch { fm_give_item(id, "weapon_hegrenade"); fm_give_item(id, "weapon_glock18"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "weapon_m3"); fm_give_item(id, "ammo_buckshot"); fm_give_item(id, "ammo_buckshot"); fm_give_item(id, "ammo_buckshot"); fm_give_item(id, "ammo_buckshot"); fm_give_item(id, "ammo_buckshot"); ColorChat(id, GREEN, "^x04[COD:MW2]^x01 You are now ^x04Overwatch^x01") } case 4: // Scout Sniper { fm_give_item(id, "weapon_hegrenade"); fm_give_item(id, "weapon_flashbang"); fm_give_item(id, "weapon_flashbang"); fm_give_item(id, "weapon_scout"); fm_give_item(id, "ammo_762nato"); fm_give_item(id, "weapon_deagle"); fm_give_item(id, "ammo_50ae"); fm_give_item(id, "ammo_50ae"); fm_give_item(id, "ammo_50ae"); fm_give_item(id, "ammo_50ae"); fm_give_item(id, "ammo_50ae"); ColorChat(id, GREEN, "^x04[COD:MW2]^x01 You are now ^x04Scout Snipist^x01") } case 5: // Riot Control { fm_give_item(id, "weapon_hegrenade"); fm_give_item(id, "weapon_flashbang"); fm_give_item(id, "weapon_flashbang"); fm_give_item(id, "weapon_knife"); fm_give_item(id, "weapon_shield"); fm_give_item(id, "weapon_deagle"); fm_give_item(id, "ammo_50ae"); fm_give_item(id, "ammo_50ae"); fm_give_item(id, "ammo_50ae"); fm_give_item(id, "ammo_50ae"); fm_give_item(id, "ammo_50ae"); fm_give_item(id, "weapon_glock18"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "ammo_9mm"); fm_give_item(id, "weapon_usp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); fm_give_item(id, "ammo_45acp"); ColorChat(id, GREEN, "^x04[COD:MW2]^x01 You are now ^x04Riot Controller^x01") } case 6: { if( gLevel[id] == 6 ) fm_give_item(id, "weapon_ak47") ColorChat(id, GREEN, "^x04[COD:MW2]^x01 Test MANG") } } }
//////////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); } stock fm_give_item(index, const item[]) { if (!equal(item, "weapon_", 7) && !equal(item, "ammo_", 5) && !equal(item, "item_", 5) && !equal(item, "tf_weapon_", 10)) return 0
new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, item)) if (!pev_valid(ent)) return 0
new Float:origin[3] pev(index, pev_origin, origin) set_pev(ent, pev_origin, origin) set_pev(ent, pev_spawnflags, pev(ent, pev_spawnflags) | SF_NORESPAWN) dllfunc(DLLFunc_Spawn, ent)
new save = pev(ent, pev_solid) dllfunc(DLLFunc_Touch, ent, index) if (pev(ent, pev_solid) != save) return ent
engfunc(EngFunc_RemoveEntity, ent)
return -1 } stock fm_strip_user_weapons(index) { new ent = engfunc(EngFunc_CreateNamedEntity, engfunc(EngFunc_AllocString, "player_weaponstrip")) if (!pev_valid(ent)) return 0
dllfunc(DLLFunc_Spawn, ent) dllfunc(DLLFunc_Use, ent, index) engfunc(EngFunc_RemoveEntity, ent)
return 1 } //stocks by XxAvalanchexX stock fm_set_user_money(id,money,flash=1) { set_pdata_int(id,OFFSET_CSMONEY,money,OFFSET_LINUX); message_begin(MSG_ONE,get_user_msgid("Money"),{0,0,0},id); write_long(money); write_byte(flash); message_end(); }
stock fm_get_user_money(id) { return get_pdata_int(id,OFFSET_CSMONEY,OFFSET_LINUX); } public ColorChat(id, Color:type, const msg[], {Float,Sql,Result,_}:...) { static SayText;
if(!SayText) SayText = get_user_msgid("SayText");
static message[256];
switch(type) { case GREEN: // Green { message[0] = 0x04; } case TEAM_COLOR: // Team Color. Ie. Red (Terrorist) or blue (Counter-Terrorist). { message[0] = 0x03; } // Will allow it to work propertly even though they might of send an invalid Color Type. // Will default to Yellow if it is. default: // Yellow. {
message[0] = 0x01; } }
vformat(message[1], 251, msg, 4);
// Make sure message is not longer than 192 character. Will crash the server. message[192] = '^0';
if(id) { if(is_user_connected(id)) { message_begin(MSG_ONE, SayText, {0, 0, 0}, id); write_byte(id); write_string(message); message_end(); } } else { static players[32]; new count, index; get_players(players, count);
for(new i = 0; i < count; i++) { index = players[i];
message_begin(MSG_ONE, SayText, {0, 0, 0}, index); write_byte(index); write_string(message); message_end();
} } }
|