10.03.2017, 08:20
I think using one traversal and replacing the elements expect the one need to be deleted is good method as they can be used with multiple occurrence . Together with the type less nature of pawn we can accomplish it like this
The above function also deletes element if they have multiple occurrence.But one should take caution that using sizeof wont work with it use strlen instead for traversal. Because sizeof operator can only insert size of array in script on compile time.
Edit:
Seems like the above function is not valid for elements having 0 value. As EOS is defined as 0 in SAMP. So it would be good if we return the size after deletion like this:
So that we can use this returned size for further traversal.
PHP код:
Delete ( array[ ] , number )
{
new
i,
j,
size;
for( i = 0 , size = strlen ( array ) ; i < size; ++i )
{
if( array[ i ] == number )
continue;
array[ j ] = array[ i ];
j++;
}
array[ j ] = _:EOS;
return 1 ;
}
Edit:
Seems like the above function is not valid for elements having 0 value. As EOS is defined as 0 in SAMP. So it would be good if we return the size after deletion like this:
PHP код:
Delete ( array[ ] , number , size = sizeof array )
{
new
i,
j = 0;
for( i = 0 ; i< size ; ++i )
{
if( array[ i ] == number )
continue;
array[ j ] = array[ i ];
j++;
}
return j ;//returns size after deletion
}

