game_war48
Dragon Quest
- 7/9/08
- 1,320
- 6
Learn Abilities Through Items
1.Giới thiệu:Sau bài này, tôi sẽ hướng dẫn cho bạn để thực hiện một hệ thống cho phép người sử dụng học đc một Ablities thông qua việc mua Items từ các Shops (điển hình về hệ thống này là map hoihoi8s). Trong bài này, tôi sẽ sử dụng 2 Abilities Dark Ritual và Inferno để hướng dẫn.
I.Hướng dẫn:
Bước 1: Chuẩn bị Items
Trước hết, chúng ta sẽ tạo các Items tương ứng với mỗi Abilities (Lưu ý chỉ tạo các Custom Items này từ Class Items Power Up):
Những Items này cho người mua biết những thông tin về Ability mà khi mua sẽ có. Tôi sẽ sử dụng các Items này cho các Icons, Tooltip, Gold/Lumber Cost và các thông tin khác cần thiết cho map của bạn.
Cách thứ nhất:
Bước 2: Chuẩn bị Variables
Tiếp theo, chúng ta sẽ làm việc với triggers. Trước khi làm việc với triggers, chúng ta phải chuẩn bị các Variables sau:
Sau khi chuẩn bị xong, chúng ta sẽ thực hiện với các triggers.
1.Đối với Abilities chỉ có 1 level:
Mã:
Infernal
Events
Unit - A unit Acquires an item
Conditions
(Item-type of (Item being manipulated)) Equal to Summon Infernal
Actions
Set Units = (Triggering unit)
Set Ability[(Player number of (Owner of Units))] = Inferno
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Ability[(Player number of (Owner of Units))] for (Triggering unit)) Less than 1
Then - Actions
Unit - Add Ability[(Player number of (Owner of Units))] to (Triggering unit)
Game - Display to (Player group((Owner of Units))) for 10.00 seconds the text: You have bought the...
Else - Actions
Game - Display to (Player group((Owner of Units))) for 5.00 seconds the text: You already have th...
Player - Add 350 to (Owner of Units) Current lumber
Mã:
Conditions
(Item-type of (Item being manipulated)) Equal to Summon Infernal
2.Đối với Abilities có nhiều level:
Đối với ví dụ này, tôi sẽ sử dụng Ability Dark Ritual.
Một lần nữa, chúng ta sẽ tạo 1 Item Dark Ritual giống như Item Summon Infernal đối với Inferno vậy (Bước này tôi sẽ kô hướng dẫn nữa vì nó gần như giống với bước tạo Item Summon Infernal trên).
Mã:
Dark Ritual
Events
Unit - A unit Acquires an item
Conditions
(Item-type of (Item being manipulated)) Equal to Dark Ritual
Actions
Set Units = (Triggering unit)
Set Ability[(Player number of (Owner of Units))] = Dark Ritual
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Ability[(Player number of (Owner of Units))] for Units) Less than 1
Then - Actions
Unit - Add Ability[(Player number of (Owner of Units))] to Units
Game - Display to (Player group((Owner of Units))) for 10.00 seconds the text: Dark Ritual Learned...
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Ability[(Player number of (Owner of Units))] for Units) Less than 3
Then - Actions
Unit - Increase level of Ability[(Player number of (Owner of Units))] for Units
Game - Display to (Player group((Owner of Units))) for 5.00 seconds the text: (Dark Ritual's Level + ( is + ( + (String((Level of Dark Ritual for Units))))))
Else - Actions
Game - Display to (Player group((Owner of Units))) for 5.00 seconds the text: This spell is alrea...
Player - Add 100 to (Owner of Units) Current lumber
Mã:
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Ability[(Player number of (Owner of Units))] for Units) Less than [B][I]3[/I][/B]
Cách thứ hai:
Đôi khi, chúng ta có quá nhiều Abilities, ví dụ tôi có 100 Abilities thì phải tạo những.... 100 triggers. Như vậy sẽ rất tốn công sức và dung lượng map. Tuy nhiên, nếu chúng ta dùng cách này, cho dù có tới 1000 Abilities đi nữa thì chúng chỉ nằm gọn trong 2 triggers mà thôi. Cách này đòi hỏi bạn phải thật thành thạo về các biến (variables). Nếu bạn kô thành thạo về chúng thì tôi có một lời khuyên là: Nên sử dụng cách thứ nhất!
1.Thiết lập biến:
Mã:
Set Variables
Events
Map initialization
Conditions
Actions
-------- Chúng ta sẽ set các biến tại đây --------
_Abilities (Biến Ability có Array).
_Items (Biến Item có Array).
_Lumber (Biến Integer có Array).
_Level (Biến Integer có Array).
_ItemAbilityCount (Biến Integer kô Array).
Ngay bây giờ, chúng ta sẽ lưu các Items, Abilities và Lumber Cost của Item trong các biến mà chúng ta vừa tạo:
Mã:
Set Variables
Events
Map initialization
Conditions
Actions
Set ItemAbilityCount = -1
-------- Inferno --------
Set ItemAbilityCount = (ItemAbilityCount + 1)
Set Abilities[ItemAbilityCount] = Inferno
Set Items[ItemAbilityCount] = Summon Infernal
Set Lumber[ItemAbilityCount] = Lumber Cost của Item Summon Infernal (350)
Set Level[ItemAbilityCount] = Level của Ability Inferno (1)
-------- Dark Ritual --------
Set ItemAbilityCount = (ItemAbilityCount + 1)
Set Abilities[ItemAbilityCount] = Dark Ritual
Set Items[ItemAbilityCount] = Dark Ritual
Set Lumber[ItemAbilityCount] = Lumber Cost của Item Dark Ritual (100)
Set Level[ItemAbilityCount] = Level của Ability Dark Ritual (3)
Khi mới bắt đầu, chúng ta Set ItemAbilityCount = ItemAbilityCount - 1. Tức là ItemAbilityCount lúc đầu có giá trị là -1. Đến phần lưu thông tin biến của Ability Inferno thì nó đc + thêm 1 (tức là nó sẽ = 0) và tất cả Array biến lưu trữ thông tin của Ability Inferno đều là 0.
Đên phần lưu thông tin biến của Ability Dark Ritual thì nó lại đc + thêm 1 (tức là nó sẽ = 1) và tất cả Array biến lưu trữ thông tin của Ability Dark Ritual đều là 1.
Tương tự với các Abilities sau.
Bước thứ hai - Trigger:
Chúng ta muốn khi Unit mua Item nào đó thì sẽ Add Ability tương ứng cho Unit đó (hình như hơi nhiều từ "đó" thì phải
). Vì vậy, chúng ta sẽ tạo một trigger mới. Event sẽ như sau:
Mã:
Unit - A unit Acquires an item
Mã:
(Item-class of (Item being manipulated)) Equal to Powerup
Mã:
Learn Ability
Events
Unit - A unit Acquires an item
Conditions
(Item-class of (Item being manipulated)) Equal to Powerup
Actions
Set TempUnit = (Triggering unit)
Set TempItem = (Item being manipulated)
For each (Integer A) from 0 to ItemAbilityCount, do (Actions)
Loop - Actions
Set TempInt = (Integer A)
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Items[TempInt] Equal to (Item-type of TempItem)
Then - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Abilities[TempInt] for TempUnit) Less than 1
Then - Actions
Unit - Add Abilities[TempInt] to TempUnit
Set TempForce = (Player group((Owner of TempUnit)))
Game - Display to TempForce the text: ((|c0000FFFF + (Name of Abilities[TempInt])) + |r learned.)
Custom script: call DestroyForce( udg_TempForce )
Special Effect - Create a special effect attached to the origin of TempUnit using Abilities\Spells\Items\AIem\AIemTarget.mdl
Special Effect - Destroy (Last created special effect)
Custom script: exitwhen true
Else - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Level[TempInt] Greater than 1
Then - Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
(Level of Abilities[TempInt] for TempUnit) Less than Level[TempInt]
Then - Actions
Unit - Increase level of Abilities[TempInt] for TempUnit
Set TempForce = (Player group((Owner of TempUnit)))
Game - Display to TempForce for 5.00 seconds the text: ((((|c0000FFFF + (Name of Abilities[TempInt])) + |r) + 's Level) + ( is increased to |c00540081 + (String((Level of Abilities[TempInt] for TempUnit)))))
Custom script: call DestroyForce( udg_TempForce )
Special Effect - Create a special effect attached to the origin of TempUnit using Abilities\Spells\Items\AIlm\AIlmTarget.mdl
Special Effect - Destroy (Last created special effect)
Custom script: exitwhen true
Else - Actions
Set TempForce = (Player group((Owner of TempUnit)))
Game - Display to TempForce for 5.00 seconds the text: (|c0000FFFF + ((Name of Abilities[TempInt]) + |r's maximum level reached.))
Custom script: call DestroyForce( udg_TempForce )
Player - Add Lumber[(Integer A)] to (Owner of TempUnit) Current lumber
Skip remaining actions
Else - Actions
Set TempForce = (Player group((Owner of TempUnit)))
Game - Display to TempForce for 5.00 seconds the text: (|c0000FFFF + ((Name of Abilities[TempInt]) + |r's maximum level reached.))
Custom script: call DestroyForce( udg_TempForce )
Player - Add Lumber[TempInt] to (Owner of TempUnit) Current lumber
Else - Actions
Credit for PurplePoot in Hiveworkshop. His Tutorial here (But His Tutorial has very a lot of error in the second way).
Thank Tom because he help me in the second way.
Translated and Edited by game_war48.
.
.
...
thế cứ set số item abi cho riêng hero