AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Invalid index 0 (count 0) help me fix it (https://forums.alliedmods.net/showthread.php?t=328626)

Abhinash 11-18-2020 13:21

Invalid index 0 (count 0) help me fix it
 
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 ?

iceeedr 11-18-2020 13:40

Re: Invalid index 0 (count 0) help me fix it
 
PHP Code:

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



Abhinash 11-18-2020 14:06

Re: Invalid index 0 (count 0) help me fix it
 
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 ?

HamletEagle 11-18-2020 14:34

Re: Invalid index 0 (count 0) help me fix it
 
Use ArrayPushString, not SetString. Or use ArrayResize to allocate space before calling ArraySetString.

Abhinash 11-18-2020 14:49

Re: Invalid index 0 (count 0) help me fix it
 
Quote:

Originally Posted by HamletEagle (Post 2725424)
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

Natsheh 11-18-2020 17:38

Re: Invalid index 0 (count 0) help me fix it
 
Show the full code don't expect us to guess what inside.

Abhinash 11-18-2020 20:02

Re: Invalid index 0 (count 0) help me fix it
 
Quote:

Originally Posted by Natsheh (Post 2725453)
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)
        }


Napoleon_be 11-18-2020 20:18

Re: Invalid index 0 (count 0) help me fix it
 
Quote:

Originally Posted by Abhinash (Post 2725428)
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

Abhinash 11-19-2020 06:35

Re: Invalid index 0 (count 0) help me fix it
 
Quote:

Originally Posted by Napoleon_be (Post 2725473)
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)
        }



All times are GMT -4. The time now is 13:41.

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