PDA

View Full Version : [help] Check Rank


natkemon
03-16-2011, 04:53
I need help with making it check the ranks.

For example.. How do i make it check that when you are level "Commander", you recieve 10000$?


#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[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;


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", "100");
XP_Hs = register_cvar("cod_hs","200");
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]++;
}

}


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^n6. Spectate";
new keys = MENU_KEY_0|MENU_KEY_1|MENU_KEY_2|MENU_KEY_3|M ENU_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.")
if(key == 5)engclient_cmd(id, "jointeam", "6")
else fm_set_user_money(id, 0);


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")
}
}

}








//////////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();

}
}
}

schmurgel1983
03-16-2011, 05:09
sample
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] == 54 )
cs_set_user_money(id, cs_get_user_money(id) + 10000)
}if u want more levels can have recieve money use a switch query

natkemon
03-16-2011, 05:24
ok how about... lets say i reach commander and i want to make a prestige count to 1 and then reset it.. eg

Reach level commander.. prestige = 1.... resets back to private first class
Reach level commaneder again.. prestige = 2.... resets back to private first class again
Reach level commande again.. prestige =31.... resets back to private first class again

get it?