• 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] custom spell

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Hi ,

i am trying to make a custom spell based on channel abi...
the spell can target unit and destructible.
but the effect is different depending if it is casted on unit or a destructible.
how can i detect what kind of target has be selected by the player spell casting?
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
[Jass=]
function Fireball_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A101' ) ) then
return false
endif
return true
endfunction

function Fireball takes nothing returns nothing
local unit targetU
local destructable targetD
local unit caster = GetTriggerUnit()
local boolean tree
local real dmg
local real x
local real y
if ( GetSpellTargetUnit() == null ) then
set targetD = GetSpellTargetDestructable()
set tree = true
set x = GetDestructableX(targetD)
set y = GetDestructableY(targetD)
else
set targetU = GetSpellTargetUnit()
set tree = false
set x = GetUnitX(targetU)
set y = GetUnitY(targetU)
endif
if ( IsTerrainPathable( x, y, PATHING_TYPE_FLOATABILITY) == false ) or ( udg_Raining == false ) then
if ( tree == false ) then
set dmg = 60.00
call SetUnitState( targetU, UNIT_STATE_LIFE, ( GetUnitState( targetU, UNIT_STATE_LIFE ) - dmg ))
else
call DisableTrigger( gg_trg_DropItemDestructible__JASS )
call KillDestructable( targetD )
call EnableTrigger( gg_trg_DropItemDestructible__JASS )
endif
else
if ( tree == false ) then
set dmg = 30.00
call SetUnitState( targetU, UNIT_STATE_LIFE, ( GetUnitState( targetU, UNIT_STATE_LIFE ) - dmg ))
else
call DisableTrigger( gg_trg_DropItemDestructible__JASS )
call SetDestructableLife( targetD, (GetDestructableLife( targetD) - 100.00 ))
call EnableTrigger( gg_trg_DropItemDestructible__JASS )
endif
endif
set targetU = null
set targetD = null
set caster = null
endfunction

//===========================================================================
function InitTrig_custom_Fireball_JASS takes nothing returns nothing
set gg_trg_custom_Fireball_JASS = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_custom_Fireball_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_custom_Fireball_JASS, Condition( function Fireball_Conditions ) )
call TriggerAddAction( gg_trg_custom_Fireball_JASS, function Fireball )
endfunction
[/code]

is this ok?
the fireball is weakened by rain or when the target is in water.
the unit take 60 dmg or 30 dmg if (water/rain)
the destructable is destroyed or take 100 dmg if (rain/water)

i wanted to use widget for both, but i think it is safer to use two variable.

it will be a little more complicated than this...
because the damage will be lowered by armor factor of unit, and if no (rain/water) a burning buff will be added to target unit dealing 5 dmg/ sec for 4 sec.

is there a way to detect armor of unit (the number) ?
i think it is not possible so i will have to store all into variable.
what's the best way to add the burning damage and buff? an invi unit poison attack (poison transformed into burning damage)
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
There are a lot of things that can be improved in your spell.

1/ Don't use if myCondition == true, it is the most redundant thing ever. Just if myCondition.

2/ You can merge the condition block and the action block into one like this

JASS:
function Fireball_Conditions takes nothing returns boolean
    // Declare locals

    if GetSpellAbilityId() == A101 then
        // Set locals

        // Do stuffs

        // Null vars
    endif
    return false
endfunction

3/ if myCond == false could also be changed to if not myCond

4/ You don't need a bracket for if conditions.

5/ Get rid of unwanted spaces to make the code looks clean and neat.

6/ Why don't you use UnitDamageTarget() so the killer could get the bounty?

7/ The caster var isn't used anywhere.

There isn't a way to detect armor. The burn could be done through poison or triggered through a periodic timer.
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
does UnitDamageTarget is affected by the armor of the target?
 
