Author Topic: Help with OnDeath script  (Read 450 times)

Legacy_Karvon

  • Sr. Member
  • ****
  • Posts: 430
  • Karma: +0/-0
Help with OnDeath script
« on: June 10, 2011, 04:15:47 am »


               I'm not much of a scriptor, relying on Lilac's for what customization I want to do in mods.  I made a script which I want to fire on the destruction of an object, as players often simply smashes things open.  Essentially, I want to fire off a couple of visual effects on the spot of the destroyed item - marked by an underlying placeable - and then spawn in a guardian at a nearby waypoint.  This is Lilac came up with, but it's not working at all '<img'>

Any words of wisdom or advice would be appreciated.

Regards

Karvon
===================================================================================

/*   Script generated by
Lilac Soul's NWN Script Generator, v. 2.3

For download info, please visit:
http://nwvault.ign.c...=4683&id=625    */

//Put this script OnDeath
#include "nw_i0_generic"
void main()
{

object oPC = GetLastKiller();

while (GetIsObjectValid(GetMaster(oPC)))
   {
   oPC=GetMaster(oPC);
   }

if (!GetIsPC(oPC)) return;

int DoOnce = GetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF));

if (DoOnce==TRUE) return;

SetLocalInt(OBJECT_SELF, GetTag(OBJECT_SELF), TRUE);

object oTarget;
oTarget = GetObjectByTag("FloorDesignsStyle1");

//Visual effects can't be applied to waypoints, so if it is a WP
//the VFX will be applied to the WP's location instead

int nInt;
nInt = GetObjectType(oTarget);

if (nInt != OBJECT_TYPE_WAYPOINT) ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SCREEN_SHAKE), oTarget);
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SCREEN_SHAKE), GetLocation(oTarget));

//Visual effects can't be applied to waypoints, so if it is a WP
//the VFX will be applied to the WP's location instead

nInt = GetObjectType(oTarget);

if (nInt != OBJECT_TYPE_WAYPOINT) ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_PULSE_NEGATIVE), oTarget);
else ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_PULSE_NEGATIVE), GetLocation(oTarget));

object oSpawn;
location lTarget;
oTarget = GetWaypointByTag("ahmoses");

lTarget = GetLocation(oTarget);

oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "ahmoses", lTarget);

oTarget = oSpawn;

SetIsTemporaryEnemy(oPC, oTarget);

AssignCommand(oTarget, ActionAttack(oPC));

AssignCommand(oTarget, DetermineCombatRound(oPC));

//Visual effects can't be applied to waypoints, so if it is a WP
//the VFX will be applied to the WP's location instead

nInt = GetObjectType(oTarget);

if (nInt != OBJECT_TYPE_WAYPOINT) DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_EPIC_UNDEAD), oTarget));
else DelayCommand(0.5, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_FNF_SUMMON_EPIC_UNDEAD), GetLocation(oTarget)));

}
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help with OnDeath script
« Reply #1 on: June 10, 2011, 05:09:20 am »


               What is "FloorDesignsStyle1"  a Tag to.   If it is a placeable is it static?

What is "ahmoses"  Is it both a Tag and a resref?  If so do you have only one waypoint with it as a tag in the module?
               
               

               
            

Legacy_Karvon

  • Sr. Member
  • ****
  • Posts: 430
  • Karma: +0/-0
Help with OnDeath script
« Reply #2 on: June 10, 2011, 05:55:23 am »


               

Lightfoot8 wrote...

What is "FloorDesignsStyle1"  a Tag to.   If it is a placeable is it static?

What is "ahmoses"  Is it both a Tag and a resref?  If so do you have only one waypoint with it as a tag in the module?


FloorDesignStyle1 is a tag to a placeable which is static.  I originally tried to chose the object being destroyed as the target in Lilac for the effect center target, but that didn't work, so I switched to floor design as that was unaffected by destruction damage, being static.  I suppose I could try making a waypoint for the target if there's a prob using a static placeable as such.

ahmoses is a being used as the resref for the creature and the tag for the waypoint where it's supposed to be spawned.  It's the only waypoint so named in the module.  I suppose I could change the waypoint name to insure there's no chance of confusion between the two.

Thanks

Karvon
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Help with OnDeath script
« Reply #3 on: June 10, 2011, 06:37:22 am »


               Ok I did not have time to test this so I hope it works right. 

I did change the name of your waypoint to "wp_ahmoses" just to make sure it does not grab the wrong thing.


//Put this script OnDeath
#include "nw_i0_generic"
void main()
{
object oPC = GetLastKiller();
object oTarget;
object oArea = GetArea(OBJECT_SELF);
location lLocSelf= GetLocation(OBJECT_SELF);
while (GetIsObjectValid(GetMaster(oPC))) oPC=GetMaster(oPC);
if (!GetIsPC(oPC)) return;
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_FNF_SCREEN_SHAKE), lLocSelf,1.0);
 
// needs a non static object to apply this to.
//ApplyEffectToObject(DURATION_TYPE_INSTANT, EffectVisualEffect(VFX_IMP_PULSE_NEGATIVE), oTarget);
 
location lSpawn = GetLocation(GetNearestObjectByTag("wp_ahmoses"));
object oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "ahmoses", lSpawn);
 
SetIsTemporaryEnemy(oPC, oSpawn);
AssignCommand(oSpawn, ActionAttack(oPC));
AssignCommand(oSpawn, DetermineCombatRound(oPC));
ApplyEffectToObject(DURATION_TYPE_TEMPORARY, EffectVisualEffect(VFX_FNF_SUMMON_EPIC_UNDEAD), oSpawn);

}
               
               

               
            

Legacy_Melkior_King

  • Full Member
  • ***
  • Posts: 234
  • Karma: +0/-0
Help with OnDeath script
« Reply #4 on: June 11, 2011, 08:42:06 am »


               I have discovered that some of the visual effects do not show up when they are applied to a placeable object.

I haven't tested to find out why this is happening or exactly which effects fail.

I just find the location of the placeable and then use ApplyEffectAtLocation instead.