Author Topic: Exploding Barrels System  (Read 368 times)

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Exploding Barrels System
« Reply #15 on: August 15, 2013, 02:28:44 am »


               Sorry, I got sidetracked chatting. Here's a test mod with it working:
Barrels Go Boom

Here's the cleaned up script, though I suggest you just yank the one from the mod if the forum eats the indents:


void ExplodeAtLocation(location lTarget) {
    int nDamage;
    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)) {

        nDamage = GetReflexAdjustedDamage(d20(6), 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.");
    }
}


I would probably have written it a bit differently (I just cleaned up your version), but it works as expected.

Funky
               
               

               
            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Exploding Barrels System
« Reply #16 on: August 15, 2013, 01:02:41 pm »


               Hey thanks, this script is just what I wanted. '<img'> The module one is very complicated, and I just want a simple exploding barrel you can lug around and so. Of course, I'd like to ask if it's possible for me to add an if sentence somewhere to check if the PC has this barrel in his/her inventory, and if so and caught in that sphere, the PC would also explode = death and losing the barrels. Where would this sentence go to ? To the explosion script or to the main script ?
               
               

               
            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Exploding Barrels System
« Reply #17 on: August 15, 2013, 05:27:05 pm »


               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
               
               

               
            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Exploding Barrels System
« Reply #18 on: August 15, 2013, 08:35:33 pm »


               You forgot to assign PC as object, but it's okay. The problem still is that the barrels won't get destroyed from your inventory, strangely enough. I'm sure the tag of the item is correct.

Otherwise it works, it does assign damage and blow you up (needed to apply fireball visual to the item holding PC too but yeah. Thanks alot for helping me here '<img'>
               
               

               


                     Modifié par JerrodAmolyan, 15 août 2013 - 07:36 .
                     
                  


            

Legacy_FunkySwerve

  • Hero Member
  • *****
  • Posts: 2325
  • Karma: +0/-0
Exploding Barrels System
« Reply #19 on: August 15, 2013, 10:49:06 pm »


               

JerrodAmolyan wrote...

You forgot to assign PC as object, but it's okay. The problem still is that the barrels won't get destroyed from your inventory, strangely enough. I'm sure the tag of the item is correct.


No, it's not okay. That's WHY the barrels aren't being taken. '<img'>

Change that line's oPC to oObject, like this:

nCount = DeleteCountItem(oObject, "TAGOFYOURITEM");
Funky
               
               

               
            

Legacy_JerrodAmolyan

  • Full Member
  • ***
  • Posts: 175
  • Karma: +0/-0
Exploding Barrels System
« Reply #20 on: August 19, 2013, 08:49:06 am »


               AAAAH. Damn, now it seems to work flawlessly '<img'> Thanks man.