Quote:
Originally Posted by fysiks
The thing that stands out to me about this is that you have code execution for all every cell in perks_id[] (because the if statements are opposite so one or the other code blocks will get executed) but you're being inefficient about it by using two loops.
You can do this in a single loop by just looping through all cells of the array and just using an if-then-else to determine which code you execute on each iteration.
P.S. While I understand that it's only part of your debugging, it's probably a good thing to point out so that you get better at seeing your coding mistakes in general: your log_amx() functions in your second loop should be throwing errors because you pass two arguments but the format string only has one.
|
PHP Code:
new damage_better_items = random_num(3, 12);
new damage_items = random_num(1, 6);
new perks_id[] = { 1, 2, 3, 4, 7, 13 };
for( new i; i < sizeof(perks_id); i++ ) {
if( cod_get_user_perk(vid) == perks_id[i] ) {
log_amx("Better Durability: %i | PerkID %i", durability_perks[vid], perks_id[i]);
durability_perks[vid] -= (durability_perks[vid] > damage_better_items)? damage_better_items: durability_perks[vid];
log_amx("Better Durability: %i | PerkID %i", durability_perks[vid], perks_id[i]);
return PLUGIN_CONTINUE;
} else {
log_amx("Durability: %i", durability_perks[vid], perks_id[i]);
durability_perks[vid] -= (durability_perks[vid] > damage_items)? damage_items: durability_perks[vid];
log_amx("Durability: %i", durability_perks[vid], perks_id[i]);
return PLUGIN_CONTINUE;
}
}
By doing it this way, only the content after the else is executed.