Author Topic: Summon creature at location, not next to PC  (Read 443 times)

Legacy_chlorinesea

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Summon creature at location, not next to PC
« on: May 30, 2011, 01:41:29 am »


               I'm trying to create a "Unique Power" wand which will summon a creature (a sheep!) at the location targeted by the player when they "use" the wand.

I can get everything working if I summon the creature at the PC's location (ignoring where the player targeted).

I can only get a visual effect to work if I try to summon the creature at the targeted location.

Here is what is working:

ApplyEffectToObject(DURATION_TYPE_PERMANENT, eSummon, oPC, 1.0);

EDIT: derp, had oWP instead of oPC in the quote box. I've been playing with the code a lot. oPC works, oWP does not, even if I've defined oWP properly.

Here is what is inexplicably NOT working:

ApplyEffectAtLocation(DURATION_TYPE_PERMANENT, eSummon, lTarget, 1.0);


This is the whole script, a mishmash of stuff from Lilac's script generator, stuff I found online, and stuff I wrote myself.

#include "x2_inc_switches"
#include "x2_inc_spellhook"

void main()
{
int nEvent = GetUserDefinedItemEventNumber();
// Exit if not an activate event
if(nEvent !=  X2_ITEM_EVENT_ACTIVATE)return;

object oPC = GetItemActivator();
location lTarget = GetItemActivatedTargetLocation();
effect eSummon = EffectSummonCreature("lum_sheepy", VFX_FNF_SUMMON_CELESTIAL, 3.0, 1);
effect eEffect = EffectVisualEffect(VFX_FNF_SUMMON_CELESTIAL);

ApplyEffectToObject(DURATION_TYPE_PERMANENT, eEffect, oPC, 1.0);
ApplyEffectToObject(DURATION_TYPE_PERMANENT, eSummon, oPC, 1.0);

}


I know that eEffect and eSummon are calling the same visual effect. I planned to change one to VFX_FNF_MYSTICAL_EXPLOSION as soon as I got this working. '<img'>

I have also tried creating a waypoint at the targeted location and summoning the creature there using ApplyEffectToObject, with no success.

Does anybody know how to successfully summon a creature at a targeted location, rather than right next to the PC?

Thank you!
               
               

               


                     Modifié par chlorinesea, 30 mai 2011 - 07:14 .
                     
                  


            

Legacy_GhostOfGod

  • Hero Member
  • *****
  • Posts: 1490
  • Karma: +0/-0
Summon creature at location, not next to PC
« Reply #1 on: May 30, 2011, 04:15:20 am »


               Instead of using a summoning effect to create the creature just create the creature using the "CreateObject" function and then add whatever visuals you want to it. Something more like:


#include "x2_inc_switches"
void main()
{
    int nEvent = GetUserDefinedItemEventNumber();
    // Exit if not an activate event
    if(nEvent !=  X2_ITEM_EVENT_ACTIVATE) return;

    location lTarget = GetItemActivatedTargetLocation();
    object oSheep = CreateObject(OBJECT_TYPE_CREATURE, "res ref here", lTarget);
    effect eVisual = EffectVisualEffect(VFX_FNF_SUMMON_CELESTIAL);

    ApplyEffectToObject(DURATION_TYPE_INSTANT, eVisual, oSheep);
}


Just make sure you plug in the right res ref for the creature you want to create.
               
               

               


                     Modifié par GhostOfGod, 30 mai 2011 - 03:18 .
                     
                  


            

Legacy_chlorinesea

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Summon creature at location, not next to PC
« Reply #2 on: May 30, 2011, 06:17:39 am »


               Hmm, that created a sheep at the proper location, but the sheep isn't controllable as a summon and it played no visual effect.

I'll keep working on it. I'm trying to avoid henchmen scripts because it's just a "toy" or "gimmick" item for a PW. In the worst case scenario, I'll just change the visual effect to something that doesn't look so awful when it plays right next to the PC.
               
               

               
            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Summon creature at location, not next to PC
« Reply #3 on: May 30, 2011, 06:28:03 am »


               The only thing I see wrong, with a quick glance, is that you are trying to use DURATION_TYPE_PERMANENT with effects that need to be DURATION_TYPE_TEMPORARY.  

The Problem may be as simple as your duration on the ApplyEffect  of 1.0  is already expired when the creature is trying to be created, since the creature is being created 3.0 seconcd after the visual display.  
               
               

               


                     Modifié par Lightfoot8, 30 mai 2011 - 05:32 .
                     
                  


            

Legacy_chlorinesea

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Summon creature at location, not next to PC
« Reply #4 on: May 30, 2011, 08:09:53 am »


               Haha, awesome, I'd actually already changed it to DURATION_TYPE_TEMPORARY. I tried upping the duration to 5.0, and also removing the duration completely, but I'm still getting a visual effect with no sheep. Here's what I've got now:

#include "x2_inc_switches"

void main()
{
int nEvent = GetUserDefinedItemEventNumber();
// Exit if not an activate event
if(nEvent !=  X2_ITEM_EVENT_ACTIVATE)return;

object oPC = GetItemActivator();
location lTarget = GetItemActivatedTargetLocation();
effect eSummon = EffectSummonCreature("lum_sheepy", VFX_FNF_SUMMON_CELESTIAL, 3.5);
effect eEffect = EffectVisualEffect(VFX_FNF_MYSTICAL_EXPLOSION);

DelayCommand(3.5, ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eEffect, lTarget, 5.0)); //this one works perfectly.
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, lTarget, 5.0); //this does not summon a sheep OR play the effect. I can't figure out why.

}


Blaah it feels like this should be easy. '<img'>

EDIT: Default NWN summon script seems to use GetSpellTargetLocation() instead of GetItemActivatedTargetLocation() for obvious reasons. I tried that for kicks and got no result whatsoever.
               
               

               


                     Modifié par chlorinesea, 30 mai 2011 - 07:21 .
                     
                  


            

Legacy_Lightfoot8

  • Hero Member
  • *****
  • Posts: 4797
  • Karma: +0/-0
Summon creature at location, not next to PC
« Reply #5 on: May 30, 2011, 08:55:54 am »


               Ok, I see the problem now.  

Unlike spell scripts, OnActivate scripts run on the module not the PC.  So when you are creating you eSummons effect it is the module creating it.  It is also the module that the script is trying to add the summons to its party.  and of cource it just does not have one.  

so you need to assign the creation and application of the Effect to the PC.  

AssignCommand(oPC,ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, EffectSummonCreature("lum_sheepy", VFX_FNF_SUMMON_CELESTIAL, 3.5), lTarget, 5.0));

Yes messy but it all need to be done in one line.
               
               

               
            

Legacy_chlorinesea

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Summon creature at location, not next to PC
« Reply #6 on: June 06, 2011, 07:13:58 am »


               THANK YOU.

That fixed it. My module was corrupted (...unrelated) so right now it's spawning a naked dwarf instead of a sheep, but I know how to fix that.

THANK YOU SO MUCH.