@Patskie
You want to use a variable with the getarraysize value as opposed to calling the function directly inside the for loop.
prontera,150,150,0 script Sample 100,{
for ( .@i = 0; .@i < .num_r; .@i += 2 ) {
if ( countitem( .r[ .@i ] ) < .r[ .@i + 1 ] ) {
mes "Lack of requirements";
close;
}
}
for ( .@i = 0; .@i < .num_r; .@i += 2 )
delitem .r[ .@i ], .r[ .@i + 1 ];
for ( .@i = 0; .@i < .num_p; .@i += 2 )
getitem .p[ .@i ], .p[ .@i + 1 ];
mes "Nice!";
close;
OnInit:
// item id, amount ( r = requirements | p = prize )
setarray .r[0],7227,5,7179,5;
setarray .p[0],1202,1,5013,1;
set .num_r, getarraysize(.r);
set .num_p, getarraysize(.p);
end;
}
The getarraysize() function quite literally goes through the array checking if each value exists till the end. To put it in a loop like that means the processing time will increase quadratically as you add items.
static int32 getarraysize(struct script_state* st, int32 id, int32 idx, int isstring, struct DBMap** ref)
{
int32 ret = idx;
if( isstring )
{
for( ; idx < SCRIPT_MAX_ARRAYSIZE; ++idx )
{
char* str = (char*)get_val2(st, reference_uid(id, idx), ref);
if( str && *str )
ret = idx + 1;
script_removetop(st, -1, 0);
}
}
else
{
for( ; idx < SCRIPT_MAX_ARRAYSIZE; ++idx )
{
int32 num = (int32)__64BPRTSIZE(get_val2(st, reference_uid(id, idx), ref));
if( num )
ret = idx + 1;
script_removetop(st, -1, 0);
}
}
return ret;
}