Author Topic: Need Help Modifying A Heartbeat Script  (Read 486 times)

Legacy_A Darker Shade of Soul

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« on: January 30, 2011, 12:04:02 am »


               Can someone show me how to convert this over from a heartbeat script to an on_open script please?

[nwscript]//::///////////////////////////////////////////////
//:: NW_O2_SKELETON.nss
//:: Copyright © 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
   Turns the placeable into a skeleton
   if a player comes near enough.
*/
//:://////////////////////////////////////////////
//:: Created By:   Brent
//:: Created On:   January 17, 2002
//:://////////////////////////////////////////////
void ActionCreate(string sCreature, location lLoc)
{
    CreateObject(OBJECT_TYPE_CREATURE, sCreature, lLoc);
}
void main()
{
   object oCreature = GetNearestCreature(CREATURE_TYPE_PLAYER_CHAR, PLAYER_CHAR_IS_PC);
   if (GetIsObjectValid(oCreature) == TRUE && GetDistanceToObject(oCreature) < 10.0)
   {
    effect eMind = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD);
    string sCreature = "NW_SKELWARR01";
    // * 10% chance of a skeleton chief instead
    if (Random(100) > 90)
    {
        sCreature = "NW_SKELCHIEF";
    }
    location lLoc = GetLocation(OBJECT_SELF);
    DelayCommand(0.3, ActionCreate(sCreature, lLoc));
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eMind, GetLocation(OBJECT_SELF));
    SetPlotFlag(OBJECT_SELF, FALSE);
    DestroyObject(OBJECT_SELF, 0.5);
   }
}[/nwscript]
               
               

               


                     Modifié par A Darker Shade of Soul, 30 janvier 2011 - 12:05 .
                     
                  


            

Legacy_Shadooow

  • Hero Member
  • *****
  • Posts: 7698
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #1 on: January 30, 2011, 12:25:59 am »


               

void ObjectToVoid(object o){}

void main()
{
object oPlc = OBJECT_SELF;
object oPC = GetLastOpenenedBy();
 if(!GetIsPC(oPC))
 {
 return;
 }
float fDelay = 0.0;//adjust this to delay the spawn
string sCreature = "NW_SKELWARR01";//change this to resref of whatever creature you want
effect eVFX = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD);
location lLoc = GetLocation(oPlc);

DelayCommand(fDelay, ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eVFX, lLoc));
DelayCommand(fDelay, ObjectToVoid(CreateObject(OBJECT_TYPE_CREATURE, sCreature, lLoc)));
int bDestroyMe = TRUE;//change to FALSE if you do not want to destroy playeable
 if(bDestroyMe)
 {
  DestroyObject(oPlc,fDelay+0.2);
 }
}


Again was mistaken... Now changed if you care.
               
               

               


                     Modifié par ShaDoOoW, 30 janvier 2011 - 11:14 .
                     
                  


            

Legacy_A Darker Shade of Soul

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #2 on: January 30, 2011, 02:33:44 am »


               I see this appears to be for a door? Will this still work on say a coffin? Thank you none the less though.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #3 on: January 30, 2011, 02:35:37 am »


               
void ActionCreate(string sCreature, location lLoc)

{

    CreateObject(OBJECT_TYPE_CREATURE, sCreature, lLoc);

}

void main()

{



    effect eMind = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD);

    string sCreature = "NW_SKELWARR01";

    // * 10% chance of a skeleton chief instead

    if (Random(100) > 90)

    {

        sCreature = "NW_SKELCHIEF";

    }

    location lLoc = GetLocation(OBJECT_SELF);

    DelayCommand(0.3, ActionCreate(sCreature, lLoc));

    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eMind, GetLocation(OBJECT_SELF));

    SetPlotFlag(OBJECT_SELF, FALSE);

    DestroyObject(OBJECT_SELF, 0.5);


               
               

               
            

Legacy_A Darker Shade of Soul

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #4 on: January 30, 2011, 03:11:29 am »


               Thank you as well Lightfoot.
               
               

               
            

Legacy_A Darker Shade of Soul

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #5 on: January 30, 2011, 03:59:39 am »


               

Lightfoot8 wrote...

void ActionCreate(string sCreature, location lLoc)
{
    CreateObject(OBJECT_TYPE_CREATURE, sCreature, lLoc);
}
void main()
{

    effect eMind = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD);
    string sCreature = "NW_SKELWARR01";
    // * 10% chance of a skeleton chief instead
    if (Random(100) > 90)
    {
        sCreature = "NW_SKELCHIEF";
    }
    location lLoc = GetLocation(OBJECT_SELF);
    DelayCommand(0.3, ActionCreate(sCreature, lLoc));
    ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eMind, GetLocation(OBJECT_SELF));
    SetPlotFlag(OBJECT_SELF, FALSE);
    DestroyObject(OBJECT_SELF, 0.5);


Hmmm it didn't quite work. I opened the coffin, the visual effect fired and the coffin dissapeared but it didn't spawn the creature or any creature for that matter lol...I put the tag of the creature I wanted in the string sCreature qoutation location but it didn't work. Any ideas?
               
               

               
            

Legacy_Xovian

  • Full Member
  • ***
  • Posts: 158
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #6 on: January 30, 2011, 04:10:31 am »


               Your quoted script uses a random to spawn the creature, it wont happen every time.
Play with the % numbers to get it where you want it.

If you want it to fire every time you can remove the random script entirely or modify it as such:

if (Random(100) > 90)

Change to:

if (Random(100) > 0)
               
               

               


                     Modifié par Xovian, 30 janvier 2011 - 04:10 .
                     
                  


            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #7 on: January 30, 2011, 07:12:40 am »


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

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

//Put this script OnOpen
#include "nw_i0_generic"

