[Tutorial]Learn Abilities Through Items (Học Abilities Qua Items)

game_war48

Dragon Quest
Tham gia ngày
7/9/08
Bài viết
1,320
Reaction score
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):
attachment.php

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:
attachment.php

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
Tôi sẽ giải thích Trigger trên. Bây giờ nếu Unit nào đó mua Item Summon Infernal thì nó sẽ thêm Ability Inferno cho Unit đó. Bạn phải tạo mỗi Trigger tương ứng với mỗi Ability.
Mã:
Conditions
    (Item-type of (Item being manipulated)) Equal to Summon Infernal
Dòng điều kiện này rất quan trọng. Nếu như kô có nó thì khi Unit mua bất cứ Item nào thì Ability Inferno sẽ đc add cho Unit đó, chắc chắn bạn sẽ kô muốn điều này, phải kô:)?
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
Trigger này gần giống với trigger Infernal, tuy nhiên, nó đã đc thêm vài dòng. "Vài dòng" ấy đảm nhiệm việc tăng Level của Ability Dark Ritual sau lần học thứ nhất (Mua Item lần thứ nhất Dark Ritual sẽ có level 1, lần thứ hai là level 2, ....). Để thay đổi Level của Dark Ritual sẽ học đc thông qua mua Item này thì ta sẽ sửa số 3 ở dòng sau:
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]
Và nếu Level của Dark Ritual kô nhỏ hơn 3 mà vẫn tiếp tục mua Item thì sẽ trả lại số Gold Cost (Bạn phải thay đổi số 100 = số Gold Cost của Item đó).

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 --------
Chúng ta sẽ tạo một vài Variables, gồm:
_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ột Unit nhận đc một Item, điều này hầu hết đều đc diễn ra trong tất cả các games. Bây giờ chúng ta sẽ đi vào ruột của trigger (Acticons). Trước khi chúng ta làm điều đó, phải chắc chắn rằng Item đc mua trong Shop (Dark Ritual, Summoning Infernal) đã có thể loại riêng (Class), tôi sẽ lựa chọn Class Power Up. Bây giờ sẽ tạo điều kiện này:
Mã:
(Item-class of (Item being manipulated)) Equal to Powerup
Dòng điều kiện này dùng để kiểm tra Item đc mua thuộc Class Power Up. Để hoàn tất Trigger này, chúng ta sẽ thực hiện Acticons sau:
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
Đã đính kèm map demo ở dưới, ai kô hiểu gì cứ hỏi:).

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.
 

Attachments

Cám ơn bác gamewar rất nhiều, bài viết rất hữu ích và dễ hiểu với newbie như em, hiện giờ em đang test thử theo chỉ dân của bác. Cám ơn bác nhiều nha!
 
Ờ đừng test cách 2 vội, test cách 1 trước, hình như cách 2 đang có vấn đề (sửa trong vòng sáng nay thôi, trưa vào test cách 2 sau).
 
Cảm ơn anh Tom, em cũng vừa sửa xong cái Tut=)).
P/s: Mọi người cứ đóng góp ý kiến nhiệt tình để góp phần hoàn thiệt Tut nhé:D.
 
Thank a war nhé....Thế là có thêm hệ thống mới :">...
 
làm thế nào để 1 hero chỉ học được 5 skill thôi bạn?

ai giúp dùm mình cái............
 
Last edited by a moderator:
5 skill :-? thế cứ set số item abi cho riêng hero :-? rồi set số max item sử dụng nhất định xem sao.
 
đọc từ trên xuống ... ko hiểu gì lun .. công nhận mình ngu thật
 
== cái này có j đâu mà không hiểu, chi tiết thế rồi còn gì :-? quan sát mấy cái trigger :-? với text là đc thôi,
 
Back
Top