Spell Spells - Simple Dash Spell

K

Knyves

Guest
When your tutorial uses more then one costom trigger code, I think it's kind of redundant to call it "Simple". just a thought...
 

emjlr3

Change can be a good thing
Reaction score
395
lol

its got like 3 custom functions....to me...or most JASSers, that is pretty simple

I called it a simple DASH spell bacause, it a DASH spell, which is a popular thing, as easy as can be done in JASS

its not even many lines, not even 100 I think

I've got plenty of spells that are 300+ lines of code, with a dozen custom functions
 

WarLuvr3393

Hmmm...too many things to play (WoW, COD4, WC3)
Reaction score
54
JASS:
local real ang = bj_RADTODEG * Atan2(ytargy, xtargx)


What is this line doing? Can't you just use "AngleBetweenPoints()"? You can just use locations and get the angle.

Edit: This tutorial is WAY too much for me, I don't get any of this.
 

Sim

Forum Administrator
Staff member
Reaction score
534
It's to prevent the use of BJs, or pre-made functions by Blizzard.

Instead of calling the function you do what it does directly.
 

WarLuvr3393

Hmmm...too many things to play (WoW, COD4, WC3)
Reaction score
54
Well, this tutorial is FAR FROM "simple", I don't get any of these "GetAttachment" stuff and reading this, I caught myself just copying and not learning because I do NOT get what he's doing in this tutorial.
 

Sim

Forum Administrator
Staff member
Reaction score
534
He's using the CScache, by Vexorian. That's why maybe you see function calls you don't understand at all, such as the tables.
 

emjlr3

Change can be a good thing
Reaction score
395
this is a simple dash spell, not a simple jass tut, it is required u know jass and how to use cscache/other handle vars system to read this, or did you jsut skip my whole intro?
 

WarLuvr3393

Hmmm...too many things to play (WoW, COD4, WC3)
Reaction score
54
JASS:
//*************************************************************
//* Constant Functions (Only edit things under this section.) *
//*************************************************************
constant function FW_Raw_Code takes nothing returns integer
  return 'A003'
endfunction

//**************
//* Conditions *
//**************

function FW_Spell_Check takes nothing returns boolean
  return GetSpellAbilityId() == FW_Raw_Code()
endfunction

//*************
//* Functions *
//*************

function FW_Dash takes nothing returns nothing
  //Local Varibles and Handles
    local timer dashtimer = GetExpiredTimer()
    local unit caster = GetHandleUnit(dashtimer, "caster")
    local real dist = GetHandleReal(dashtimer, "dist")
    local location casterpos = GetUnitLoc(caster)
    local real xtarget = GetHandleReal(dashtimer, "xtarget")
    local real ytarget = GetHandleReal(dashtimer, "ytarget")
    local location targetpoint = Location(xtarget, ytarget)
    local real angle = AngleBetweenPoints(casterpos,targetpoint)
    
  //Functions
    if GetHandleReal(dashtimer, "dist") >= 0.0 then //Cannot be exact.  Must go into negatives to take effect so weird distances can be detected
      call SetUnitPositionLoc(caster, PolarProjectionBJ(casterpos, 75.00, angle))
      call SetHandleReal(dashtimer, "dist", dist-75.00) //This is my indicator which will keep decreasing until it's below 0
      call DestroyEffect(AddSpecialEffect("Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl", GetUnitX(caster), GetUnitY(caster)))
    else
      call PauseUnit(caster, false)
      call ResetUnitAnimation(caster)
      call SetUnitPathing(caster, false)
    endif      
        
  //Null Variables
    set caster = null
    call RemoveLocation(casterpos)
    call RemoveLocation(targetpoint)
    set casterpos = null
    set targetpoint = null   
endfunction

