Raised This Month: $51 Target: $400
 12% 

Array must be indexed


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
victorrr
Junior Member
Join Date: Feb 2021
Location: Austria
Old 02-11-2021 , 12:40   Array must be indexed
Reply With Quote #1

Hello, i got a problem with a plugin..

Code:
#include <amxmodx>
#include <hamsandwich>

static const
PLUGIN[] = "",
VERSION[] = "1.0",
AUTHOR[] = "scosmyn";

new count[33] = 0

public plugin_init() {
	register_plugin(PLUGIN,VERSION,AUTHOR);
	
	register_clcmd("say /revive","cmdRevive")
	
	register_logevent("round_start",2,"1=Round_Start");
}

public round_start( ) {
	static i
	for(i = 1; i <= get_maxplayers(); i++)
		count = 0
}

public cmdRevive(id) {
	if(count[id] == 3)
	{
		color(id,"!team[V.I.P REVIVE] !yAi folosit deja de 3 ori !grevive !yrunda viitoare poti accesa dinou!")
		return 1
	}
	if(is_user_alive(id))
		return 1
	
	if(!(get_user_flags(id) & ADMIN_LEVEL_H))
	{
		color(id,"!team[V.I.P REVIVE] !yNu ai acces la /revive , doar !gV.I.P-ul !yare acces!")
		return 1
	}
	
	count[id]++
	
	ExecuteHam(Ham_CS_RoundRespawn,id)
	return 0
}

stock color( const id, const input[ ], any:... )
{
	new count = 1, players[ 32 ]
	
	static msg[ 191 ]
	vformat( msg, 190, input, 3 )
	
	replace_all( msg, 190, "!g", "^4" ) //- verde
	replace_all( msg, 190, "!y", "^1" ) //- galben
	replace_all( msg, 190, "!team", "^3" ) //- echipa
	replace_all( msg, 190, "!n", "^0" ) //- normal
	
	if( id ) players[ 0 ] = id; else get_players( players, count, "ch" )
	{
	for( new i = 0; i < count; i++ )
	{
		if( is_user_connected( players[ i ] ) )
		{
			message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ), _, players[ i ] )
			write_byte( players[ i ] );
			write_string( msg );
			message_end( );
		}
	}
}
}
At line 22-23 I get the error "Array must be indexed (variable "count").
Please, can you tell me please how can i fix this?
victorrr is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-11-2021 , 12:49   Re: Array must be indexed
Reply With Quote #2

You have it defined as an array but are trying to use it like a single cell variable. You also should not define a local variable with the same name as a global variable. Always prefix global variables with g_ so you know their scope and avoid a lot of headaches.
Code:
#include <amxmodx> #include <hamsandwich> static const PLUGIN[] = "", VERSION[] = "1.0", AUTHOR[] = "scosmyn";
new count[33] = 0
public plugin_init() {     register_plugin(PLUGIN,VERSION,AUTHOR);         register_clcmd("say /revive","cmdRevive")         register_logevent("round_start",2,"1=Round_Start"); } public round_start( ) {     static i     for(i = 1; i <= get_maxplayers(); i++)
        count = 0
} public cmdRevive(id) {     if(count[id] == 3)     {         color(id,"!team[V.I.P REVIVE] !yAi folosit deja de 3 ori !grevive !yrunda viitoare poti accesa dinou!")         return 1     }     if(is_user_alive(id))         return 1         if(!(get_user_flags(id) & ADMIN_LEVEL_H))     {         color(id,"!team[V.I.P REVIVE] !yNu ai acces la /revive , doar !gV.I.P-ul !yare acces!")         return 1     }         count[id]++         ExecuteHam(Ham_CS_RoundRespawn,id)     return 0 } stock color( const id, const input[ ], any:... ) {
    new count = 1, players[ 32 ]
__________________
Bugsy is offline
victorrr
Junior Member
Join Date: Feb 2021
Location: Austria
Old 02-11-2021 , 14:43   Re: Array must be indexed
Reply With Quote #3

I put the prefix "g_" but I get more errors .. I probably don't put the prefix properly or what is the problem?
victorrr is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 02-11-2021 , 14:44   Re: Array must be indexed
Reply With Quote #4

change all
PHP Code:
count 
to
PHP Code:
count[id
lexzor is offline
victorrr
Junior Member
Join Date: Feb 2021
Location: Austria
Old 02-11-2021 , 15:00   Re: Array must be indexed
Reply With Quote #5

Quote:
Originally Posted by lexzor View Post
change all
PHP Code:
count 
to
PHP Code:
count[id

doesn't work

Last edited by victorrr; 02-11-2021 at 15:00.
victorrr is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 02-11-2021 , 15:02   Re: Array must be indexed
Reply With Quote #6

In round_start, use count[ i ] = 0, or g_count[ i ] if you renamed. There are other issues with your code but it may work.
__________________
Bugsy is offline
victorrr
Junior Member
Join Date: Feb 2021
Location: Austria
Old 02-11-2021 , 15:12   Re: Array must be indexed
Reply With Quote #7

Quote:
Originally Posted by Bugsy View Post
In round_start, use count[ i ] = 0, or g_count[ i ] if you renamed. There are other issues with your code but it may work.
Thank you Bugsy, it worked !!
victorrr is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 02-11-2021 , 15:39   Re: Array must be indexed
Reply With Quote #8

PHP Code:
#include <amxmodx>
#include <hamsandwich>

#if AMXX_VERSION_NUM < 183 // Aici definim variabila MAX_PLAYERS pentru versiunile mai vechi ale compilerului. Foloseste 1.9 sau 1.10
    #define MAX_PLAYERS 32
#endif
static const
PLUGIN[] = "",
VERSION[] = "1.0",
AUTHOR[] = "scosmyn";

new 
count[MAX_PLAYERS 1// Aici definim variabila count. Folosim MAX_PLAYERS + 1 pentru ca la orice array ultimul slot nu poate fi folosit 
                // deci daca ai o variabila count[33] tu poti folosit doar primele 32 de sloturi (de la 0 la 32)

public plugin_init() {
    
register_plugin(PLUGIN,VERSION,AUTHOR);
    
    
register_clcmd("say /revive","cmdRevive")
    
    
register_logevent("round_start",2,"1=Round_Start");
}

public 
round_start(id)  // aici punem id intre paranteze deoarece acela va fi indexul (adica playerul pe care executam functia)

    for(new 
1<= get_maxplayers(); i++)
        
count[id] = // aici definim variabila count pentru fiecare user in parte, de aceea folosim [id]
}

public 
cmdRevive(id) {
    if(
count[id] == 3// asta inseamn daca count[id] (adica variabila count pentru fiecare player in parte) este egala cu 3
     
{
        
color(id,"!team[V.I.P REVIVE] !yAi folosit deja de 3 ori !grevive !yrunda viitoare poti accesa dinou!")
        return 
1
    
}
    if(
is_user_alive(id))
        return 
1
    
    
if(!(get_user_flags(id) & ADMIN_LEVEL_H))
    {
        
color(id,"!team[V.I.P REVIVE] !yNu ai acces la /revive , doar !gV.I.P-ul !yare acces!")
        return 
1
    
}
    
    
count[id]++
    
    
ExecuteHam(Ham_CS_RoundRespawn,id)
    return 
0


Last edited by lexzor; 02-11-2021 at 15:40.
lexzor 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 17:01.


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