• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Trying to make my own spell

Status
Not open for further replies.
Level 19
Joined
Feb 15, 2008
Messages
2,184
I need help making a spell im trying to make it.

Make a spell that allows player to target a point, and move in quickly to that point. The unit must reach that point within 0.5 seconds and casting range can be up to 2000.

i got this from a friend who telling me to do this as my first step.

He told me i need 2 triggers. I started first trigger

  • Trig1
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to wfdasfd
    • Actions
Hmm then im stuck And he told me i need periodic event :S Im trying to learn this stuff now all help is welcome :)
 
Level 13
Joined
Sep 14, 2008
Messages
1,407
Well first of all you need some actions and variables and another trigger:

Variable Point
Variable Unit

Actions:
set VariablePoint = targeted point of ability being cast
set Variable Unit = casting unit
Trigger - enable "secondtrigger"


Second trigger:

Event: Every "..." of game time (should be something like 0.05 - 0.1)
Actions: Move "variableUnit" instantly to (point with polar offset) position of variableUnit offset by 10 or 20 (choose) in "degree between "position of "variableUnit" and "variablePoint".

If(distance between position of "variableUnit" and "variablePoint" > 30)
trigger - turn off this trigger
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
Nice helping, DarkAngelAzazel :D

No offense, but I don't think he'll get that :)

My answer to all questions in the universe: read a tutorial or two

You have some on this site, on wc3campaigns.net, on thehelper.net etc. Believe me, it will help, that's what they're for :D
 
Level 9
Joined
Oct 17, 2007
Messages
547
Just modify the Blink ability.. and use the trigger to add the moving effects. Make sure you give blink 1 sec delay so you can create the effects before the unit is moved.
 
Level 6
Joined
Jul 25, 2005
Messages
221
Indeed there are tutorials that will familiarize you with the GUI as well as the JASS scripting, everything is on this forum!

Even so, I've learnt that it is easier to learn new things by seeing it in action, right?
So, let's begin. I'll keep it simple.
Also, please note that if you set the time to 0.5 seconds, then the animation won't be that cool, in my opinion at least. I'd set it to like 1.5 seconds, but nontheless, let's follow the parameters you gave.

  • InitSpell
    • Events
      • Unit - A unit Begins casting an ability
    • Conditions
      • (Ability being cast) Equal to MyEpicSpell
    • Actions
      • -------- You could just as easily use Triggering Unit, but it is easier to understand this way --------
      • Set caster = (Casting unit)
      • Set target_point = (Target point of ability being cast)
      • Set move_point = (Position of (Casting unit))
      • Set hero_point = (Position of (Casting unit))
      • Set timer_interval = 0.05
      • Set time = (0.50/timer_interval)
      • Set distance = (Distance between hero_point and target_point)
      • Set speed = (distance / time)
      • Countdown Timer - Start timer as a Repeating timer that will expire in timer_interval seconds
  • timerMoveHero
    • Events
      • Time - timer expires
    • Conditions
    • Actions
      • Set move_point = ((Position of caster) offset by speed towards (Angle from (Position of caster) to target_point) degrees)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between move_point and target_point) Less than speed
        • Then - Actions
          • Countdown Timer - Pause timer
        • Else - Actions
          • Unit - Move caster instantly to move_point, facing target_point
Similarily this could be written like this in JASS:
JASS:
globals
    timer MOVE_TIMER = CreateTimer( )
    unit CASTER
    location HERO_LOC
    location DESTINATION_LOC
    location MOVE_LOC
    real SPEED
    real TIME = 0.50
    real TIMER_INTERVAL = 0.05
    real DISTANCE
endglobals

function conditions takes nothing returns boolean
return GetSpellAbilityId() == 'A000' //Spell ID
endfunction

