game_war48
Dragon Quest
- 7/9/08
- 1,320
- 6
@Kingwar:
[spoil]
Như đoạn code trên, Sau khi mỗi Peasant create ở trong loop (scope 1) thì đc "save" vào biến globals array UNITP. Và Peasant sẽ bị kill ở scope 2. [/spoil]
----------------------------------------------
@Zhenghe: Xem post này: http://forum.gamevn.com/showpost.php?p=15877471
[spoil]Đoạn code đấy thiếu và sai rất nhiều.
Dùng Jassnewgen, native này kô có
thì nó kô hiện lên màu (ngoại trừ một số native ở 1.24, jassnewgen chưa cập nhật). Native đúng của nó phải là
Và function này:
có:
Tiếp, 2 function còn lại. Xem sơ qua thì function Dummy_Attach_Target là để move dummy unit sát với target, function Dummy_Wraith_Count là để deals damage. Có thể gộp 2 function này lại làm 1. Nhưng trước hết sửa lỗi ở function Dummy_Wraith_Count đã.
Trở lại việc gộp 2 function kia. Spell này mỗi 1 giây deals damage 1 lần đúng kô ? Giờ tạo thêm 1 biến integer ở struct, đặt tên là tick.
Thêm tick, bỏ loc đi:
Ngừng ở đây, kô chữa nữa, làm lại cái mới thôi.
[/spoil]
[spoil]
Mã:
globals
unit array UNITP
endglobals
scope CreateUnits initializer IntCreateUnit
function Create_Actions takes nothing returns nothing
local integer i = 1
loop
exitwhen i > 50
set UNITP[i] = CreateUnitAtLoc(Player(0),'hpea',Location(320,25),270)
call TriggerSleepAction( 0. )
set i = i + 1
endloop
endfunction
function IntCreateUnit takes nothing returns nothing
local trigger Create = CreateTrigger()
call TriggerRegisterTimerEventSingle( Create, 5 )
call TriggerAddAction(Create, function Create_Actions)
endfunction
endscope
scope GameInfo initializer InitTrig
function Trig_Actions takes nothing returns nothing
local integer i
call DisplayTimedTextToPlayer( Player( 0 ), 0., 0., 30., "Create Peasant !")
call TriggerSleepAction( 3. )
call DisplayTimedTextToPlayer( Player( 0 ), 0., 0., 30., "Kill Peasant !")
set i = 1
loop
exitwhen i > 50
call KillUnit( UNITP[i] )
call DisplayTimedTextToPlayer( Player( 0 ), 0., 0., 30., "Killed " + I2S( i ) + " Peasant !")
call TriggerSleepAction( 0.1 )
set i = i + 1
endloop
endfunction
function InitTrig takes nothing returns nothing
local trigger Trig = CreateTrigger()
call TriggerRegisterTimerEventSingle(Trig,3)
call TriggerAddAction(Trig, function Trig_Actions)
endfunction
endscope
Như đoạn code trên, Sau khi mỗi Peasant create ở trong loop (scope 1) thì đc "save" vào biến globals array UNITP. Và Peasant sẽ bị kill ở scope 2. [/spoil]
----------------------------------------------
@Zhenghe: Xem post này: http://forum.gamevn.com/showpost.php?p=15877471
[spoil]Đoạn code đấy thiếu và sai rất nhiều.
Dùng Jassnewgen, native này kô có
Mã:
call [B]AddSpecialEffectTargetUnit[/B]( "chest", data.target, data.sfx)
Mã:
call[B] AddSpecialEffectTarget[/B]( "chest", data.target, data.sfx)
Và function này:
Mã:
function Thunder_Wraith_Setup takes unit caster, unit target, unit dummy, integer int, string sfx, location loc returns nothing
local TS data = TS.create()
local timer t1 = NewTimer()
local timer t2
set data.caster = GetSpellAbility()
set data.target = GetSpellTargetUnit()
set loc = GetUnitLoc (data.target)
set data.sfx = "Abilities\Spells\Orc\LightningShield\LightningShieldBuff.mdl"
set data.int = 3
set data.dummy = CreateNUnitsAtLoc ( 1, 'e001', GetOwningPlayer(data.caster), GetUnitLoc(data.target), 0.00)
call TimerStart( t1, (I2R(4/3) ), true, function Thunder_Wraith_Count)
call TimerStart( t2, 0.03 ), true, function Dummy_Attach_Target)
set t1 = null
set t2 = null
endfunction
có:
1/timer t1 thì có NewTimer() mà timer t2 thì lại bỏ trống ? Như vậy chẳng phải là toàn bộ những thứ gì dính dáng đến timer t2 đều vô giá trị à ?Mã:local timer t1 = NewTimer() local timer t2
2/Dùng Jassnewgen, muốn xem native như thế nào thì bấm Ctrl + Chuột trái vào cái native đó. Native GetSpellAbility như sau:Mã:set data.caster = GetSpellAbility()
Để ý cái phần bôi đên, tức là native này sẽ trả 1 giá trị ability, còn data.caster thì là unit, set unit = ability ? Nếu muốn lấy caster thì dùng native GetTriggerUnit.Mã:constant native GetSpellAbility takes nothing [B]returns ability[/B]
3/Cũng như trên, nếu dùng BJ CreateNUnitsAtLoc thì sẽ trả group, set unit = group ? Trong trường hợp này, phải dùng native CreateUnitAtLoc:Mã:set data.dummy = CreateNUnitsAtLoc ( 1, 'e001', GetOwningPlayer(data.caster), GetUnitLoc(data.target), 0.00)
Mã:set data.dummy = CreateUnitAtLoc ( 'e001', GetOwningPlayer(data.caster), GetUnitLoc(data.target), 0. )
4/loc ở đây là cái gì mài set = GetUnitLoc( data.target ) ? Chưa local, chưa gì cả mà đã set luôn rồi.Mã:set loc = GetUnitLoc (data.target)
hoặcMã:local location loc = GetUnitLoc( data.target )
Kô thấy function nào gọi function này, mà function này chỉ chạy khi cast spell, thế thì mấy cái kia có cần thiết kô ?Mã:local location loc ........... set loc = GetUnitLoc( data.target ) [code] (local phải luôn luôn ở đầu function). Sau đó nhớ [B]call RemoveLocation( loc )[/B] và [B]set loc = null[/B] 5/Và ở tên function [code]function Thunder_Wraith_Setup [B]takes unit caster, unit target, unit dummy, integer int, string sfx, location loc[/B]returns nothing
6/Tên struct ở trên là TW, ở dưới lại
?Mã:local TS data = TS.create()
7/Phần trigger Init,
Mà sao kô thấy function nào tên là Thunder_Wraith_Actions ?Mã:call TriggerAddAction( gg_trg_t, function Thunder_Wraith_Actions )
8/Cả cái lệnh này nữa
Chả thấy function nào tên là Thunder_Wraith_Count cả.Mã:call TimerStart( t1, (I2R(4/3) ), true, function [B]Thunder_Wraith_Count[/B])
9/Đang dùng TimerUtils phải kô ? Muốn lưu struct thì phải có dòng SetTimerData đã (cái này trong TimerUtils có, kèm cả GetTimerData để lấy struct nữa):
Mã:call SetTimerData( timer, data )
Sửa hết tất cả lỗi cho function này thì đc:
Mã:function Thunder_Wraith_Actions takes nothing returns nothing local TW data = TW.create() local timer t1 = NewTimer() local timer t2 = NewTimer() local location loc set data.caster = GetTriggerUnit() set data.target = GetSpellTargetUnit() set loc = GetUnitLoc( data.target ) set data.sfx = "Abilities\Spells\Orc\LightningShield\LightningShieldBuff.mdl" set data.int = 3 set data.dummy = CreateUnitAtLoc( 'e001', GetOwningPlayer(data.caster), GetUnitLoc(data.target), 0. ) call SetTimerData( t1, data ) call SetTimerData( t2, data ) call TimerStart( t1, (I2R(4/3) ), true, function Dummy_Wraith_Count) call TimerStart( t2, 0.03 ), true, function Dummy_Attach_Target) call RemoveLocation( loc ) set loc = null set t1 = null set t2 = null endfunction
Tiếp, 2 function còn lại. Xem sơ qua thì function Dummy_Attach_Target là để move dummy unit sát với target, function Dummy_Wraith_Count là để deals damage. Có thể gộp 2 function này lại làm 1. Nhưng trước hết sửa lỗi ở function Dummy_Wraith_Count đã.
Mã:
function Dummy_Wraith_Count takes nothing returns nothing
local timer t1 = GetExpiredTimer()
call UnitAddAbility( 'A006', data.dummy)
call IssueTargetOrder( data.dummy, "chainlightning", data.target)
call AddSpecialEffectTarget( "chest", data.target, data.sfx)
call DestroyEffect( GetLastCreatedEffect() )
call UnitDamageTarget( data.caster, data.target, ((35*I2R(GetUnitAbilityLevel(data.caster, 'A004')))+ 15),true,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS)
set data.int = (data.int - 1)
if data.int <= 0 then
call data.destroy()
call ReleaseTimer(t1)
endif
set t1 = null
endfunction
1/ Chưa có cái gì liên quan đến data cả, sao mà dùng ngay đc ? Phải lấy "data" từ struct TW đã
Mã:local timer t1 = GetExpiredTimer() local TW data = GetTimerData( t1 )
2/Hai dòng này có thể gộp lại làm mộtMã:call AddSpecialEffectTarget( "chest", data.target, data.sfx) call DestroyEffect( GetLastCreatedEffect() )
Mà vốn dĩ, chả có native hay BJ nào là GetLastCreatedEffect cả >> saiMã:call DestroyEffect( AddSpecialEffectTarget( "chest", data.target, data.sfx ) ).
3/Sao kô Add luôn lúc tạo dummy ? Ở function Thunder_Wraith_Actions ấy (sau khi tạo dummy thì add vào).Mã:call UnitAddAbility( 'A006', data.dummy)
Tổng kết:
Mã:function Dummy_Wraith_Count takes nothing returns nothing local timer t1 = GetExpiredTimer() local TW data = GetTimerData( t1 ) call IssueTargetOrder( data.dummy, "chainlightning", data.target) call DestroyEffect( AddSpecialEffectTarget( "chest", data.target, data.sfx ) ) call UnitDamageTarget( data.caster, data.target, ((35*I2R(GetUnitAbilityLevel(data.caster, 'A004')))+ 15),true,false,ATTACK_TYPE_MAGIC,DAMAGE_TYPE_NORMAL,WEAPON_TYPE_WHOKNOWS) set data.int = data.int - 1 if data.int <= 0 then call data.destroy() call ReleaseTimer( t1 ) endif set t1 = null endfunction
Trở lại việc gộp 2 function kia. Spell này mỗi 1 giây deals damage 1 lần đúng kô ? Giờ tạo thêm 1 biến integer ở struct, đặt tên là tick.
Mã:
struct TW
unit caster
unit target
unit dummy
location loc // Giờ mới để ý cái này, bỏ đi, kô dùng đến mà.
integer int
string sfx
endstruct
Thêm tick, bỏ loc đi:
Mã:
truct TW
unit caster
unit target
unit dummy
integer int
integer tick
string sfx
endstruct
Ngừng ở đây, kô chữa nữa, làm lại cái mới thôi.
[/spoil]
Chỉnh sửa cuối:
.