function FW_Spell takes nothing returns nothing
  //Local Variables
    local unit caster = GetTriggerUnit()
    local timer dashtimer = CreateTimer()
    local location targetpoint = GetSpellTargetLoc()
    local real xtarget = GetLocationX(targetpoint)
    local real ytarget = GetLocationY(targetpoint)
    local real dist = DistanceBetweenPoints(GetUnitLoc(caster), targetpoint)
      
  //Handles
    call SetHandleHandle(dashtimer, "caster", caster)
    call SetHandleReal(dashtimer, "xtarget", xtarget)
    call SetHandleReal(dashtimer, "ytarget", ytarget)
    call SetHandleReal(dashtimer, "dist", dist)
       
  //Functions
    call PauseUnit(caster, true)
    call SetUnitAnimation(caster, "attack")
    call SetUnitPathing(caster, true)
    call TimerStart(dashtimer, 0.035, true, function FW_Dash)
    
  //Null Variables
    call ResetUnitAnimation(caster)
    call PauseTimer(dashtimer)
    call DestroyTimer(dashtimer)
    set dashtimer = null
    call FlushHandleLocals(dashtimer)
    set caster = null
    call RemoveLocation(targetpoint)
    set targetpoint = null
endfunction

//===========================================================================
function InitTrig_Flame_Walk takes nothing returns nothing
local integer i
    set i = 0
    set gg_trg_Flame_Walk = CreateTrigger(  )
    loop
      exitwhen i>12
      call TriggerRegisterPlayerUnitEventSimple( gg_trg_Flame_Walk, Player(i), EVENT_PLAYER_UNIT_SPELL_EFFECT)
      set i = i + 1
    endloop
    call TriggerAddCondition( gg_trg_Flame_Walk, Condition(function FW_Spell_Check))    
    call TriggerAddAction( gg_trg_Flame_Walk, function FW_Spell )
    call Preload("Abilities\\Spells\\Human\\FlameStrike\\FlameStrike1.mdl")
endfunction


Edit: WOW! I had it working then it magically stopped (just kidding about the magic), I don't know what I did wrong. Please help me complete this tedious spell!
 
R

Rode

Guest
Well this was way to hard for me at the moment. maybe when I get better this will help me.
Is there a tutorial like this but with a VERY simple spell? That would be more helpful for me.
:)
 

emjlr3

Change can be a good thing
Reaction score
395
you can try my "So you want to learn JASS" tut., that may help a bit
 

Hatebreeder

So many apples
Reaction score
381
Emj, I have made a Spell due to your Tut.
JASS:
function Trig_Dash_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A001'
endfunction

function Trig_Dash_Condition takes nothing returns boolean
    local string String2 = GetAttachmentTable(GetTriggeringTrigger())
    return IsUnitEnemy(Caster,GetFilterUnit(), GetOwningPlayer(GetTableUnit(String,"Caster"))) == true and GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) >= 0 and IsUnitType(GetFilterUnit(),UNIT_TYPE_STRUCTURE) == false) and IsUnitType(GetFilterUnit(),UNIT_TYPE_MAGIC_IMMUNE) == false)
endfunction

