Jump to content


Photo

Question about the "HaveSpell" trigger


5 replies to this topic

#1 Zvalat

Zvalat
  • Members
  • 3 posts

Posted 17 August 2011 - 11:50 PM

Hello,

I have two questions about spells and scripting.

1/ I added a NPC to the game, let's call him Bob. I talk to Bob with a party member, let's say Alice. I would like that Bob's dialog has different replies depending on the spells that Alice can cast. For example I put in Bob.d:

IF ~~ THEN BEGIN SpellList   SAY @400   IF ~HaveSpell(2112)~ THEN REPLY @403 EXIT   IF ~~ THEN REPLY @402 EXITEND

The problem with that code is that (if I understand correctly) it checks if Bob can cast the spell instead of checking if Alice can cast the spell. The IESDP specifies

HaveSpell(I:Spell*Spell) - Returns true only if the active CRE has the specified spell memorised.


How could I make Alice the "active CRE" in the dialog file?

2/ Is it possible to add/remove a spell from the list of known spells of a NPC? For example, I would like to remove the spell "Magic Missile" from Alice's spellbook. I looked in the IESDP action list, but could not find how to do that.

Thanks in advance for your answers.

Edited by Zvalat, 17 August 2011 - 11:53 PM.


#2 Avenger

Avenger
  • Modders
  • 3388 posts
  • Gender:Male
  • Location:Hungary

Posted 18 August 2011 - 12:30 AM

This trigger doesn't support objects, so you have to run it from Alice.
If Alice is in the party and Bob isn't in the party, you may try HaveSpellParty.

Removing spells is easy. Apply a spell on the target with the effect 172 (0xac)

#3 Zvalat

Zvalat
  • Members
  • 3 posts

Posted 18 August 2011 - 11:34 AM

Thank you for your answer.

1/ For the memorised spell detection.

This trigger doesn't support objects, so you have to run it from Alice.
If Alice is in the party and Bob isn't in the party, you may try HaveSpellParty.



After some tinkering, I ended up with some scripts that more or less do what I want. But I do not know if it is the correct way to do that. Here they are:

BOB.d
IF ~~ THEN BEGIN CheckSpells   SAY @500   IF ~~ THEN DO ~SetGlobal("ZVCheckSpells","GLOBAL",1)~ EXITEND

BOB.baf (Override script of Bob)
IF  Global("ZVCheckSpells","GLOBAL",1)THEN    RESPONSE #100             SetGlobal("ZVCheckSpells","GLOBAL",0)             ActionOverride(LastTalkedToBy(Myself),ChangeAIScript("TEST",DEFAULT))             Continue()END

TEST.baf
IF  Global("ZVTest","GLOBAL",0)  HaveSpell(2112)THEN    RESPONSE #100             SetGlobal("ZVTest","GLOBAL",1)             DisplayString(Myself,46150)             Continue()END

Basically, the dialog file set a global variable that triggers the check spell block in Bob's override script. This script assigns the script Test.baf as Alice default script so that the ability to cast Magic Missile is checked with Alice as active creature.

It works, but I do not know how to correctly remove the script Test from Alice. I guess I should do another ChangeAIScript("Something",DEFAULT), but with which"something" script? Also, could it be a problem to replace a NPC default script with another one?


2/ The addition/removal of spells from the spellbook.

Removing spells is easy. Apply a spell on the target with the effect 172 (0xac)



I'll test that another day :)

Edited by Zvalat, 18 August 2011 - 11:36 AM.


#4 Avenger

Avenger
  • Modders
  • 3388 posts
  • Gender:Male
  • Location:Hungary

Posted 18 August 2011 - 12:58 PM

The default script for joined npcs is DPLAYER2

#5 Zvalat

Zvalat
  • Members
  • 3 posts

Posted 19 August 2011 - 11:59 AM

W00t it works.

Thanks a lot for your answers. My NPC is now able to identify the spell in a (party member) sorcerer's spellbook, and can then swap one of the known spells for another (unknown) one.

Now that the technical part is (more or less) sound, I can add the dialogues and extend my scripts to include all existing spells.

Edited by Zvalat, 19 August 2011 - 12:01 PM.


#6 Miloch

Miloch

    Barbarian

  • Modders
  • 4715 posts
  • Gender:Male
  • Location:At Large

Posted 24 August 2011 - 11:48 PM

I just hit a similar wall with this. In my case, I don't think the ChangeAIScript() trick is going to work, because I can't count on the trigger always coming from an NPC (it could be from the PC for example). So I'm not sure if we always know what the existing default (or any other) script value is. There is probably some long, contrived, jury-rigged script that might work but...

Why the hell doesn't the engine have a HaveSpell() that takes an object? Or at least a TriggerOverride() the same way there's an ActionOverride()? So many other spell triggers like SpellCast() take an object, why not this one?
Mod Contributions
Aurora (new release!) * BG1 NPC * Gnomes * Haiass * Level 1 NPCs * Lost Items * P5Tweaks
PnP Free Action * Thrown Hammers * Unique Containers * In Progress: Adjusted Portraits * DSotSC (Tutu)
================================================================
Player & Modder Resources
BAM Batcher * Creature Lister * PSPad Highlighters * Tutu/BGT Area Map & List * Tutu Mod List
================================================================
"Wherefore do ye toil; is it not that ye may live and be happy? And if ye toil only that ye may toil more,
when shall happiness find you?" -H.P. Lovecraft, The Quest of Iranon



Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users