Tom sẽ hướng dẫn lại cách tạo 1 auto cast spell. Cụ thể là spell Impetus (DotA)
Impetus: hero làm mục tiêu mất nhiều máu hơn, phụ thuộc vào khoảng cách giữa hero và mục tiêu
---
Đầu tiên, vào Object Editor:
- Buffs/Effects: tạo 1 custom buff, base từ Poison (stacking). Đổi tên, đổi icon...
- Abilities: tạo 1 custom ability, base từ Poison Arrows (tìm thấy trong abilities của Neutral Hostile). Chỉnh lại các dữ liệu của Poison Arrows như sau:
Icon: ReplaceableTextures\CommandButtons\BTNImpalingBolt.blp
Sau đó vào Trigger Editor:
Tôi sẽ nói sơ qua cách làm như sau: Ta phải có 1 trigger mà trigger này sẽ hoạt động khi 1 unit "take damage" (nhận sát thương). Và nếu unit đó có buff Impetus thì sẽ deal thêm damage, phụ thuộc vào khoảng cách giữa unit đó và thằng deal dam (Damage Source).
Chú ý: Cho dù spell này đc cast hay để auto (attack ấy) thì nếu đánh trúng thì unit sẽ có buff, cho nên ko lo lỗi gì cả, mà hoàn toàn MUI. Vì khi có buff, ta sẽ remove buff đó luôn, và có Damage Source rõ ràng nên ko lo 2 unit đánh 1 unit sẽ nhầm lẫn.
Vì trigger ko có event: "Generic unit take damage" chỉ có "Specific unit take damage". Nên ta sẽ pick từng unit rồi add event cho trigger cần dùng, pick unit là "specific" rồi đó.
Trigger thứ 1:
Ta cần 2 biến unit group, TempGroup và TakeDamGroup. Khi 1 unit đã có event take damage rồi thì phải add vào TakeDamGroup (để biết là nó "đã có event") nếu add event 2 lần thì sẽ lỗi, unit đó sẽ take 2 lần damage.
Trigger này để add event cho các unit đã đc đặt sẵn.
Trigger này là khi 1 unit "đi" vào bản đồ, cho dù là đc summon, create (trigger),... Tất nhiên vẫn phải kiểm tra xem unit này đã ở trong TakeDamGroup chưa, nếu chưa thì mới add. (cẩn thận vẫn hơn)
Trigger này là trigger chính đây.
Variable:
TempUnit, TempUnit2 - unit,
TempLoc, TempLoc2 - point
TempInt - integer
TempReal - real
Trigger này chưa có event, nhưng event đã đc add nhờ 2 trigger trên. Bây giờ có "event a unit takes damage" rồi.
Đối với event này thì có: (Triggering unit) là unit bị mất máu (một trong những unit đã add event ấy). (Damage source) là unit deal damage.
Trước hết phải turn off trigger này, rồi turn on sau khi xong. Ko turn off sẽ có chuyện ko hay xảy ra.
Sau đó kiểm tra xem Damage source có ability Impetus ko (level > 0), rồi kiểm tra Triggering unit có buff ko. (thật ra chỉ cần điều kiện này thôi, ko cần nhiều)
Nếu Trigger unit có buff, tức là bị Damage source làm mất máu khi dùng Impetus. Vậy ta sẽ cho Damage source deal thêm damage theo khoảng cách giữa 2 unit này. Có số damage rồi thì dùng floating text để show và dùng Unit - Damage Target để deal damage thôi. Nhớ là pure damage thì nên dùng ATTACK_TYPE_CHAOS và DAMAGE_TYPE_UNIVERSAL.
Đến đây thì đã xong rồi, từ cách làm này các bạn có thể tạo các auto cast spell mà mình muốn. Hoặc vài spell như trong DotA: Glaive of Wisdom (deal damage = % Int ) Arcane Orb (deal damage = % current mana)
----
-----
BONUS SPELLS:
Thêm 1 spell nữa nhá. Ai chơi DotA 6.53 rồi sẽ biết Magina ( Anti Mage ) có cái blink rất "ảo" (nhiều người cho rằng rất "cool", tôi cũng nghĩ thế, chỉ hơi thiếu tí sound thôi)
Ta cần các biến sau:
InstantMovementCaster, InstantMovementDummy - unit //caster và dummy
InstantMovementFade - real //đây là biến đếm cho việc "mờ" của dummy và caster
InstantMovementBlink - boolean //biến này để kiểm tra xem caster đã cast xong chưa, xong rồi thì mới hiện dummy và bắt đầu "mờ" dummy, caster.
Cần 4 trigger (

)
Mã:
InstantMovementBegin
Events
Unit - A unit Begins casting an ability
Conditions
(Ability being cast) Equal to Instant Movement
Actions
Set InstantMovementCaster = (Casting unit)
Set TempLoc = (Position of InstantMovementCaster)
Set TempLoc2 = (Target point of ability being cast)
Unit - Create 1 Dummy Instant Movement for (Owner of InstantMovementCaster) at TempLoc facing (Angle from TempLoc to TempLoc2) degrees
Set InstantMovementDummy = (Last created unit)
Animation - Play InstantMovementDummy's spell throw animation
Animation - Change InstantMovementDummy's vertex coloring to (100.00%, 100.00%, 100.00%) with 100.00% transparency
Custom script: call RemoveLocation( udg_TempLoc )
Custom script: call RemoveLocation( udg_TempLoc2 )
Vì vấn đề animation nên ta phải tạo dummy ngay từ lúc caster bắt đầu cast. Nhưng lúc này phải cho transperency của dummy = 100% (ko nhìn thấy gì) và bắt dummy thực hiện động tác (animation) "spell throw" như caster.
Mã:
InstantMovementBlink
Events
Unit - A unit Starts the effect of an ability
Conditions
(Ability being cast) Equal to Instant Movement
Actions
Set InstantMovementFade = 50.00
Set InstantMovementBlink = True
Animation - Change InstantMovementCaster's vertex coloring to (100.00%, 100.00%, 100.00%) with 50.00% transparency
Animation - Change InstantMovementDummy's vertex coloring to (100.00%, 100.00%, 100.00%) with 50.00% transparency
Trigger - Turn on InstantMovementTimer <gen>
Start effect, tức là đã caster đã cast xong (bây giờ đã move rồi). Vậy thì hiện dummy ra với 1 nữa transperency và caster cũng phải "mờ" đi 1 nửa. Bậy trigger "mờ" dummy và caster lên. Nhớ rằng biến InstantMovementBlink phải = true (vì đã cast xong)
Mã:
InstantMovementStop
Events
Unit - A unit Stops casting an ability
Conditions
(Ability being cast) Equal to Instant Movement
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
InstantMovementBlink Equal to False
Then - Actions
Unit - Remove InstantMovementDummy from the game
Else - Actions
stop casting là dừng cast, có thể là cast xong, có thể là bị stun chẳng hạn, nói chung là bị interrupt (gián đoạn

, "cắt cơn" ấy :'> ) Nếu chưa cast xong thì remove dummy, ko thì thôi.
Mã:
InstantMovementTimer
Events
Time - Every 0.01 seconds of game time
Conditions
Actions
Set InstantMovementFade = (InstantMovementFade + 1.00)
Animation - Change InstantMovementCaster's vertex coloring to (100.00%, 100.00%, 100.00%) with (100.00 - InstantMovementFade)% transparency
Animation - Change InstantMovementDummy's vertex coloring to (100.00%, 100.00%, 100.00%) with InstantMovementFade% transparency
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
InstantMovementFade Equal to 100.00
Then - Actions
Unit - Remove InstantMovementDummy from the game
Trigger - Turn off (This trigger)
Else - Actions
Sau khi cast xong thì bật trigger này, cứ 0.01s dummy sẽ mờ đi 1% và caster sẽ hiện rõ hơn 1%.
50 + 1 = 51 -> 100 - 50 = 49 => số này nhỏ dần, caster sẽ hiện ra dần dần
Khi InstantMovementFade = 100 tức là dummy đã mờ hẳn và caster đã hiện ra rõ hẳn.
Đến đây đã xong.
PS: à mà spell này ko MUI nhg tôi nghĩ blink chỉ trong 0.33s nên ko có vấn đề gì to lớn. Mà nếu ko chắc thì có lẽ tôi sẽ nghĩ ra cách làm cho MUI.
---
Hy vọng mọi người hiểu.
Tom đã gửi kèm map demo.