Jump to content

Scripting help needed for creature to befriend BGII NPC


ericp07

Recommended Posts

Hello,

 

The idea here is that, if Meleryn the ranger sees any creature (while in an outdoor area) with Race(CAT) and Class(HUNTER_CREATURE), she will use the ranger ability to charm animals, making the creature her friend/ally. Ideally, if and when the effect wears off, the creature won't automatically turn hostile, but will go about its business. This comes from the fact that Sylvan Elves regularly attract big cats and owls (but there aren't really owls in BGII, are there?) as helpful allies, at least when encountered in forests. I could limit the area to (FOREST) if necessary, or else just set up the script for any non-CITY and non-DUNGEON area.

 

It appears to me that I'll need to use both Race(CAT) and Class(HUNTER_CREATURE) to specify the target creature in the conditions, and then Spell([target_creature],SPPR204) to apply the effect. However, I don't see what I should use as an identifier for "target_creature", meaning I'm not sure how to tie it all together in a script block.

 

Can this be done? Would someone please enlighten me on this, or refer me to something I can read that will clear up my uncertainty here?

 

Thanks very much!

Eric

Link to comment

Figured out enough to write a script block, but I need to know if 1) class abilities are referenced as spells, and 2) if class abilities are treated as spells for scripting purposes. Knowing these things will allow me to complete the script, having Meleryn use her ranger charm animal ability on the nearest creature that's both a CAT and a HUNTER_CREATURE.

 

However...would there be any advantage to handling it this way, instead? Set the conditions the same (nearest creature meets the criteria), and give a percentage chance of the animal becoming friendly (using "Ally()"). Speaking of Ally(), is NEAREST supposed to go inside the parentheses, or is that to be left as-is?

 

Thanks,

Eric

Link to comment

Here's the damage I've done so far (in EP#Mel.baf) :

 

// Attracting big cats
IF
InParty(Myself)
See(NEAREST)
AND(2)
Race(NEAREST,CAT)
Class(NEAREST,HUNTER_CREATURE)
THEN
RESPONSE #100
DO ~Spell(NEAREST,GA_spcl311)~
END

 

Something tells me I need to change this in some way, but I wouldn't know without testing, and I can't test yet. Any pointers?

 

Cheers,

Eric

Link to comment
It won't trigger if any of the conditions aren't true anyway, so yeah, you don't need it. :)

 

That should do it, then...and Eric learns to figure more stuff out :) That one took a little sleuthing, and I'm glad to have found how to put it together. Apprenticeship continues.

 

- E

Link to comment

You'll have better luck with something like this:

// Attracting big cats
IF
InParty(Myself)
See([0.0.CAT]) //Nearest object with race=CAT
Class(LastSeenBy(Myself),HUNTER_CREATURE) //if the object we saw has class=HUNTER_CREATURE
!Allegiance(LastSeenBy(Myself),GOODCUTOFF) //If the object we saw isn't already friendly
HaveSpell(RANGER_CHARM_ANIMAL) //can't cast the spell if it's not memorised
THEN
RESPONSE #100
Spell(LastSeenBy(Myself),RANGER_CHARM_ANIMAL)~
END

There's a lot more than could be done, but at least it'll (probably) compile.

Link to comment
You'll have better luck with something like this:

// Attracting big cats
IF
InParty(Myself)
See([0.0.CAT]) //Nearest object with race=CAT
Class(LastSeenBy(Myself),HUNTER_CREATURE) //if the object we saw has class=HUNTER_CREATURE
!Allegiance(LastSeenBy(Myself),GOODCUTOFF) //If the object we saw isn't already friendly
HaveSpell(RANGER_CHARM_ANIMAL) //can't cast the spell if it's not memorised
THEN
RESPONSE #100
Spell(LastSeenBy(Myself),RANGER_CHARM_ANIMAL)~
END

There's a lot more than could be done, but at least it'll (probably) compile.

 

This looks like what I was after...but now I'm not so sure the charm spell is the best way to handle this; I prefer to use the ranger ability rather than "waste" a spell, which is why I thought GA_spcl311 was the correct choice. In any case, I'll use the above code until and unless I arrive at a more suitable solution.

 

Thanks very much!

Eric

Link to comment

"GA_*" is nonsense outside .2da files. Furthermore, RANGER_CHARM_ANIMAL is the ids label of spcl311. If you don't want to use one of the class spells for it, you need to use SpellNoDec(target,spell) (or ApplySpell if you want to make it seem the cat spontaneously becomes friendly, but then you need a spell that doesn't allow for a save etc) instead, in which case you can remove the HaveSpell() trigger.

 

Yet more edit: But having your NPC cast spells like this will interrupt whatever she's currently doing (e.g., fighting) and leave her standing there until the player or her script gives her a new command. You might want to give the cats a script that makes them go Ally when they see your NPC, or something, instead.

Link to comment
"GA_*" is nonsense outside .2da files. Furthermore, RANGER_CHARM_ANIMAL is the ids label of spcl311. If you don't want to use one of the class spells for it, you need to use SpellNoDec(target,spell) (or ApplySpell if you want to make it seem the cat spontaneously becomes friendly, but then you need a spell that doesn't allow for a save etc) instead, in which case you can remove the HaveSpell() trigger.

 

Yet more edit: But having your NPC cast spells like this will interrupt whatever she's currently doing (e.g., fighting) and leave her standing there until the player or her script gives her a new command. You might want to give the cats a script that makes them go Ally when they see your NPC, or something, instead.

 

Ah, OK. I didn't realize that we were talking about the same spell *L* Yes, it should appear to be a more spontaneous thing, as Sylvan Elves and big cats are favorably disposed toward each other, according to one of the game materials I've read. I'd like to represent this in the mod. I'll have to find out if there's an appropriate spell to use for the effect...but, as you pointed out, I don't want the NPC to be left idle, and I had begun to consider working something up from the creature's side, rather than from the NPC's side. Not sure yet how to implement that, though.

 

Thanks! Back to the drawing board :)

- E

Link to comment

I don't suppose there'd be a way to patch all the CAT/HUNTER_CREATURE .cre files in the game (including ToB), to give them all a percentage chance to befriend Meleryn on sight, via the .tp2...? The only other way to set this up that comes to mind is to make custom versions of the relevant .cre files, then COPY them into override in the .tp2 to replace the vanilla versions.

 

I'm always interested in efficient solutions :)

 

Thanks,

Eric

Link to comment
I don't suppose there'd be a way to patch all the CAT/HUNTER_CREATURE .cre files in the game (including ToB), to give them all a percentage chance to befriend Meleryn on sight, via the .tp2...?
It sure can be done. The catch is, you probably do not want to assign blindly new scripts to them, so manual checking is better.

 

Ok, this code says there's only a dozen of them in existance, and at least three seem to be 'special'.

COPY_EXISTING_REGEXP GLOB ~.*\.cre~ override LPF FJ_CRE_VALIDITY RET valid=valid END PATCH_IF valid BEGIN
 READ_BYTE 0x272 race
 READ_BYTE 0x273 class
 PATCH_IF race=0x89 AND class=0xc8 BEGIN
PATCH_PRINT ~%SOURCE_RES%~
 END
END BUT_ONLY

So I guess manually updating each is not a big deal.

 

PS The HUNTER script looks like the place to go to.

Link to comment

Looks like custom versions of the big cats to replace vanilla counterparts is in order, to give them a custom script to assign to the Race script field. On it. Doing it this way will avoid the mod's Beasts of Malar befriending Meleryn (which would be amusing, but just wrong) :)

 

Thanks,

Eric

Link to comment

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...