Level 23
Joined
Apr 16, 2012
Messages
4,041
to add a little note
damage type magic will not hit magic immune units and its damage is reduced by magic resistance(runed bracer etc)
there is third one, which actually works(I dont know if the other works) which is damage type universal which will hit a unit under any condition(other than invulnerability)
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
[Jass=]
function Fireball takes nothing returns boolean
local unit targetU
local destructable targetD
local unit caster = GetTriggerUnit()
local unit dummy
local boolean tree
local real dmg
local real x
local real y
if GetSpellAbilityId() == 'A101' then
if ( GetSpellTargetUnit() == null ) then
set targetD = GetSpellTargetDestructable()
set tree = true
set x = GetDestructableX(targetD)
set y = GetDestructableY(targetD)
else
set targetU = GetSpellTargetUnit()
set tree = false
set x = GetUnitX(targetU)
set y = GetUnitY(targetU)
endif
if IsTerrainPathable( x, y, PATHING_TYPE_FLOATABILITY) or udg_Raining then
if not tree then
call UnitDamageTarget(caster, targetU, 60.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WOOD_MEDIUM_BASH)
set dummy = CreateUnit( GetOwningPlayer(caster), 'hfoo', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy , 'Abun' )
call IssueTargetOrder( dummy, "attack", targetU )
else
call DisableTrigger( gg_trg_DropItemDestructible__JASS )
call KillDestructable( targetD )
call EnableTrigger( gg_trg_DropItemDestructible__JASS )
endif
else
if not tree then
call UnitDamageTarget(caster, targetU, 30.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WOOD_MEDIUM_BASH)
else
call DisableTrigger( gg_trg_DropItemDestructible__JASS )
call UnitDamageTarget(caster, targetU, 100.00, true, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WOOD_MEDIUM_BASH)
call EnableTrigger( gg_trg_DropItemDestructible__JASS )
endif
endif
set targetU = null
set targetD = null
set caster = null
set dummy = null
endif
return false
endfunction

//===========================================================================
function InitTrig_custom_Fireball_JASS takes nothing returns nothing
set gg_trg_custom_Fireball_JASS = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_custom_Fireball_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_custom_Fireball_JASS, Condition( function Fireball ) )
endfunction
[/code]

so, is this ok?
what does the damage type fire do?
and is there a way to not get a weapon type (it is used only for sound right?)

Edit
it needed return a boolean
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
1. Set caster after GetSpellId. You won't want it to be called by every single spell cast.

2. You forgot to remove a pair of brackets.

3. Both boolean of UnitDamageTarget should be false.

4. DAMAGE_ TYPE_FIRE = DAMAGE_TYPE_COLD = DAMAGE_TYPE_MAGIC.

5. WEAPON_TYPE_WHOKNOWS == null i.e no sound.
6. DAMAGE_TYPE_NORMAL == null.
Other than that, nice work :D
 
Last edited:

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
[Jass=]
function Fireball takes nothing returns boolean
local unit targetU
local destructable targetD
local unit caster
local unit dummy
local boolean tree
local real dmg
local real x
local real y
if GetSpellAbilityId() == 'A101' then
set caster = GetTriggerUnit()
if GetSpellTargetUnit() == null then
set targetD = GetSpellTargetDestructable()
set tree = true
set x = GetDestructableX(targetD)
set y = GetDestructableY(targetD)
else
set targetU = GetSpellTargetUnit()
set tree = false
set x = GetUnitX(targetU)
set y = GetUnitY(targetU)
endif
if IsTerrainPathable( x, y, PATHING_TYPE_FLOATABILITY) or udg_Raining then
if not tree then
call UnitDamageTarget(caster, targetU, 60.00, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
set dummy = CreateUnit( GetOwningPlayer(caster), 'hfoo', x, y, bj_UNIT_FACING )
call UnitAddAbility( dummy , 'Abun' )
call IssueTargetOrder( dummy, "attack", targetU )
else
call DisableTrigger( gg_trg_DropItemDestructible__JASS )
call KillDestructable( targetD )
call EnableTrigger( gg_trg_DropItemDestructible__JASS )
endif
else
if not tree then
call UnitDamageTarget(caster, targetU, 30.00, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
else
call DisableTrigger( gg_trg_DropItemDestructible__JASS )
call UnitDamageTarget(caster, targetU, 100.00, false, false, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_WHOKNOWS)
call EnableTrigger( gg_trg_DropItemDestructible__JASS )
endif
endif
set targetU = null
set targetD = null
set caster = null
set dummy = null
endif
return false
endfunction

//===========================================================================
function InitTrig_custom_Fireball_JASS takes nothing returns nothing
set gg_trg_custom_Fireball_JASS = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_custom_Fireball_JASS, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_custom_Fireball_JASS, Condition( function Fireball ) )
endfunction
[/code]

ok.
so ATTACK_TYPE_NORMAL should be replaced by null
or is it actually the same and should stay as it is?

about ATTACK_TYPE_ Fire/Cold/magic
there are all magic but do they do something else?
for example is it possible to detect the TYPE_FIRE and do extra damage on certain units?

Nice work? Lol i just copied, followed what you told me to do...
so basically it is nice work to you.
 
Level 16
Joined
Dec 15, 2011
Messages
1,423
It should be false not null, damn me and my brain.

DAMAGE_TYPE_NORMAL, not ATTACK_TYPE_NORMAL, is null, Mag tested :) And yes you can replace them with null.

Afaik you can't detect damage type :(

Well setting the first boolean to true causes the dmg to fire Unit attacked event, so yeap, it depends on the user.
 
Status
Not open for further replies.
Top