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.
__________________