The test module one is identical to the one I posted. Just download it, open it in the editor, and hit F9 to test (assuming your test toon has fire damage). Otherwise, just play it - only takes a minute, and shows off the domino effect.
Where you put the line checking for a barrel in inventory depends on what behavior you want, what you expect the use by players to be, and so on. If you only care about barrels in inventory of the person who sets off the first barrel, you can avoid putting it in the explosion function. If you do care about secondary explosions setting off barrels in player inventory, however, it will have to go in the explosion function, inside the while loop.
You'd need another custom function to iterate the pc's inventory, delete all instances of the barrel while counting deleted instances, and return the number of deleted instances, to know how much damage to apply. Here's a modified script that checks inside the explosion:
int DeleteCountItem(object oPC, string sTag) {
int nCount;
object oScan = GetFirstItemInInventory(oPC);
while (GetIsObjectValid(oScan)) {
if (GetTag(oScan) == sTag) {
nCount++;
DestroyObject(oScan);
}
oScan = GetNextItemInInventory(oPC);
}
return nCount;
}
void ExplodeAtLocation(location lTarget) {
int nDamage, nCount;
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_FIREBALL), lTarget);
object oObject = GetFirstObjectInShape(SHAPE_SPHERE, 7.0, lTarget, FALSE, OBJECT_TYPE_CREATURE | OBJECT_TYPE_PLACEABLE | OBJECT_TYPE_DOOR);
while (GetIsObjectValid(oObject)) {
if (GetIsPC(oObject)) //saves us from scanning inventory of placeables and other creatures
nCount = DeleteCountItem(oPC, "TAGOFYOURITEM");
nDamage = GetReflexAdjustedDamage(d20(6*(nCount+1)), oObject, 30, SAVING_THROW_TYPE_FIRE);
if (nDamage > 0) {
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectDamage(nDamage, DAMAGE_TYPE_FIRE), oObject);
ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_FLAME_M), oObject);
}
oObject = GetNextObjectInShape(SHAPE_SPHERE, 7.0, lTarget, FALSE, OBJECT_TYPE_CREATURE | OBJECT_TYPE_PLACEABLE | OBJECT_TYPE_DOOR);
}
}
void main() {
location lSource = GetLocation(OBJECT_SELF);
object oPC = GetLastHostileActor();
object oWeapon = GetItemInSlot(INVENTORY_SLOT_RIGHTHAND,oPC);
if (GetDamageDealtByType(DAMAGE_TYPE_FIRE) > 0) {
DelayCommand(0.1, ExplodeAtLocation(lSource));
PlaySound("zep_explosion");
} else if (GetStringLeft(GetResRef(oWeapon), 4) == "gun_") {
DelayCommand(0.1, ExplodeAtLocation(lSource));
PlaySound("zep_explosion");
}
else {
SendMessageToPC(oPC, "You must use fire or a gun to detonate this barrel.");
}
}
Fair warning: I haven't compiled this, so there could be a typo.
Funky