function move_timer takes nothing returns nothing
    if( DistanceBetweenPoints( MOVE_LOC, DESTINATION_LOC ) >= SPEED ) then
    set MOVE_LOC = PolarProjectionBJ( GetUnitLoc( CASTER ), SPEED, AngleBetweenPoints( HERO_LOC, DESTINATION_LOC ) )
    call SetUnitPositionLoc( CASTER, MOVE_LOC )
    else
    call PauseTimer(MOVE_TIMER)
endif
endfunction

function init_values takes nothing returns nothing
    set MOVE_LOC = GetUnitLoc( CASTER )
    set CASTER = GetTriggerUnit()
    set HERO_LOC = GetUnitLoc( CASTER )
    set DESTINATION_LOC = GetSpellTargetLoc( )
    set DISTANCE = DistanceBetweenPoints( HERO_LOC, DESTINATION_LOC)
    set TIME = TIME/TIMER_INTERVAL
    set SPEED = DISTANCE/TIME
    call TimerStart( MOVE_TIMER, TIMER_INTERVAL, true, function move_timer )
endfunction

//===========================================================================
function InitTrig_initspell takes nothing returns nothing
    local trigger initspell = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( initspell, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( initspell, Condition( function conditions ) )
    call TriggerAddAction( initspell, function init_values )
endfunction
Note that if you can't do Global declarations, then download Newgen, or just create the variables on your own in the variable tab (CTRL+B) in the trigger editor. All you need to do then is add udg_ to your variable names and remove the global declarations at the start of the script and it should be the same

JASS:
function conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A000' //Spell ID
endfunction

function move_timer takes nothing returns nothing
    if( DistanceBetweenPoints( udg_MOVE_LOC, DESTINATION_LOC ) >= udg_SPEED ) then 
    set udg_MOVE_LOC = PolarProjectionBJ( GetUnitLoc( udg_CASTER ), udg_SPEED, AngleBetweenPoints( udg_HERO_LOC, udg_DESTINATION_LOC ) )
    call SetUnitPositionLoc( udg_CASTER, MOVE_LOC )
    else
    call PauseTimer(udg_MOVE_TIMER)
    endif
endfunction

function init_values takes nothing returns nothing
    set udg_MOVE_LOC = GetUnitLoc( udg_CASTER )
    set udg_CASTER = GetTriggerUnit()
    set udg_HERO_LOC = GetUnitLoc( udg_CASTER )
    set udg_DESTINATION_LOC = GetSpellTargetLoc( )
    set udg_TIME = udg_TIME/udg_TIMER_INTERVAL
    set udg_DISTANCE = DistanceBetweenPoints( udg_HERO_LOC, udg_DESTINATION_LOC)
    set udg_SPEED = udg_DISTANCE/udg_TIME
    call TimerStart( udg_MOVE_TIMER, udg_TIMER_INTERVAL, true, move_timer )
endfunction

//===========================================================================
function InitTrig_InitSpell takes nothing returns nothing
    local trigger initspell = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( initspell, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( initspell, Condition( function conditions ) )
    call TriggerAddAction( initspell, function init_values )
endfunction
This is not MUI. (I know...)
The JASS functions should be applicable right into a new trigger, just remove everything when you convert it to JASS and add the code and replace the line: "function InitTrig_InitSpell" to "function InitTrig_'TriggerName'"
Example: function InitTrig_Untitled_Trigger_001
 
Last edited:
Level 11
Joined
May 31, 2008
Messages
698
Heres a trigger i used for my map. It is leak free (or should be) and it can be used for multiple players (i used arrays).

  • Grapple
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Grapple
    • Actions
      • Set Target_Loc[(Player number of (Owner of (Triggering unit)))] = (Target point of ability being cast)
      • Set Caster_Loc[(Player number of (Owner of (Triggering unit)))] = (Position of (Casting unit))
      • Lightning - Create a Chain Lightning - Primary lightning effect from source (Position of (Triggering unit)) to target Target_Loc[(Player number of (Owner of (Triggering unit)))]
      • Set Grapple_Lightining[(Player number of (Owner of (Triggering unit)))] = (Last created lightning effect)
      • Set GrappleTarget[(Player number of (Owner of (Triggering unit)))] = (Target unit of ability being cast)
      • Set GrappleCaster[(Player number of (Owner of (Triggering unit)))] = (Casting unit)
      • Unit - Make (Triggering unit) face Target_Loc[(Player number of (Owner of (Triggering unit)))] over 0.01 seconds

  • Grapple2
    • Events
      • Time - Every 0.01 seconds of game time
    • Conditions
    • Actions
      • Unit Group - Pick every unit in Grapplers and do (Actions)
        • Loop - Actions
          • Set Grapple_Loc = ((Position of (Picked unit)) offset by ((Distance between Caster_Loc[(Player number of (Owner of (Picked unit)))] and Target_Loc[(Player number of (Owner of (Picked unit)))]) / 20.00) towards (Facing of (Picked unit)) degrees)
          • Lightning - Move Grapple_Lightining[(Player number of (Owner of (Picked unit)))] to source (Position of (Picked unit)) and target Target_Loc[(Player number of (Owner of (Picked unit)))]
          • Set Hop_Int[(Player number of (Owner of (Picked unit)))] = (Hop_Int[(Player number of (Owner of (Picked unit)))] + 1)
          • Unit - Move (Picked unit) instantly to Grapple_Loc
          • Unit - Turn collision for GrappleCaster[(Player number of (Owner of (Picked unit)))] Off
          • Unit - Create 1 Frog Illusion for (Owner of (Picked unit)) at (Position of GrappleCaster[(Player number of (Owner of (Picked unit)))]) facing (Facing of GrappleCaster[(Player number of (Owner of (Picked unit)))]) degrees
          • Unit - Add a 0.15 second Generic expiration timer to (Last created unit)
          • Custom script: call RemoveLocation(udg_Grapple_Loc)
            • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
              • If - Conditions
                • Hop_Int[(Player number of (Owner of (Picked unit)))] Greater than or equal to (>=) 20
              • Then - Actions
                • Lightning - Destroy Grapple_Lightining[(Player number of (Owner of (Picked unit)))]
                • Set Hop_Int[(Player number of (Owner of (Picked unit)))] = 0
                • Unit Group - Remove (Picked unit) from Grapplers
                • Unit - Turn collision for GrappleCaster[(Player number of (Owner of (Picked unit)))] On
              • Else - Actions
Some of this you might not need. I used some effects so it makes a lightning to the target that moves with the unit as it approaches the target. I also made the dummy units to make a kind of illusion path behind the caster.
This one should take .2 seconds to reach the destination, but i think it takes longer because the times in trigger editor are not exact. You can tell it should be .2 seconds because it goes every .01 seconds and i have it set so that it moves the unit forward 20 times (20 times .01 = .2). You might want to move the unit towards Math - Angle between points(CasterLoc and Target Loc) just so it will move exactly in the direction of where you casted the ability.
 
Level 6
Joined
Jul 25, 2005
Messages
221
wolfman, keep in mind that he is a novice on this subject, or so I believe; don't confuse him with arrays for MUI capability, nor leaks for that matter.
I also suggest you clean up your code a bit; using variables so that it becomes easier to change something if it's wrong.
That way, it is easy on the eyes and structured for any further editing. Commenting and adding seperation lines is a great way to improve your script.

Other than that, it was an interesting script.
 
Level 11
Joined
May 31, 2008
Messages
698
wolfman, keep in mind that he is a novice on this subject, or so I believe; don't confuse him with arrays for MUI capability, nor leaks for that matter.
I also suggest you clean up your code a bit; using variables so that it becomes easier to change something if it's wrong.
That way, it is easy on the eyes and structured for any further editing. Commenting and adding seperation lines is a great way to improve your script.

Other than that, it was an interesting script.

Well for my maps, i dont really feel like making it easy to understand cuz usually im the only one that has to understand it :p
But yeah, a lot of times when i set variables i usually do it in one long line instead of making multiple ones that are easier to read but whatever lol
 
Status
Not open for further replies.
Top