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

Solved Invalid index 0 (count 0) help me fix it


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-18-2020 , 13:21   Invalid index 0 (count 0) help me fix it
Reply With Quote #1

I am getting invalid index 0 (count 0) in this part of code --
Code:
new i
for ( i = 0; i < sizeof g_cHumanModels; i++ )
    {
          ArraySetString(model_human, i, g_cHumanModels[i])
    }
This loop is inside plugin_precache() and model_human = ArrayCreate( 32, sizeof g_cHumanModels )

This is g_cHumanModels part -
Code:
new const g_cHumanModels[][] =
{
    "model_one",
    "model_two",
    "model_three",
    "model_four"
}
Whats my mistake and how to fix it ?

Last edited by Abhinash; 11-20-2020 at 09:50. Reason: corrected codes
Abhinash is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 11-18-2020 , 13:40   Re: Invalid index 0 (count 0) help me fix it
Reply With Quote #2

PHP Code:
new const g_cHumanModels[][] =
{
    
"model_one"
    "model_two"
    "model_three"
    "model_four"

__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-18-2020 , 14:06   Re: Invalid index 0 (count 0) help me fix it
Reply With Quote #3

I tried the correct way like this but still error stays --
Code:
new const g_cHumanModels[][] =
{
    "model_one",
    "model_two",
    "model_three",
    "model_four"
}
Anyone knows how to fix it ?

Last edited by Abhinash; 11-18-2020 at 14:13.
Abhinash is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 11-18-2020 , 14:34   Re: Invalid index 0 (count 0) help me fix it
Reply With Quote #4

Use ArrayPushString, not SetString. Or use ArrayResize to allocate space before calling ArraySetString.
__________________
HamletEagle is offline
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-18-2020 , 14:49   Re: Invalid index 0 (count 0) help me fix it
Reply With Quote #5

Quote:
Originally Posted by HamletEagle View Post
Use ArrayPushString, not SetString. Or use ArrayResize to allocate space before calling ArraySetString.
1. ArrayPushString does work, but not properly. The problem with ArrayPushString is that when changing model of more than one player it changes model for only one player and the others are replaced with default cs player models.

2. How to allocate space ?

EDIT: Tried with ArrayPushArray but the result is same as with ArrayPushString

Last edited by Abhinash; 11-18-2020 at 15:03.
Abhinash is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 11-18-2020 , 17:38   Re: Invalid index 0 (count 0) help me fix it
Reply With Quote #6

Show the full code don't expect us to guess what inside.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !


Last edited by Natsheh; 11-18-2020 at 17:38.
Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-18-2020 , 20:02   Re: Invalid index 0 (count 0) help me fix it
Reply With Quote #7

Quote:
Originally Posted by Natsheh View Post
Show the full code don't expect us to guess what inside.
Please see my first post, I posted every codes there.
This is the rest part, I am getting Invalid index 0 (Count 0) here also --

Code:
// Custom models stuff
	static currentmodel[32], tempmodel[32], already_has_model, i, iRand, size
	already_has_model = false
	
	// Get current model for comparing it with the current one
	fm_cs_get_user_model(id, currentmodel, charsmax(currentmodel))
	
	// Set the right model, after checking that we don't already have it
	if (get_user_flags( id ) & read_flags( "a" ) )
	{
		size = ArraySize(model_admin_human)
		for (i = 0; i < size; i++)
		{
			ArrayGetString(model_admin_human, i, tempmodel, charsmax(tempmodel))
			if (equal(currentmodel, tempmodel)) already_has_model = true
		}
		
		if (!already_has_model)
		{
			iRand = random_num(0, size - 1)
			ArrayGetString(model_admin_human, iRand, g_playermodel[id], charsmax(g_playermodel[]))
			if (g_set_modelindex_offset) fm_cs_set_user_model_index(id, ArrayGetCell(g_modelindex_admin_human, iRand))
		}
	}
	else
	{
		size = ArraySize(model_human)
		for (i = 0; i < size; i++)
		{
			ArrayGetString(model_human, i, tempmodel, charsmax(tempmodel))
			if (equal(currentmodel, tempmodel)) already_has_model = true
		}
		
		if (!already_has_model)
		{
			iRand = random_num(0, size - 1)
			ArrayGetString(model_human, iRand, g_playermodel[id], charsmax(g_playermodel[]))
			if (g_set_modelindex_offset) fm_cs_set_user_model_index(id, ArrayGetCell(g_modelindex_human, iRand))
		}
	}
	
	// Need to change the model?
	if (!already_has_model)
	{
		// An additional delay is offset at round start
		// since SVC_BAD is more likely to be triggered there
		if (g_newround)
		set_task(5.0 * g_modelchange_delay, "fm_user_model_update", id+TASK_MODEL)
		else
		fm_user_model_update(id+TASK_MODEL)
	}
Abhinash is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 11-18-2020 , 20:18   Re: Invalid index 0 (count 0) help me fix it
Reply With Quote #8

Quote:
Originally Posted by Abhinash View Post
1. ArrayPushString does work, but not properly. The problem with ArrayPushString is that when changing model of more than one player it changes model for only one player and the others are replaced with default cs player models.

2. How to allocate space ?

EDIT: Tried with ArrayPushArray but the result is same as with ArrayPushString
It's probably because you're not properly retrieving/storing your info. Show us what u tried with ArrayPushString
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Abhinash
Senior Member
Join Date: Jan 2015
Location: India,kolkata
Old 11-19-2020 , 06:35   Re: Invalid index 0 (count 0) help me fix it
Reply With Quote #9

Quote:
Originally Posted by Napoleon_be View Post
It's probably because you're not properly retrieving/storing your info. Show us what u tried with ArrayPushString
This is how I am doing with ArrayPushString --
Code:
new i
for ( i = 0; i < sizeof g_cHumanModels; i++ )
    {
          ArrayPushString(model_human, i, g_cHumanModels[i])
    }
And this is the retrieval part -
Code:
// Custom models stuff
	static currentmodel[32], tempmodel[32], already_has_model, i, iRand, size
	already_has_model = false
	
	// Get current model for comparing it with the current one
	fm_cs_get_user_model(id, currentmodel, charsmax(currentmodel))
	
	// Set the right model, after checking that we don't already have it
	if (get_user_flags( id ) & read_flags( "a" ) )
	{
		size = ArraySize(model_admin_human)
		for (i = 0; i < size; i++)
		{
			ArrayGetString(model_admin_human, i, tempmodel, charsmax(tempmodel))
			if (equal(currentmodel, tempmodel)) already_has_model = true
		}
		
		if (!already_has_model)
		{
			iRand = random_num(0, size - 1)
			ArrayGetString(model_admin_human, iRand, g_playermodel[id], charsmax(g_playermodel[]))
			if (g_set_modelindex_offset) fm_cs_set_user_model_index(id, ArrayGetCell(g_modelindex_admin_human, iRand))
		}
	}
	else
	{
		size = ArraySize(model_human)
		for (i = 0; i < size; i++)
		{
			ArrayGetString(model_human, i, tempmodel, charsmax(tempmodel))
			if (equal(currentmodel, tempmodel)) already_has_model = true
		}
		
		if (!already_has_model)
		{
			iRand = random_num(0, size - 1)
			ArrayGetString(model_human, iRand, g_playermodel[id], charsmax(g_playermodel[]))
			if (g_set_modelindex_offset) fm_cs_set_user_model_index(id, ArrayGetCell(g_modelindex_human, iRand))
		}
	}
	
	// Need to change the model?
	if (!already_has_model)
	{
		// An additional delay is offset at round start
		// since SVC_BAD is more likely to be triggered there
		if (g_newround)
		set_task(5.0 * g_modelchange_delay, "fm_user_model_update", id+TASK_MODEL)
		else
		fm_user_model_update(id+TASK_MODEL)
	}

Last edited by Abhinash; 11-19-2020 at 06:38.
Abhinash is offline
Reply


Thread Tools
Display Modes

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 20:14.


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