Jump to content

Photo

Hijacking Wands (or Swords)

Beta Quality of Life script

  • Please log in to reply
3 replies to this topic

#1 Orithan

Orithan

    Studying Scientist - Commission from Silvixen

  • Members
  • Location:Australia

Posted 11 August 2015 - 11:05 PM

Code


Update: 8:31 PM 12/08/2015 AEST - Addition of the option to enable getting hit while stabbing or slashing to cancel the projectile, and minor rewrite to the script to match how the built-in Wand consumes Magic/counter.

As it says on the tin, this script will allow you to hijack wands (and other things that have a stab/slash animation, like Candles and Swords) to delay the onset of the effect until the slash/stab animation has ended instead on the frame the item is used on. This replicates the delay of projectiles fired by Swords, Wands and Candles and is useful for having them fire custom LWeapons. This is currently in beta and needs testing.


Setup

Simply copy-paste the script into your script files, import std.zh if you already haven't, and place the ScriptWand(); function call in the main global loop of Global Script Slot 2. If you want the Wand to slash, change "ANIMATION_STAB_DURATION" in the ScriptWand(); call to "ANIMATION_SLASH_DURATION". Compile it and then set up your Wand (or Sword) in the item editor:
  • Under the Data page of the Wand item, make sure the checkbox "Allow Magic w/o Book" is unchecked. This is to prevent the wand from firing its default Magic LWeapon alongside your scripted effect. (For Swords, make sure "B.H. is percent" is unchecked and Beam Hearts is set to a really high amount (eg. 100) to prevent the sword beam from firing off alongside your scripted effect).
  • (Skip this if you don't require the effect to have a cost) Go over to the Pickup tab and set "Counter Reference" to the counter that the weapon uses to check against costs is set to the counter you require (eg. Set it to "Arrows" if you require the effect to cost Arrows).  Next, pop over to Augments and set D1 to how much of the counter specified before it takes to activate the Wand's special effect.
  • While still under Augments, attach the ScriptWand script to the Wand's active slot and set D0 to the item's ID. Setting it to the correct ID is vital to the script's function, Don't miss it.
  • Change the item's Level, Power, UseSound and the other D-Variables to your heart's content and you are ready
However, the script by itself doesn't actually do anything - This is merely the skeleton of such a script. You, the scripter, will have to write the effect yourself. Here are a few guidelines on how to write the effect:
  • All 8 D# variables must be declared in the void run() of the item script or else the script will not compile.
  • LoadItemdataScriptWand must be called at the start of the item script.
  • ClearItemdataScriptWand must be called whenever the script might end. This includes in the global script after the scripted effect ends and in the item script if there is any chance that the script might end before it reaches the trigger that activates the Global portion of it (eg. If you don't meet the item's cost.). It also must be called in Global script Slot_3 (OnExit) to prevent possible issues for if you die or F6 during the wands' animation.
  • You put your code into the area which says "//Stuff goes here"
List of Weapon types supported by this script:
  • Wand
  • Sword
  • Candle
  • Cane of Bryna
  • Hammer (Use the ANIMATION_SLASH_DURATION with Hammers)

 
Caveats

  • If you are using this with Wands, do not give the player the Book unless you want it to fire the default Wand magic alongside your intended effect if the player acquires it. For the same reason, it is not a good idea to give the player the Peril Beam scroll if you give this to swords unless you like the idea of Link randomly shooting Sword Beams alongside the script's effect when at 1 Heart or whatnot.
  • If you charge using the sword while the script is attached to said sword, the effect occurs while you are charging; much like the standard sword beam.
  • If you wish to give the item a counter increase alongside this script and you wish to give it a cost, the counter the counter increase on pickup refers to is the same one as the weapon uses to read its counter cost.

Future plans

  • Full support for Hammers. They may or may not be supported by this script, but I will need to test that.
  • Support for delaying effects for swords until Link has finished charging his sword and after he has finished a Spin Attack/Hurricane spin.
  • A basic example script.
  • Full documentation. This documentation is rough and fails to explain everything I wish to explain.

Edited by Orithan, 12 August 2015 - 05:35 PM.


#2 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 12 August 2015 - 12:37 AM

I've some scripted wand, sword, and other weapons that could fill in the blanks. I even have most of the stock items set up as global functions, to make it easier to map an item to Ex buttons, or use them any way that I please.

 

I'm not however, sold on why this is useful: Why would you want to delay the damage of a sword, or other weapon, like this?

 

i.e. What is the intended application?

 

I should not again, for added emphasis, that if you script an item to use magic, you need to tie its cost into Game->Generic[GEN_MAGICDRAINRATE] so that if a user wants to utilise 'half-magic' in a game, it is consistent for values set both via the Item Editor, and direct script checks/instructions. 



#3 Orithan

Orithan

    Studying Scientist - Commission from Silvixen

  • Members
  • Location:Australia

Posted 12 August 2015 - 04:24 AM

The script's intended application is to time the activation of the script's effect with the animation of the built-in Stab or Slash animation the Wand it is attached to has (which is shared with other weapon types like Sword, Candle and Cane of Bryna), instead of activating on the frame after the button is pressed like what an item script by itself would, to produce a projectile that is fired by the Wand in much the same way as how the built-in Magic weapon is fired. This can be adapted to Swords, Candles and Canes of Bryna (though the latter two are not optimal, as they have effects of their own that are harder to stop and are rendered obsolete by the versatility of the Wand unless you wish to have the weapon's swing to not cause damage and the rule that prevents the Wand from being used as a Melee weapon is not checked).
 
Say for instance you have a special projectile that you want a custom wand to fire. If you use just an item script, the projectile is fired on the frame you use the weapon; which does not match up with the timing at which the Wand fires its default projectile. This is acceptable when the wand has no slash/stab animation (at which point you should be using a different item class altogether instead of a wand item) or somewhat acceptable when it uses the stab animation because it instead of yourself still appears to fire the projectile.
However, when you wish to have the Wand use the slashing animation, the projectile is fired well before the Wand is held in front of Link (and before the animation ends); which looks bad as it appears to fire from Link and not the Wand itself. This combined Global/Item script approach solves this issue, as the Wand with the slashing animation now correctly appears to fire the projectile from the wand as opposed to Link appearing to fire it. It also makes the stabbing variant look more authentic and in line with how the wand fires projectiles.
 
Edit: I also forgot one important feature that I need to include - Getting hit while slashing or stabbing with the built-in Wand before the projectile is fired cancels the projectile. This script will need to be updated to reflect that... And done!

 

Edit again: Scratch that, that wasn't a feature present on the Wand. Modifying post accordingly.


Edited by Orithan, 12 August 2015 - 05:01 AM.

  • Timelord likes this

#4 Timelord

Timelord

    The Timelord

  • Banned
  • Location:Prydon Academy

Posted 12 August 2015 - 05:26 AM

Ah, that's much clearer, and something I could do in three, or four ways. I'll try to make some code for you next week, so that you have a more well-rounded project. I may even consider making a function DelayItem() as a general thing, or DelayProjectile().

 

It's actually probably possible to copy, kill, and recreate a projectile too.

 

It does sound like a very good plan indeed, and the way that I hadled this in the past was a bit different.

 

I may even make something like AutoGhost for weapons at some point. They're one of my specialisations (engine dynamics, and visual effects are my other prime foci), after all. That would allow a user to set up routines for eweapons, and lweapons in general.





Also tagged with one or more of these keywords: Beta, Quality of Life, script

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users