function Trig_Dash_Damage takes nothing returns nothing
    local string String2 = GetAttachmentTable(GetTriggeringTrigger())
    local unit Caster = GetTableUnit(String2,"Caster")
    local unit Victim = GetTriggerUnit()
    local real Damage = GetHeroAgi(Caster,true)
    
    call UnitDamageTarget(Caster,Victim,Damage,true,true,ATTACK_TYPE_HERO,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
    call DestroyEffect(AddSpecialEffectTarget("Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl",Victim,chest)
    
    set Caster = null
    set Victim = null
endfunction

function Trig_Dash_Effects takes nothing returns nothing
    local timer Timer = GetExpiredTimer()
    local string String2 = GetAttachmentTable(Timer)
    local trigger Trigger
    local string String
    local unit Caster = GetTableUnit(String2,"Caster",Caster)
    local real Angle = GetTableReal(String2,"Angle",Angle)
    local real Distance = GetTableReal(String2,"Distance",Distance)
    local real Moved = GetTableReal(String2,"Moved",Moved)
    
    call SetUnitPosition(Caster,GetUnitX(Caster) + 30 Cos(Angle * bj_DEGTORAD), GetUnitY(Caster) + 30 Sin(Angle * bj_DEGTORAD))
    call SetUnitAnimationByIndex(Caster,10)
    set Moved = Moved + 30
    
    if Moved <= Distance or UNIT_STATE_LIFE <= 0 then
        set Trigger = GetTableTrigger(String2,"Trigger",Trigger)
        set String = GetAttTable(Trig)
        call TriggerRemoveAction(Trigger,GetTableTriggerAction(String,"ta"))
        call ClearTable(String)
        call DestroyTrigger(Trigger)
        set Trigger = null
        call SetUnitTimeScalePercent(Caster,100)
        call SetUnitPathing(Caster,true)
        call SetUnitAnimationByIndex(Caster,0)
        call ClearTable(String2)
        call PauseTimer(Timer)
        call DestroyTimer(Timer)
    else
        call SetTableReal(String2,"Moved",Moved)
    endif
endfunction

function Trig_Dash_Actions takes nothing returns nothing
    local unit Caster = GetTriggerUnit()
    local location Target = GetSpellTargetLoc()
    local real CasterX = GetUnitX(Caster)
    local real CasterY = GetUnitY(Caster)
    local real TargetX = GetLocationX(Target)
    local real TargetY = GetLocationY(Target)
    local real Angle = bj_RADTODEG * Atan2(TargetY - Y, TargetX - X)
    local real DistanceX = TargetX - X
    local real DistanceY = TargetY - Y
    local real Distance = SquareRoot(DistanceX * DistanceX + DistanceY * DistanceY)
    local trigger Trigger = CreateTrigger()
    local string String = GetAttachmentTable(Trigger)
    local timer Timer = CreateTimer()
    local string String2 = GetAttachmentTable(Timer)
    
    call TriggerRegisterUnitInRange(Trigger,Caster,150,null)
    call TriggerAddCondition(Trigger,Condition(function Trig_Dash_Condition))
    call SetTableObject(String,"TimerAction",TriggerAddAction(Trigger, function Trig_Dash_Damage))
    call SetTableObject(String,"Caster",Caster)
    
    call SetTableReal(String2,"Angle",Angle)
    call SetTableReal(String2,"Distance",Distance)
    call SetTableReal(String2,"Moved",Moved)
    call SetTableObject(String2,"Caster",Caster)
    call SetTableObject(String2,"Trigger",Trigger)
    call TimerStart(Timer,0.03,true,function Trig_Dash_Effects)
    
    call SetUnitTimeScalePercent(Caster,400)
    call SetUnitPathing(Caster,false)
    call SetUnitAnimationByIndex(Caster,10)
    
    set Caster = null
    call RemoveLocation(Target)
    set Target = null
    set Trigger = null
endfunction

//===========================================================================
function InitTrig_Dash takes nothing returns nothing
    set gg_trg_Dash = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Dash, EVENT_PLAYER_UNIT_SPELL_EFFECT )
    call TriggerAddCondition( gg_trg_Dash, Condition( function Trig_Dash_Conditions ) )
    call TriggerAddAction( gg_trg_Dash, function Trig_Dash_Actions )
    call Preload("Objects\\Spawnmodels\\Human\\HumanBlood\\BloodElfSpellThiefBlood.mdl")
endfunction

Gave the Variables a longer Name, so I know what what they all mean.
JASS Craft gives me alot of errors when I parse.
Did I do something wrong? Or, Is it because of CScache, that is not "Implemented" in JASSCraft?
Hehe ^^ Some Explanation of this would make me happy =)
 

emjlr3

Change can be a good thing
Reaction score
395
JASSCraft will only show correct syntax on functions it has, if you do not add CSCache to the funcions which JASSCraft contains, then ofcourse it will give you errors
 

Sim

Forum Administrator
Staff member
Reaction score
534
Broken due to the CSCache using the now-fixed H2I return bug.
 

emjlr3

Change can be a good thing
Reaction score
395
the premise is still sound - just replace Table with struct members and timersafety
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top