AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Zombie Plague 4.3 fix5a issue (https://forums.alliedmods.net/showthread.php?t=335779)

scoty 01-03-2022 14:58

Zombie Plague 4.3 fix5a issue
 
server crash when i check the logs i get this

L 01/03/2022 - 20:51:13: Invalid index 0 (count: 0)
L 01/03/2022 - 20:51:13: [AMXX] Displaying debug trace (plugin "zombie_plague.amxx", version "4.3 Fix5a")
L 01/03/2022 - 20:51:13: [AMXX] Run time error 10: native error (native "ArrayGetString")
L 01/03/2022 - 20:51:13: [AMXX] [0] zombie_plague.sma::ambience_sound_effects (line 7864)

Natsheh 01-04-2022 05:50

Re: Zombie Plague 4.3 fix5a issue
 
This has nothing to do with the server crashing but its recommended to fix the error.

scoty 01-04-2022 10:12

Re: Zombie Plague 4.3 fix5a issue
 
thank you for your response, thats why im here btw asking to fix this error

OciXCrom 01-04-2022 11:15

Re: Zombie Plague 4.3 fix5a issue
 
Maybe post the code so we can actually see what's going on?

I'm assuming the array is empty or you're trying to access it before it's created.

CrazY. 01-04-2022 11:16

Re: Zombie Plague 4.3 fix5a issue
 
You have to post some code, do not expect anyone to go into zombie plague 4.3 thread, download, and scroll through 10,000 lines to find out where that error happened.

Anyway, I will assume that ambience_sound_effects is like this

Code:

// Ambience Sound Effects Task
public ambience_sound_effects(taskid)
{
        // Play a random sound depending on the round
        static sound[64], iRand, duration
       
        if (g_nemround) // Nemesis Mode
        {
                iRand = random_num(0, ArraySize(sound_ambience2) - 1)
                ArrayGetString(sound_ambience2, iRand, sound, charsmax(sound))
                duration = ArrayGetCell(sound_ambience2_duration, iRand)
        }
        else if (g_survround) // Survivor Mode
        {
                iRand = random_num(0, ArraySize(sound_ambience3) - 1)
                ArrayGetString(sound_ambience3, iRand, sound, charsmax(sound))
                duration = ArrayGetCell(sound_ambience3_duration, iRand)
        }
        else if (g_swarmround) // Swarm Mode
        {
                iRand = random_num(0, ArraySize(sound_ambience4) - 1)
                ArrayGetString(sound_ambience4, iRand, sound, charsmax(sound))
                duration = ArrayGetCell(sound_ambience4_duration, iRand)
        }
        else if (g_plagueround) // Plague Mode
        {
                iRand = random_num(0, ArraySize(sound_ambience5) - 1)
                ArrayGetString(sound_ambience5, iRand, sound, charsmax(sound))
                duration = ArrayGetCell(sound_ambience5_duration, iRand)
        }
        else // Infection Mode
        {
                iRand = random_num(0, ArraySize(sound_ambience1) - 1)
                ArrayGetString(sound_ambience1, iRand, sound, charsmax(sound))
                duration = ArrayGetCell(sound_ambience1_duration, iRand)
        }
       
        // Play it on clients
        PlaySound(sound)
       
        // Set the task for when the sound is done playing
        set_task(float(duration), "ambience_sound_effects", TASK_AMBIENCESOUNDS)
}

You got the error because the code tried to access an array that is empty for some reason.
To fix that, check if the array has any item.

Code:
if (g_nemround) // Nemesis Mode {     new soundCount = ArraySize(sound_ambience2)     if (soundCount > 0)     {         iRand = random(soundCount)         ArrayGetString(sound_ambience2, iRand, sound, charsmax(sound))         if (0 <= iRand < ArraySize(sound_ambience2_duration))         {             duration = ArrayGetCell(sound_ambience2_duration, iRand)         }     } }

And check if any sound was selected

Code:
if (sound[0]) {     // Play it on clients     PlaySound(sound)         // Set the task for when the sound is done playing     set_task(float(duration), "ambience_sound_effects", TASK_AMBIENCESOUNDS) }

Since you're going to use this multiple times, wrap everything into one function for two reasons:
- Makes it a lot more readable and organized
- If something goes wrong, it will be easier to fix

Code:

GetRandomSoundAndDuration(Array:sounds, sound[], maxLen, Array:durations, &duration)
{
        new count = ArraySize(sounds)

        if (count == 0)
        {
                return false
        }

        new rand = random(count)

        if (!(0 <= rand < ArraySize(durations)))
        {
                return false
        }

        ArrayGetString(sounds, rand, sound, maxLen)
        duration = ArrayGetCell(durations, rand)

        return true
}

Now all of this
Code:

// Ambience Sound Effects Task
public ambience_sound_effects(taskid)
{
        // Play a random sound depending on the round
        new sound[64], iRand, duration

        if (g_nemround) // Nemesis Mode
        {
                new soundCount = ArraySize(sound_ambience2)

                if (soundCount > 0)
                {
                        iRand = random(soundCount)
                        ArrayGetString(sound_ambience2, iRand, sound, charsmax(sound))

                        if (0 <= iRand < ArraySize(sound_ambience2_duration))
                        {
                                duration = ArrayGetCell(sound_ambience2_duration, iRand)
                        }

                }
        }
        else if (g_survround) // Survivor Mode
        {
                new soundCount = ArraySize(sound_ambience3)

                if (soundCount > 0)
                {
                        iRand = random(soundCount)
                        ArrayGetString(sound_ambience3, iRand, sound, charsmax(sound))

                        if (0 <= iRand < ArraySize(sound_ambience3_duration))
                        {
                                duration = ArrayGetCell(sound_ambience3_duration, iRand)
                        }

                }
        }
        else if (g_swarmround) // Swarm Mode
        {
                new soundCount = ArraySize(sound_ambience4)

                if (soundCount > 0)
                {
                        iRand = random(soundCount)
                        ArrayGetString(sound_ambience4, iRand, sound, charsmax(sound))

                        if (0 <= iRand < ArraySize(sound_ambience4_duration))
                        {
                                duration = ArrayGetCell(sound_ambience4_duration, iRand)
                        }

                }
        }
        else if (g_plagueround) // Plague Mode
        {
                new soundCount = ArraySize(sound_ambience5)

                if (soundCount > 0)
                {
                        iRand = random(soundCount)
                        ArrayGetString(sound_ambience5, iRand, sound, charsmax(sound))

                        if (0 <= iRand < ArraySize(sound_ambience5_duration))
                        {
                                duration = ArrayGetCell(sound_ambience5_duration, iRand)
                        }

                }
        }
        else // Infection Mode
        {
                new soundCount = ArraySize(sound_ambience1)

                if (soundCount > 0)
                {
                        iRand = random(soundCount)
                        ArrayGetString(sound_ambience1, iRand, sound, charsmax(sound))

                        if (0 <= iRand < ArraySize(sound_ambience1_duration))
                        {
                                duration = ArrayGetCell(sound_ambience1_duration, iRand)
                        }

                }
        }

        if (sound[0])
        {
                // Play it on clients
                PlaySound(sound)
               
                // Set the task for when the sound is done playing
                set_task(float(duration), "ambience_sound_effects", TASK_AMBIENCESOUNDS)
        }
}

Will simply become this

Code:


// Ambience Sound Effects Task
public ambience_sound_effects(taskid)
{
        // Play a random sound depending on the round
        new sound[64], duration
       
        if (g_nemround) // Nemesis Mode
        {
                GetRandomSoundAndDuration(sound_ambience2, sound, charsmax(sound), sound_ambience2_duration, duration)
        }
        else if (g_survround) // Survivor Mode
        {
                GetRandomSoundAndDuration(sound_ambience3, sound, charsmax(sound), sound_ambience3_duration, duration)
        }
        else if (g_swarmround) // Swarm Mode
        {
                GetRandomSoundAndDuration(sound_ambience4, sound, charsmax(sound), sound_ambience4_duration, duration)
        }
        else if (g_plagueround) // Plague Mode
        {
                GetRandomSoundAndDuration(sound_ambience5, sound, charsmax(sound), sound_ambience5_duration, duration)
        }
        else // Infection Mode
        {
                GetRandomSoundAndDuration(sound_ambience1, sound, charsmax(sound), sound_ambience1_duration, duration)
        }

        // if any sound was selected
        if (sound[0])
        {
                // Play it on clients
                PlaySound(sound)
               
                // Set the task for when the sound is done playing
                set_task(float(duration), "ambience_sound_effects", TASK_AMBIENCESOUNDS)
        }
}

GetRandomSoundAndDuration(Array:sounds, sound[], maxLen, Array:durations, &duration)
{
        new count = ArraySize(sounds)

        if (count == 0)
        {
                return false
        }

        new rand = random(count)

        if (!(0 <= rand < ArraySize(durations)))
        {
                return false
        }

        ArrayGetString(sounds, rand, sound, maxLen)
        duration = ArrayGetCell(durations, rand)

        return true
}

That will fix just the log error, this isn't the cause of why your server is crashing. If it is a plugin problem, you'll have to disable all of them and keep testing one by one until you find it out.

Natsheh 01-04-2022 13:29

Re: Zombie Plague 4.3 fix5a issue
 
Whats the crash error code ?


All times are GMT -4. The time now is 11:29.

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