Author Topic: Possible to redirect spells via hook?  (Read 377 times)

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Possible to redirect spells via hook?
« on: October 29, 2012, 02:41:32 pm »


               Using a Spellhook script, is it possible to 'change' the target at cast time, without having to have an instance for every spell in the hook?

Eg - I am creating a Defensive Shield power.

You cast it, it creates a Dome around your character (maybe a 10 ft radius)

The dome is made up of placeables that are applied at certain intervals on the sphere/dome's shape.

The idea I had was to set the spellhook to do a

GetFirst/NextObjectInShape loop - to find if any of these shield placeables are in the direct path of the caster -> target.

If the Line of Sight between Caster and Target goes through the dome, then we change the target to be the node/placeable on the shield.

This results in the Fireball that was launched at the person inside the shield, actually impacting on the shield.
or
The Magic Missile cast on the person inside the shield, impacts the shield itself.


This is all conditional on being able to change the target at hooktime, preferablly in such a way, that I dont need to do a case statement for every spell in the game.
               
               

               
            

Legacy_the.gray.fox

  • Full Member
  • ***
  • Posts: 214
  • Karma: +0/-0
Possible to redirect spells via hook?
« Reply #1 on: October 29, 2012, 04:21:44 pm »


               Hello.

-- SHORT ANSWER:
What you want to do -> can be done.
Just not via spellhook. The spellhook was not conceived for that kind of functionality.


-fox





-- LONG ANSWER:
To elaborate on your example of the fireball, yes you can redirect the fiery projectile to anywhere (read: any 3D point in 3D space) you like. But to do so you must edit the spellscript that plays when you cast a fireball spell. And the spellhook takes place _before_ such spellscript gets to run (not entirely true, but true enough for what concerns you).

The bottom line is that: yes you can do it, but no you can not do it quickly & cheaply with the spellhook.

Either you do some massive script editing by yourself, or you employ a set of scripts already edited -by someone else- in which they prepared several hooks that offer more functionality than bioware thought of with their simplicistic solution.

If you accept a friendly advice, beware of the easy solutions. The easier they look, the worst they are at the core, leaving you little room for intervention... short of massively modding them yourself... but at that point you would have been better off starting with your own mod from scratch. Do not you think?

<< There is NO magic wand >>
Make it a mantra.


-fox
               
               

               


                     Modifié par the.gray.fox, 29 octobre 2012 - 04:36 .
                     
                  


            

Baaleos

  • Administrator
  • Hero Member
  • *****
  • Posts: 1916
  • Karma: +0/-0
Possible to redirect spells via hook?
« Reply #2 on: October 29, 2012, 04:42:33 pm »


               I think it might be possible via nwnx. (specifically nwnx_cool or events)


int (__fastcall *CNWSCreature__AddCastSpellActionsNext)( CNWSCreature * cre, void *, unsigned long nSpell, int arg2, int arg3, int metamagic, int arg5, Vector vTarget ,nwn_objid_t arg6, int arg7, int arg8, int arg9, unsigned char arg10, int arg11, int arg12, int arg13, unsigned char arg14 );

nwnx_cool already hooks this function - which gets fired when you create the action to cast a spell.
In theory - if I hooked at this point, I could get the target,
Do the Cone/GetObjectInShape call - ascertain if there is a shield in the way.
If so - bypass (cancel the spell cast)
Add new Action to the ActionQueue in its place,with the new target.

Because the nwnx call/action cancelation would probably result in the action not have been added to the queue in the first place, it shouldnt affect combat rounds either.

eg: Although I say 'bypass/cancel' the cast event, its actually just stopping it from being created.

This means when the nwnscript takes over, and casts the spell in its stead - it should be just like the target I had selected, was actually the wall/barrier itself, and hopfully there shouldnt be anything suggesting that it had cancelled an action previously.

Although, this is all theoretical at the moment,
Implimentation will be trial and error.