| 10-25-2005, 03:21 AM | #1 |
Im new to the whole JASS thing. (well, not NEW. i use custom text lines often :)) i wish to know if there is a more efficient way of laying out this type of trigger. (its for an RP map, and this is one of ~20 similar triggers, so createing an optimal shell for it is important, especially when an RP game can go on for hours and hours.) A global Function: JASS:function checkUnit takes unit U returns boolean if ( not ( GetUnitTypeId(U) != 'e000' ) ) then return false endif if ( not ( GetOwningPlayer(U) == GetTriggerPlayer() ) ) then return false endif return true endfunction JASS:function Trig_speed_nnn_Conditions takes nothing returns boolean if ( not ( SubStringBJ(GetEventPlayerChatString(), 1, 7) == "'speed " ) ) then return false endif return true endfunction function Trig_speed_nnn_Func002A takes nothing returns nothing local unit nextUnit = GetEnumUnit() if ( checkUnit(nextUnit) ) then call SetUnitMoveSpeed( nextUnit, S2R(SubStringBJ(GetEventPlayerChatString(), 8, 10)) ) else endif endfunction function Trig_speed_nnn_Actions takes nothing returns nothing local group tempGroup = GetUnitsSelectedAll(GetTriggerPlayer()) call ForGroupBJ( tempGroup, function Trig_speed_nnn_Func002A ) call DestroyGroup( tempGroup ) endfunction //=========================================================================== function InitTrig_speed_nnn takes nothing returns nothing set gg_trg_speed_nnn = CreateTrigger( ) call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(0), "speed", false ) call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(1), "speed", false ) call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(2), "speed", false ) call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(3), "speed", false ) call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(4), "speed", false ) call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(5), "speed", false ) call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(6), "speed", false ) call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(7), "speed", false ) call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(8), "speed", false ) call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(9), "speed", false ) call TriggerAddCondition( gg_trg_speed_nnn, Condition( function Trig_speed_nnn_Conditions ) ) call TriggerAddAction( gg_trg_speed_nnn, function Trig_speed_nnn_Actions ) endfunction any advice is welcome :) |
| 10-25-2005, 10:58 PM | #2 |
Code:
function checkUnit takes unit U returns boolean
return GetUnitTypeId(U) != 'e000' and GetOwningPlayer(U) == GetTriggerPlayer()
endfunction |
| 10-25-2005, 11:01 PM | #3 |
Code:
function checkUnit takes unit U returns boolean
return GetUnitTypeId(U) != 'e000' and GetOwningPlayer(U) == GetTriggerPlayer()
endfunctionCode:
function Trig_speed_nnn_Conditions takes nothing returns boolean
return SubStringBJ(GetEventPlayerChatString(), 1, 7) == "'speed "
endfunction
function Trig_speed_nnn_Func002A takes nothing returns nothing
local unit nextUnit = GetEnumUnit()
if ( checkUnit(nextUnit) ) then
call SetUnitMoveSpeed( nextUnit, S2R(SubStringBJ(GetEventPlayerChatString(), 8, 10)) )
else
endif
endfunction
function Trig_speed_nnn_Actions takes nothing returns nothing
local group tempGroup = GetUnitsSelectedAll(GetTriggerPlayer())
call ForGroup( tempGroup, function Trig_speed_nnn_Func002A )
call DestroyGroup(tempGroug)
endfunction
//===========================================================================
function InitTrig_speed_nnn takes nothing returns nothing
set gg_trg_speed_nnn = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(0), "speed", false )
call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(1), "speed", false )
call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(2), "speed", false )
call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(3), "speed", false )
call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(4), "speed", false )
call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(5), "speed", false )
call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(6), "speed", false )
call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(7), "speed", false )
call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(8), "speed", false )
call TriggerRegisterPlayerChatEvent( gg_trg_speed_nnn, Player(9), "speed", false )
call TriggerAddCondition( gg_trg_speed_nnn, Condition( function Trig_speed_nnn_Conditions ) )
call TriggerAddAction( gg_trg_speed_nnn, function Trig_speed_nnn_Actions )
endfunction |
