Mình làm ngẫu nhiên rơi ra 1 trong 4 loại rune đó
Thú thật là mình có biết gì đâu,mình chỉ đơn thuần làm theo cách spawn unit thôi

Giờ mình muốn hỏi làm điều kiện sao cho khi nó xuất hiện rồi,fải có có người tới nhặt rune xong thì nó xuất hiện tiếp.
Chứ mình làm nó cứ tự ra một đống theo thời gian T_T
Tìm cách làm = GUI mãi không ra.. nên thử làm với JASS.
Giờ làm như thế này.
Đầu tiên tạo một Trigger để Create các Item mà bạn muốn.
PHP:
Runes
Events
Map initialization
Conditions
Actions
Item - Create Rune of Greater Healing at (Center of Rect[(Random integer number between 1 and 4)])
Set TempItem[1] = (Last created item)
Item - Create Rune of Shielding at (Center of Rect[(Random integer number between 1 and 4)])
Set TempItem[2] = (Last created item)
Item - Create Rune of Speed at (Center of Rect[(Random integer number between 1 and 4)])
Set TempItem[3] = (Last created item)
Item - Create Rune of the Watcher at (Center of Rect[(Random integer number between 1 and 4)])
Set TempItem[4] = (Last created item)
Như ví dụ trên là 4 Item. Ban đầu ta đặt cho nó là như thế này. không thể đưa nó vào vòng Loop vì 4 Item khác loại nhau.
Tạo một biến TempItem (với type là item, click Array cho nó)
Tiếp theo Copy đoạn Code Jass dưới đây vào 1 Trigger mới.
Để làm điều này thì Tạo 1 Trigger mới, tên gì cũng được ... Chọn Edit -> Convert to Custom Script.
Xong xóa hết trong đó và copy toàn bộ dưới đây vào
PHP:
scope ItemAdd initializer Init
private function CheckCond takes nothing returns boolean
local integer Int
set Int = 1
loop
exitwhen Int > 4
if ( ( GetItemTypeId(GetManipulatedItem()) == GetItemTypeId(udg_TempItem[Int]) ) ) then
return true
endif
set Int = Int + 1
endloop
return false
endfunction
private function Conditions takes nothing returns boolean
if ( not CheckCond() ) then
return false
endif
return true
endfunction
private function Actions takes nothing returns nothing
local integer a
local integer b =1
loop
exitwhen b>4
if GetItemTypeId(GetManipulatedItem())== GetItemTypeId(udg_TempItem[b]) then
set a = b
endif
set b = b+1
endloop
call TriggerSleepAction(5)
call CreateItemLoc( GetItemTypeId(udg_TempItem[a]), GetRectCenter(udg_Rect[GetRandomInt(1, 4)]) )
endfunction
//===========================================================================
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddCondition( t, Condition( function Conditions ) )
call TriggerAddAction( t, function Actions )
set t = null
endfunction
endscope
Bây giờ mình thử phân tích đoạn trên để bạn có thể hiểu và áp dụng.
Mã:
private function CheckCond takes nothing returns boolean
local integer [COLOR="#FF0000"]Int [/COLOR]
set[COLOR="#FF0000"] Int[/COLOR] = 1
loop
exitwhen [COLOR="#FF0000"]Int[/COLOR] > 4
if ( ( GetItemTypeId(GetManipulatedItem()) == GetItemTypeId(udg_TempItem[[COLOR="#FF0000"]Int[/COLOR]]) ) ) then
return true
endif
set [COLOR="#FF0000"]Int[/COLOR] = [COLOR="#FF0000"]Int[/COLOR] + 1
endloop
return false
endfunction
Đoạn trên này là điều kiện được Convert từ đoạn GUI này ra.
Conditions
Or - Any (Conditions) are true
Conditions
(Item-type of (Item being manipulated)) Equal to (Item-type of TempItem[1])
(Item-type of (Item being manipulated)) Equal to (Item-type of TempItem[2])
(Item-type of (Item being manipulated)) Equal to (Item-type of TempItem[3])
(Item-type of (Item being manipulated)) Equal to (Item-type of TempItem[4])
Bạn hiểu nó đúng không . Cái này là điều kiện xem xem Unit đó nhặt Item số mấy mà mình đã lưu lại ở Trigger trên kia.
Nếu có nhiều Item hơn thì ta có thể thay đổi đoạn này.
Mã:
[B]exitwhen[/B][COLOR="#0000FF"] Int [/COLOR]> X
Với X là số Item mà bạn đã đặt ở Trigger trên.
Tiếp đến mình xuống Function này.
PHP:
private function Actions takes nothing returns nothing
local integer a
local integer b =1
loop
exitwhen b>4
if GetItemTypeId(GetManipulatedItem())== GetItemTypeId(udg_TempItem[b]) then
set a = b
endif
set b = b+1
endloop
call TriggerSleepAction(5)
call CreateItemLoc( GetItemTypeId(udg_TempItem[a]), GetRectCenter(udg_Rect[GetRandomInt(1, 4)]) )
endfunction
Ở đây cũng tương tự. Nếu số Item của bạn lớn hơn 4.. bạn có thể thay đổi số 4 ở trong này thành số lượng Item mà bạn đặt ở Trigger đầu.
Trọng đoạn này. Số 5 là số thời gian mà nó sẽ tạo lại một Item mới cho bạn ở vị trí Random như bạn nói. Nếu muốn thay đổi thời gian thì cứ đổi số 5 thành số nào tùy bạn.
PHP:
call TriggerSleepAction(5)
Thế là xong.. Chỉ cần thay đổi các giá trị mình đề cập để làm điều bạn muốn. Chúc thành công
---------- Post added at 18:50 ---------- Previous post was at 18:48 ----------
Tặng bạn cái Maps này.. đây là Những gì mà mình nêu ở trên.
---------- Post added at 18:52 ---------- Previous post was at 18:50 ----------
À quên.. mở maps = NEWGEN nha.. JassHelper mới nhất ... như vậy mới mở được/