Re: array must be indexed ?
Quote:
Originally Posted by akcaliberg
(Post 2023348)
I think you are declaring iRank as an array
Show the declaration line of the iRank variable
Plus, there are very little information. You must show the purpose of using iRank variable. So, it would be better if you post your full code
|
PHP Code:
#include <amxmodx>
#include <fakemeta>
#include <nvault>
#include <colorchat>
new const VERSION[] = "1.0"
new const AUTHOR[] = "Bobs"
new const PLUGIN[] = "Military Rank System"
new const RANKS[][]=
{
"[0/18] Private",
"[1/18] Private 1st Class",
"[2/18] Corporal",
"[3/18] Sergeant",
"[4/18] Staff Sergeant",
"[5/18] Sergeant 1st Class",
"[6/18] Master Sergeant",
"[7/18] Sergeant Major",
"[8/18] 2nd Lieutenant",
"[9/18] 1st Lieutenant",
"[10/18] Captain",
"[11/18] Major",
"[12/18] Lieutenant Colonel",
"[13/18] Colonel",
"[14/18] Brigadier General",
"[15/18] Major General",
"[16/18] Lieutenant General",
"[17/18] General",
"[MAX] General of the Army",
""
}
new const KILLS[] =
{
0,
50,
100,
200,
300,
500,
700,
1000,
1400,
2000,
2400,
2900,
3500,
4000,
4600,
5300,
6000,
7000,
8000,
8000
}
#define PRINT_INTERVAL 1.0
new cvar_kills, cvar_hskills
new cached_kills, cached_hskills
new g_vault, g_status_sync
new iKills[33], iRank[33]
new iKilled[33][33]
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
register_clcmd("say /rank", "show_stats")
register_clcmd("say_team /rank", "show_stats")
register_clcmd("say /top15", "Cmd_Top15")
register_clcmd("say_team /top15", "Cmd_Top15")
register_clcmd("say top15", "Cmd_Top15")
register_clcmd("say_team top15", "Cmd_Top15")
cvar_kills = register_cvar("mr_rank_kills", "1")
cvar_hskills = register_cvar("mr_rank_hskills", "2")
register_event("StatusValue", "showStatus", "be", "1=2", "2!0")
register_event("StatusValue", "hideStatus", "be", "1=1", "2=0")
register_event("DeathMsg", "event_DeathMsg", "a", "1>0")
g_vault = nvault_open("vault_rank")
g_status_sync = CreateHudSyncObj()
if(g_vault == INVALID_HANDLE)
{
set_fail_state("Error")
}
}
public plugin_end()
{
new iPlayers[32], iNum, iPlayer
get_players(iPlayers, iNum)
for(new i = 0; i < iNum; i++)
{
iPlayer = iPlayers[i]
SaveData(iPlayer)
}
nvault_close(g_vault)
}
public client_putinserver(id)
{
set_task(PRINT_INTERVAL, "ShowPrint", id)
LoadData(id)
}
public client_disconnect(id)
{
SaveData(id)
}
public showStatus(id)
{
if(!is_user_bot(id) && is_user_connected(id))
{
new name[32]
new pid = read_data(2)
get_user_name(pid, name, 31)
new color1 = 0
new color2 = 0
new team1 = get_user_team(id), team2 = get_user_team(pid)
if (team2 == 1)
{
color1 = 200
}
else
{
color2 = 200
}
if(team1 == team2)
{
set_hudmessage(color1, 50, color2, -1.0, 0.60, 1, 0.01, 3.0, 0.01, 0.01, -1)
ShowSyncHudMsg(id, g_status_sync, "Name: %s^nHealth: %d^nRank: %s^nKills: %d", name, get_user_health(pid), RANKS[iRank[pid]], iKills[pid])
}
else
{
set_hudmessage(color1, 50, color2, -1.0, 0.60, 1, 0.01, 3.0, 0.01, 0.01, -1)
ShowSyncHudMsg(id, g_status_sync, "Name: %s^nRank: %s^nKills: %d", name, RANKS[iRank[pid]], iKills[pid])
}
}
}
public hideStatus(id)
{
ClearSyncHud(id, g_status_sync)
}
public ShowPrint(id)
{
if(!is_user_connected(id) && !is_user_alive(id))
{
return 0
}
client_print(id, print_center, "Rank: %s | Kills: %d / %d", RANKS[iRank[id]], iKills[id], KILLS[iRank[id] + 1])
set_task(PRINT_INTERVAL, "ShowPrint", id)
return PLUGIN_CONTINUE
}
public show_stats(id)
{
if(is_user_connected(id))
{
new szName[32]
get_user_name(id, szName, charsmax(szName))
ColorChat(0, GREEN, "^x04[T.D] ^x03%s's ^x01Rank: ^x04%s ^x01 | with: ^x04%d ^x01kill(s) | Next rank: ^x04%d ^x01kill(s)!", szName, RANKS[iRank[id]], iKills[id], KILLS[iRank[id] + 1] - iKills[id])
}
}
public event_DeathMsg()
{
static iKiller; iKiller = read_data(1)
static iVictim; iVictim = read_data(2)
static iIsHeadshot; iIsHeadshot = read_data(3)
cached_kills = get_pcvar_num(cvar_kills)
cached_hskills = get_pcvar_num(cvar_hskills)
if(iVictim == iKiller)
{
return PLUGIN_CONTINUE
}
if(iIsHeadshot)
{
iKilled[iKiller][iVictim] = true
iKills[iKiller] += cached_hskills
ColorChat(iKiller, GREEN, "^x04[T.D] ^x01You've earned ^x04%d ^x01Kill Points for killing an enemy with ^x04Headshot^x01!", get_pcvar_num(cvar_hskills))
}
else
{
iKilled[iKiller][iVictim] = true
iKills[iKiller] += cached_kills
ColorChat(iKiller, GREEN, "^x04[T.D] ^x01You've earned ^x04%d ^x01Kill Point for killing an enemy!", get_pcvar_num(cvar_kills))
}
while((iKills[iKiller] >= KILLS[iRank[iKiller] + 1] && iRank[iKiller] < 18))
{
iRank[iKiller] += 1
new szName[32]
get_user_name(iKiller, szName, charsmax(szName))
ColorChat(0, GREEN, "^x04[T.D] ^x03%s ^x01has Promoted to: ^x04%s^x01!", szName, RANKS[iRank[iKiller]])
}
SaveData(iKiller)
set_task(PRINT_INTERVAL, "ShowPrint", iKiller)
return PLUGIN_CONTINUE
}
public SaveData(id)
{
new authid[32]
get_user_authid(id, authid, 31)
new vaultkey[64], vaultdata[64]
format(vaultkey, 63, "mr-%s-rank", authid)
format(vaultdata, 63, "%d", iRank[id])
set_vaultdata(vaultkey, vaultdata)
format(vaultkey, 63, "mr-%s-kills", authid)
format(vaultdata, 63, "%d", iKills[id])
set_vaultdata(vaultkey, vaultdata)
}
public LoadData(id)
{
new authid[32]
get_user_authid(id, authid, 31)
new vaultkey[64], vaultdata[64]
format(vaultkey, 63, "mr-%s-rank", authid)
get_vaultdata(vaultkey, vaultdata, 63)
iRank[id] = str_to_num(vaultdata)
format(vaultkey, 63, "mr-%s-kills", authid)
get_vaultdata(vaultkey, vaultdata, 63)
iKills[id] = str_to_num(vaultdata)
}
public Cmd_Top15(id)
{
new i, count;
static sort[33][3], maxPlayers;
if(!maxPlayers) maxPlayers = get_maxplayers();
for(i=1;i<=maxPlayers;i++)
{
sort[count][0] = i;
sort[count][1] = iKills[i];
sort[count][2] = RANKS[iRank][i];
count++;
}
SortCustom2D(sort, count, "stats_custom_compare");
new motd[1024], len
len = format(motd, 1023,"<body bgcolor=#778899><font color=#ff0000><pre>")
len += format(motd[len], 1023-len,"%2s %-22.22s %6s %6s^n", " #", "Nick", " Kills", "Rank")
static name[32]
for(new a = 0; a < 15; a++)
{
get_user_name(sort[a][0], name, 31)
len += format(motd[len], 1023-len,"%2d %-22.22s %6d %10s^n", a + 1, name, sort[a][1], RANKS[iRank[id]])
}
len += format(motd[len], 1023-len,"</body></font></pre>")
show_motd(id, motd, "*Top15*")
return PLUGIN_CONTINUE;
}
public stats_custom_compare(elem1[],elem2[])
{
if(elem1[1] > elem2[1]) return -1;
else if(elem1[1] < elem2[1]) return 1;
return 0;
}
|