Your example doesn't delete the position 2, it deletes whatever position contains the value 2.
If you're going to post an example instead of your actual code, make sure that the example can produce the error.
I'm gonna guess that your actual loop doesn't contain break. Because then you will get that error unless you account for the removed entries.
Code:
/**
* Deletes an item from the array. All items beyond it get shifted down 1 space.
*
* @param which The array that contains the item to delete.
* @param item The item to delete.
*/
native ArrayDeleteItem(Array:which, item);
Code:
#include <amxmodx>
public plugin_init() {
register_plugin("Test Plugin 6", "", "");
new Array:hArray = ArrayCreate(1,1);
for ( new i = 1 ; i <= 5 ; i++ )
ArrayPushCell(hArray, i);
new size = ArraySize(hArray);
for ( new i = 0 ; i < size ; i++ )
server_print("PRE: %d: %d", i, ArrayGetCell(hArray, i));
new deleted_items;
for ( new i = 0 ; i < size ; i++ ) {
server_print("Reading cell %d with value of %d", i - deleted_items, ArrayGetCell(hArray, i - deleted_items));
if ( ArrayGetCell(hArray, i - deleted_items) == 3 )
ArrayDeleteItem(hArray, i - deleted_items++);
}
size = ArraySize(hArray);
for ( new i = 0 ; i < size ; i++ )
server_print("POST: %d: %d", i, ArrayGetCell(hArray, i));
}
Code:
PRE: 0: 1
PRE: 1: 2
PRE: 2: 3
PRE: 3: 4
PRE: 4: 5
Reading cell 0 with value of 1
Reading cell 1 with value of 2
Reading cell 2 with value of 3
Reading cell 2 with value of 4
Reading cell 3 with value of 5
POST: 0: 1
POST: 1: 2
POST: 2: 4
POST: 3: 5
__________________