Raised This Month: $ Target: $400
 0% 

array must be indexed ?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bobs
Member
Join Date: Oct 2011
Old 08-28-2013 , 11:05   array must be indexed ?
Reply With Quote #1

"array must be indexed <variable "iRank">

can some1 fix it fast:
PHP Code:
for(i=1;i<=maxPlayers;i++)
    {
        
sort[count][0] = i;
        
sort[count][1] = iKills[i];
        
sort[count][2] = RANKS[iRank][i]; //this line i got problems and cant solve, searched and nothing helped me
        
count++;
    } 

Last edited by Bobs; 08-28-2013 at 11:06.
Bobs is offline
akcaliberg
Senior Member
Join Date: Nov 2011
Location: Istanbul
Old 08-28-2013 , 11:10   Re: array must be indexed ?
Reply With Quote #2

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

Last edited by akcaliberg; 08-28-2013 at 11:17.
akcaliberg is offline
Bobs
Member
Join Date: Oct 2011
Old 08-28-2013 , 12:09   Re: array must be indexed ?
Reply With Quote #3

Quote:
Originally Posted by akcaliberg View Post
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_killscvar_hskills
new cached_killscached_hskills
new g_vaultg_status_sync
new iKills[33], iRank[33]
new 
iKilled[33][33]

public 
plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
    
    
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], iNumiPlayer
    get_players
(iPlayersiNum)
    
    for(new 
0iNumi++)
    {
        
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(pidname31)
        
        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(color150color2, -1.00.6010.013.00.010.01, -1)
            
ShowSyncHudMsg(idg_status_sync"Name: %s^nHealth: %d^nRank: %s^nKills: %d"nameget_user_health(pid), RANKS[iRank[pid]], iKills[pid])
        }
        else
        {
            
set_hudmessage(color150color2, -1.00.6010.013.00.010.01, -1)
            
ShowSyncHudMsg(idg_status_sync"Name: %s^nRank: %s^nKills: %d"nameRANKS[iRank[pid]], iKills[pid])
        }
    }
}

public 
hideStatus(id)
{
    
ClearSyncHud(idg_status_sync)
}

public 
ShowPrint(id)
{
    if(!
is_user_connected(id) && !is_user_alive(id))
    {
        return 
0
    
}
        
    
client_print(idprint_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(idszNamecharsmax(szName))
        
        
ColorChat(0GREEN"^x04[T.D] ^x03%s's ^x01Rank: ^x04%s ^x01 | with: ^x04%d ^x01kill(s) | Next rank: ^x04%d ^x01kill(s)!"szNameRANKS[iRank[id]], iKills[id], KILLS[iRank[id] + 1] - iKills[id])
    }
}

public 
event_DeathMsg()
{
    static 
iKilleriKiller read_data(1)
    static 
iVictimiVictim read_data(2)
    static 
iIsHeadshotiIsHeadshot 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
(iKillerGREEN"^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
(iKillerGREEN"^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(iKillerszNamecharsmax(szName))
        
        
ColorChat(0GREEN"^x04[T.D] ^x03%s ^x01has Promoted to: ^x04%s^x01!"szNameRANKS[iRank[iKiller]])
    }
    
SaveData(iKiller)
    
set_task(PRINT_INTERVAL"ShowPrint"iKiller)
    
    return 
PLUGIN_CONTINUE
}

public 
SaveData(id)
{
    new 
authid[32]
    
get_user_authid(idauthid31)

    new 
vaultkey[64], vaultdata[64
  
    
format(vaultkey63"mr-%s-rank"authid)
    
format(vaultdata63"%d"iRank[id])
    
set_vaultdata(vaultkeyvaultdata)

    
format(vaultkey63"mr-%s-kills"authid)
    
format(vaultdata63"%d"iKills[id])
    
set_vaultdata(vaultkeyvaultdata)
}

public 
LoadData(id)
{
    new 
authid[32]
    
get_user_authid(idauthid31)

    new 
vaultkey[64], vaultdata[64]

    
format(vaultkey63"mr-%s-rank"authid)
    
get_vaultdata(vaultkeyvaultdata63)
    
iRank[id] = str_to_num(vaultdata)

    
format(vaultkey63"mr-%s-kills"authid)
    
get_vaultdata(vaultkeyvaultdata63)
    
iKills[id] = str_to_num(vaultdata)
}

public 
Cmd_Top15(id)
{
    new 
icount;
    static 
sort[33][3], maxPlayers;
    
    if(!
maxPlayersmaxPlayers 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(sortcount"stats_custom_compare");
    
    new 
motd[1024], len    
    
    len 
format(motd1023,"<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 
015a++)
    {
        
get_user_name(sort[a][0], name31)        
        
len += format(motd[len], 1023-len,"%2d %-22.22s %6d %10s^n"1namesort[a][1], RANKS[iRank[id]])
    }
    
    
len += format(motd[len], 1023-len,"</body></font></pre>")
    
show_motd(idmotd"*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;


Last edited by Bobs; 08-28-2013 at 12:10.
Bobs is offline
Kz1.0
Senior Member
Join Date: Jan 2013
Location: Vietnam
Old 08-28-2013 , 12:52   Re: array must be indexed ?
Reply With Quote #4

sort[count][2] = RANKS[iRank][i]
->

PHP Code:
sort[count][2] = RANKS[iRank[i]] 
?
Kz1.0 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-28-2013 , 12:58   Re: array must be indexed ?
Reply With Quote #5

Quote:
Originally Posted by Kz1.0 View Post
sort[count][2] = RANKS[iRank][i]
->

PHP Code:
sort[count][2] = RANKS[iRank[i]] 
?
That's what I thought first as well.

But after looking twice I changed my mind. I think it should be like this:
Code:
sort[count][2] = iRank[i]
because RANKS[] is a string.

EDIT: Since the second index is never used I guess it doesn't matter.
__________________

Last edited by Black Rose; 08-28-2013 at 13:09.
Black Rose is offline
Bobs
Member
Join Date: Oct 2011
Old 08-28-2013 , 15:57   Re: array must be indexed ?
Reply With Quote #6

Quote:
Originally Posted by Black Rose View Post
That's what I thought first as well.

But after looking twice I changed my mind. I think it should be like this:
Code:
sort[count][2] = iRank[i]
because RANKS[] is a string.

EDIT: Since the second index is never used I guess it doesn't matter.
yes it is iRank, but i want RANKS with it, else it only shows numbers, and i want it to be text, like:
Rank:
[13/18] Pro guy (with RANKS[iRank][i]) - but it dont allow me do RANKS[iRank][i]
and
13 (with iRank[i])
Bobs is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 08-29-2013 , 13:31   Re: array must be indexed ?
Reply With Quote #7

Code:
public Cmd_Top15(id) {     new sort[32], count;         get_players(sort, count, "c");     SortCustom1D(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,"# Nick Kills Rank^n")         static name[32]     for(new a = 0; a < 15; a++)     {         get_user_name(sort[a], name, 31)         len += format(motd[len], 1023-len,"%d %s %d %s^n", a + 1, name, iKills[sort[a]], RANKS[iRank[sort[a]]])     }         len += format(motd[len], 1023-len,"</body></font></pre>")     show_motd(id, motd, "*Top15*")         return PLUGIN_CONTINUE; } public stats_custom_compare(elem1,elem2) {     if(iKills[elem1] > iKills[elem2]) return -1;     else if(iKills[elem1] < iKills[elem2]) return 1;         return 0; }
__________________

Last edited by Black Rose; 08-29-2013 at 13:31.
Black Rose is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 18:56.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode