# Basic attack spell

#### Klann

Level 9
how do i make the basic attack as spell?
SPELL : damage the unit in front of the user, no required target, attack on cast

EDIT : to explain further, im going to remove the units basic attack and add a spell which would be the units new basic attack, removing some functions like auto attack when an enemy gets near the unit, and continuously attacking the enemy unit

Last edited:

#### Maker

Level 37
Here's something to work with:

JASS:
``````function Attack_Filter takes nothing returns boolean
endfunction

function Attack_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'Acrs'
endfunction

function Attack_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
local real x = GetUnitX(u)
local real y = GetUnitY(u)
local real f = GetUnitFacing(u) * bj_DEGTORAD
local player p = GetOwningPlayer(u)
local unit t
local real x2
local real y2

call GroupEnumUnitsInRange(bj_lastCreatedGroup, x ,y, 172+150, function Attack_Filter)
loop
set t = FirstOfGroup(bj_lastCreatedGroup)
exitwhen t == null
set x2 = GetUnitX(t)
set y2 = GetUnitY(t)
if IsUnitEnemy(t, p) and IsUnitInRangeXY(t, x, y, 150) and Cos(f-Atan2(y2-y, x2-x)) > 0 then
call UnitDamageTarget(u, t, 50, true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_NORMAL, WEAPON_TYPE_CLAW_HEAVY_SLICE)
call GroupClear(bj_lastCreatedGroup)
else
call GroupRemoveUnit(bj_lastCreatedGroup, t)
endif
endloop

set u = null
set p = null
endfunction

//===========================================================================
function InitTrig_Attack takes nothing returns nothing
set gg_trg_Attack = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( gg_trg_Attack, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Attack, Condition( function Attack_Conditions ) )
call TriggerAddAction( gg_trg_Attack, function Attack_Actions )
endfunction``````

172 is the max collision size of a unit in your map, the 150 is the range.

#### Klann

Level 9
I dont understand jass.

but i do know that it requires a spell id so the script would only work on a certain ability.
" return GetSpellAbilityId() == 'Acrs' " <- what is Acrs for?

#### PurgeandFire

Level 44
That is the rawcode object ID of the ability you want to register the cast of. It is a 4 character code enclosed in single quotes. `'XXXX'` You can find an object's rawcode by finding it in the object editor, and then pressing CTRL+D. Then just look where its name is.

Example:

`'Amls'` is the rawcode ID of the aerial shackles ability.

#### Klann

Level 9
some text appearing after using the skill only when hitting an enemy unit
`UNIT INDEX ERROR : ATTEMPT TO LOCK NULL INDEX
`UNIT INDEX ERROR : ATTEMPT TO UNLOCK UNLOCKED INDEX

Also how do i add an animation attack in jass?

#### mckill2009

Level 29
see my map Fog Horror, its an open source...it has a custom ranged & melee attack, you just need to adjust the damage...

#### Klann

Level 9
still having the same problem
`UNIT INDEX ERROR : ATTEMPT TO LOCK NULL INDEX
`UNIT INDEX ERROR : ATTEMPT TO UNLOCK UNLOCKED INDEX

mckill and makers spell work fine with damage and everything, but wont play my unit's attack animation. maybe there's a problem with my other triggers?

Replies
3
Views
2K
Replies
5
Views
563
Replies
8
Views
2K
Replies
2
Views
478