• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Order a unit to move to another Unit; Current Mana

Status
Not open for further replies.

JJE

JJE

Level 2
Joined
Jan 29, 2009
Messages
8
Hi,

I wanted to create a spell, that deals damage to an enemy unit based on the current MP of the casting Unit.

Now there are 2 problems.

1. I didnt find a function on how to get the exact amount of the current Mana of the casting unit, only the ManaPercent. (solved)

2. The Moving Order targeting the enemy Unit doesnt work and Im pretty sure Ive taken the wrong Order, but Idk which one I shouldve taken.

So heres the script:

Code:
function trig_Manaburst_conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A004' ) 
endfunction

function trig_Manaburst_actions takes nothing returns nothing

    local unit caster = GetSpellAbilityUnit()
    local unit dmgUnit = null
    local unit targetUnit = GetSpellTargetUnit()
[COLOR="Blue"][B]    local real damage = ( 0.5 * GetUnitManaPercent(caster) )[/B][/COLOR]
       
    set dmgUnit = CreateUnitAtLoc( GetOwningPlayer(caster), 'h004', GetUnitLoc(caster), bj_UNIT_FACING )
[COLOR="Blue"][B]    call SetUnitMoveSpeed( dmgUnit, 1000 )
    call IssueTargetOrderBJ( dmgUnit, "move", targetUnit )[/B][/COLOR]
    call UnitDamageTargetBJ( dmgUnit, targetUnit, damage, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC )
    call RemoveUnit( dmgUnit )
endfunction

function InitTrig_Manaburst takes nothing returns nothing
    local trigger trg_manaburst = null
    set trg_manaburst = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trg_manaburst, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( trg_manaburst, Condition( function trig_Manaburst_conditions ) )
    call TriggerAddAction( trg_manaburst, function trig_Manaburst_actions )
endfunction

Hope you can help me,

Thx in advance :)
 
Last edited:
Level 20
Joined
Apr 22, 2007
Messages
1,960
Use
JASS:
 tags next time. :P

To get mana, I believe the function is [icode=jass]call GetUnitState(yourUnit, UNIT_STATE_MANA)[/icode]
Not sure though, I don't have access to my native list now.

Try the "smart" order. I don't know if it will work for sure, because I haven't worked with orders like at all, but try it anyway.

Also, fix all of those BJ calls. Natives make your code more efficient and cleaner (most of the time). You also have to null your local handles at the end of your function. Please read one of the Jass tutorials on this site and you'll most likely find a lot of help.

Oh, yeah 1000 surpasses the move speed limit (I think it's around 500). It's impossible to pass that limit no matter what you do. The only way to make it move faster is by scripting the movement.
 

JJE

JJE

Level 2
Joined
Jan 29, 2009
Messages
8
Thx for the help, going to test it later, not enough time now, though I think it would work with your code.

Since my dummy unit is thought as a missile / projectile it can surpass the speed max. The speed isnt maxed to 522, you can change that with triggers / jass. It isnt impossible to surpass this, look at abiolities at dota like for example leap, there the MS is temporary about 800.

And I did use the Jass tags ;)


Edit: Tried out the Code, it works now, but unfortunately it doesnt calculate 0.5 * Mana State, but only the Mana State :S

Well, 1st problem half solved, 2nd still the same.

Btw, what did you mean with "smart"? And if I change the IssueTargetOrderBJ into IssueTargetOrder, then theres a mistake.


Edit 2: Thx for reminding me about the locals, I forgot that ;)

Now the trigger looks like this:
Code:
function trig_Manaburst_conditions takes nothing returns boolean
    return ( GetSpellAbilityId() == 'A004' ) 
endfunction

function trig_Manaburst_actions takes nothing returns nothing

    local unit caster = GetSpellAbilityUnit()
    local unit dmgUnit = null
    local unit targetUnit = GetSpellTargetUnit()
    local real damage = ( 0.5 * GetUnitState( caster, UNIT_STATE_MANA ) )
       
    set dmgUnit = CreateUnitAtLoc( GetOwningPlayer(caster), 'h004', GetUnitLoc(caster), bj_UNIT_FACING )
    call SetUnitMoveSpeed( dmgUnit, 1000 )
    call IssueTargetOrder( dmgUnit, "move", targetUnit )
    call UnitDamageTargetBJ( dmgUnit, targetUnit, damage, ATTACK_TYPE_MAGIC, DAMAGE_TYPE_MAGIC )
    call RemoveUnit( dmgUnit )
    
    set caster = null
    set dmgUnit = null
    set targetUnit = null
endfunction

function InitTrig_Manaburst takes nothing returns nothing
    local trigger trg_manaburst = null
    set trg_manaburst = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ( trg_manaburst, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddCondition( trg_manaburst, Condition( function trig_Manaburst_conditions ) )
    call TriggerAddAction( trg_manaburst, function trig_Manaburst_actions )
endfunction
 
Last edited:
Level 7
Joined
Jul 20, 2008
Messages
377
I think "move" doesn't work on a target, since the move functionality on a target is "follow" but I assume you want the unit to move to the position of the target, so just do:

JASS:
call IssuePointOrder(dmgUnit, "move", GetUnitX(targetUnit), GetUnitY(targetUnit))

Though, of course, I also don't have my native list with me now, so check the order of the parameters.

P.S., your GetUnitLoc (in your create unit call) is leaking. Either use a local var for that or just don't use locations. In general, you should try to use direct X and Y coordinates instead of locations.
 
Status
Not open for further replies.
Top