Aller au contenu

Photo

Scripting a returning weapon?


  • Veuillez vous connecter pour répondre
8 réponses à ce sujet

#1
rjshae

rjshae
  • Members
  • 4 485 messages
I would like to have an item like the Axe of Returning, which is a magical throwing axe that returns to the wielder's hand after being thrown. A tag-based script works fine for putting a duplicate of the hurled object back in the character's weapon slot. The problem is that, in between the time the weapon is thrown and a duplicate object is added back in, the character AI has switch over to performing a melee attack. Has anybody found a way to make this work?

Thank you. :happy:

#2
Quilistan

Quilistan
  • Members
  • 111 messages
I remember seeing this done back with NWN1, so it should be possible. A quick search on the NWvault brought up this from CODI

nwvault.ign.com/View.php
 
It might at least get you started.

Modifié par Quilistan, 23 août 2010 - 03:09 .


#3
Kaldor Silverwand

Kaldor Silverwand
  • Members
  • 1 585 messages
Or you could just download my returnable weapons from the vault here: http://nwvault.ign.c...s.Detail&id=130

My scripts are generic and can be easily adapted to any thrown item.

Regards

Modifié par Kaldor Silverwand, 24 août 2010 - 09:19 .


#4
kamalpoe

kamalpoe
  • Members
  • 711 messages

Kaldor Silverwand wrote...

Or you could just download my returnable weapons from the vault here: .

My scripts are generic and can be easily adapted to any thrown item.

Regards

Yes. These are very handy. As are some of the other weapons there.

#5
rjshae

rjshae
  • Members
  • 4 485 messages
Ah okay. So you basically check for a combat opponent, then clear all actions, restore the weapon and send the owner back into combat against the same opponent. Thanks, I think that will do the trick nicely.

Modifié par rjshae, 23 août 2010 - 08:55 .


#6
rjshae

rjshae
  • Members
  • 4 485 messages
I did some testing of the technique last night, and it wasn't quite as simple as I had hoped. First, I have to perform the ClearAllActions right away to avoid the character closing for melee. In addition, if I move the character prior to the thrown weapon being re-equipped, but after it is added to the inventory, it does not get equipped. I had to do a couple of delayed commands to make sure the weapon gets equipped even if a move occurs; adding more ClearAllActions in the process. Also, if the character moved prior to the next attack, it will still continue to attack the same target even though it should cease. Thus I had to put in checks to see if a move occurred and the character did not switch targets. Phew, it's messy.

I guess this could be added to the list things I wish were built in item properties.

Modifié par rjshae, 24 août 2010 - 02:28 .


#7
Shaughn78

Shaughn78
  • Members
  • 637 messages
For my giant boulder toss to prevent the giants from throwing a boulder then charging into melee I used the AIIgnoreCombat(); from #include "ginc_ai". You can calculate the travel time from the player to target and return, which I assume is how you are delay the re-equip part and have it turn the AI back on.

#8
rjshae

rjshae
  • Members
  • 4 485 messages
I think I finally got this working fairly reliably. To make it more robust, I split the weapon handling into three scripts (unequip, acquire and equip). In the previous unequip-only script, under some circumstances the weapon was being duplicated (such as when I immediately unequip it after it gets equipped). To fix this, I immediately delete the original after creating the copy. Still, I did occasionally end up with some duplicates, perhaps through timing problems. Fortunately, I'm able to address this by set the stack size to 1 after creating the copy.

To cause the owner to attack the same opponent after the weapon is retrieved, I store the opponent's object on the weapon copy. When the re-acquire occurs, that object can be retrieved and the owner returned to the attack. I also added a location variable, which is used to see if the owner has moved between the attack and the re-equip. If the move is more than some small amount, I cancel the attack.

Modifié par rjshae, 13 septembre 2010 - 03:45 .


#9
Dann-J

Dann-J
  • Members
  • 3 161 messages
I've approached the problem from a different angle, and created an OnHit tag-based script that returns the thrown weapon (or ammo) only on a successful hit:

http://www.neverwint...ds.com/mods/210

If you miss, the stack decreases by one as usual. When used with throwing axes or darts, you get a projectile effect of it returning to the player. It doesn't work if you throw the last one in the stack though (since all it's doing is incrementing the stack size by 1 on each hit, and there's no stack left to increment after the last is gone).

I'll be using it only on throwing axes and darts (even though it also works for ammo), and making them available individually from merchants (set to infinite). That way you can top up your stack if you've been missing your targets a lot.

I'm also thinking of making special ammo that can be reused, by giving them an OnHit script that creates a single copy of the ammo blueprint on a creature with each hit, so you can pluck them from the corpse afterward. A random number could determine whether the ammo is recoverable or whether it breaks on impact, rather than always have them recoverable.