void main()
{

   object oPC = GetLastOpenedBy();

   if (!GetIsPC(oPC)) return;

   object oTarget;
   object oSpawn;
   location lTarget;
   oTarget = oPC;

   lTarget = GetLocation(oTarget);

   //Change nw_skeleton to the RESREF of the creature you want to spawn.
oSpawn = CreateObject(OBJECT_TYPE_CREATURE, "nw_skeleton", 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

   int nInt;
   nInt = GetObjectType(oTarget);

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

}

Try this. I generated it from Lilac Soul's Script Generator - nice little tool for such mundane tasks. I didn't bother to clean it up.

@Xovian - the random has nothing to do with Lightfoot's script not working. The way its written it should spawn a skeleton each time, with a 10% chance of spawning a Skeleton Chief instead. My guess would be that when Darker Shade modified the string name he used the creature's TAG and not its RESREF. CreateObject uses the RESREF to call the template, not the template's TAG.
               
               

               


                     Modifié par Pstemarie, 30 janvier 2011 - 07:19 .
                     
                  


            

Legacy_Pstemarie

  • Hero Member
  • *****
  • Posts: 4368
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #8 on: January 30, 2011, 07:26:15 am »


               To make the coffin disappear, add the following lines to the end of the script:

SetPlotFlag(OBJECT_SELF, FALSE);
DestroyObject(OBJECT_SELF, 0.5);

Note that the script I presented above will spawn the creature next to the PC and force it to attack. If you want the creature to spawn where the coffin was, change the following line:

oTarget = oPC;

TO:

oTarget = OBJECT_SELF;
               
               

               


                     Modifié par Pstemarie, 30 janvier 2011 - 07:26 .
                     
                  


            

Legacy_A Darker Shade of Soul

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #9 on: January 30, 2011, 06:53:23 pm »


               Thanks everyone for your help. And yes I used the tag instead of the resref....
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #10 on: January 30, 2011, 07:21:50 pm »


               Yes the Tag was your problem.  The script I posted was just what you requested, It was the script you posted with all the HB stuff striped out of it.   There was no reason to Check who opened the object since all you really cared about was if it was opened or not.  



As far as the %chance it was only there to change the creature to a more powerfull one 10 % of the time. So the script should have been spawning a creature every time If you used a valid ResRef.



Hope you have everything working the way you want.

L8
               
               

               
            

Legacy_A Darker Shade of Soul

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #11 on: January 30, 2011, 07:24:38 pm »


               Pste, the script fired and this time the creature spawned however it didn't apply the visual effect. I opened the coffin and the lich just appeared w/o the visual. Destroying the coffin isn't really neccessary because this is for a pw so it can keep firing. One thing however I'd like to have happen is have the monster spawn at a wp away from the coffin that way the pc's don't have the advantage of immediate attack being as the lich is a spellcaster and needs time to buff etc. I appreciate all of you guys help.
               
               

               
            

Legacy_A Darker Shade of Soul

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #12 on: January 30, 2011, 07:28:04 pm »


               @Lightfoot, yep I tried yours again as well with a resref instead of the tag and it worked just how it was supposed to. Only thing being is if it could spawn the lich at a wp to give it time to buff as I said to Pste. I forgot about that when I op'd this '<img'>
               
               

               
            

Legacy_Greyfort

  • Sr. Member
  • ****
  • Posts: 442
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #13 on: January 30, 2011, 07:32:34 pm »


               here is rerite of lightfoots script making you spaw creature at way point

//  l8_spwn
void ActionCreate(string sCreature, location lLoc)
{
   CreateObject(OBJECT_TYPE_CREATURE, sCreature, lLoc);
}
void main()
{

   effect eMind = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD);
   string sCreature = "NW_SKELWARR01";
   // * 10% chance of a skeleton chief instead
   if (Random(100) > 90)
   {
       sCreature = "NW_SKELCHIEF";
   }
   location lLoc = GetLocation(GetObjectByTag("NAME OF WAYPOINT HERE"));//GetLocation(OBJECT_SELF);
   DelayCommand(0.3, ActionCreate(sCreature, lLoc));
   ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eMind, GetLocation(OBJECT_SELF));
   SetPlotFlag(OBJECT_SELF, FALSE);
   DestroyObject(OBJECT_SELF, 0.5);
}

be sure to put your way point name ware it says NAME OF WAY POINT HERE

and you should be good
               
               

               


                     Modifié par Greyfort, 30 janvier 2011 - 07:32 .
                     
                  


            

Legacy_A Darker Shade of Soul

  • Full Member
  • ***
  • Posts: 159
  • Karma: +0/-0
Need Help Modifying A Heartbeat Script
« Reply #14 on: January 30, 2011, 07:41:58 pm »


               

Greyfort wrote...

here is rerite of lightfoots script making you spaw creature at way point

// l8_spwn
void ActionCreate(string sCreature, location lLoc)
{
CreateObject(OBJECT_TYPE_CREATURE, sCreature, lLoc);
}
void main()
{

effect eMind = EffectVisualEffect(VFX_FNF_SUMMON_UNDEAD);
string sCreature = "NW_SKELWARR01";
// * 10% chance of a skeleton chief instead
if (Random(100) > 90)
{
sCreature = "NW_SKELCHIEF";
}
location lLoc = GetLocation(GetObjectByTag("NAME OF WAYPOINT HERE"));//GetLocation(OBJECT_SELF);
DelayCommand(0.3, ActionCreate(sCreature, lLoc));
ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eMind, GetLocation(OBJECT_SELF));
SetPlotFlag(OBJECT_SELF, FALSE);
DestroyObject(OBJECT_SELF, 0.5);
}

be sure to put your way point name ware it says NAME OF WAY POINT HERE

and you should be good

 

Lol..gotcha! Thank you.