After my pro jassing skills:
Code:
function Trig_Spell_Conditions takes nothing returns boolean
if ( not ( GetSpellAbilityId() == 'A00W' ) ) then
return false
endif
return true
endfunction
function Trig_Spell_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
call ForGroupBJ( GetUnitsInRangeOfLocMatching(150.00, GetSpellTargetLoc(), ( IsUnitEnemy(GetOwningPlayer(u)) == true )
call CreateNUnitsAtLoc( 1, 'oshm', GetOwningPlayer(u), GetUnitLoc(u), bj_UNIT_FACING )
call UnitApplyTimedLifeBJ( 0.50, 'BTLF', GetLastCreatedUnit() )
call IssueTargetOrderBJ( GetLastCreatedUnit(), "ensnare", GetEnumUnit() )
endfunction
//===========================================================================
function InitTrig_Spell takes nothing returns nothing
set gg_trg_Spell = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Spell, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( gg_trg_Spell, Condition( function Trig_Spell_Conditions ) )
call TriggerAddAction( gg_trg_Spell, function Trig_Spell_Actions )
endfunction
sry, i messed up so i cant show how the spell looked right after conversion to jass. And i dont have it GUI'd anymore.
It looked something like this though:
Code:
Events:|||Firstly, you should add 'set u = null' to the end of that code. As for accessing locals from other functions, it's usually quicker and simpler just to redeclare the locals (GetTriggerUnit and similar natives will work just as well). In addition, most of the 'if' functions created by the GUI triggers can easily be merged in to the main body function (example code below). When neither of them are an option, which should be almost never if you're not using local triggers, you can store the local in a hashtable and then load it in the alternate function. However, I doubt you'll find need to do that.
Unit starts the effect of an ability
Conditions:
Ability cast = Spell
Actions:
Pick every unit in Units within 150 of Point of Ability being cast and do Action:
Action:
unit - create 1 shaman for owner of triggering unit
unit - order last created unit to neutral hostile: ensnare Picked unit
unit - add a 0.5 sec expiration timer to last created unit
Code:
function ExampleIfFunc takes nothing returns boolean
if ( not (u == SomeUnit) ) then
return false
endif
return true
endfunction
function Trig_ExampleTrig_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
if (ExampleIfFunc()) then
call doStuff()
endif
set u = null
endfunction
This can be simplified to...
Code:
function Trig_ExampleTrig_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
if (u == SomeUnit) then
call doStuff()
endif
set u = null
endfunction
Finally, I feel that I should mention that you'll end up with far cleaner and more readable code if you write your triggers in JASS from scratch, rather than just converting at the end.|||Quote:
Firstly, you should add 'set u = null' to the end of that code. As for accessing locals from other functions, it's usually quicker and simpler just to redeclare the locals (GetTriggerUnit and similar natives will work just as well). In addition, most of the 'if' functions created by the GUI triggers can easily be merged in to the main body function (example code below). When neither of them are an option, which should be almost never if you're not using local triggers, you can store the local in a hashtable and then load it in the alternate function. However, I doubt you'll find need to do that.
Code:
function ExampleIfFunc takes nothing returns boolean
if ( not (u == SomeUnit) ) then
return false
endif
return true
endfunction
function Trig_ExampleTrig_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
if (ExampleIfFunc()) then
call doStuff()
endif
set u = null
endfunction
This can be simplified to...
Code:
function Trig_ExampleTrig_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
if (u == SomeUnit) then
call doStuff()
endif
set u = null
endfunction
Finally, I feel that I should mention that you'll end up with far cleaner and more readable code if you write your triggers in JASS from scratch, rather than just converting at the end.
thanks. But first of all, im not competent enough to write in jass from scratch. As mentioned before, I mainly use it so I can have local variables instead of globals.
second, I'm not having trouble setting TriggerUnit = <LocalUnit>, the problem is to write it so that I have a local unit group, and if the player owning the units within that group isn't playing, the get removed. I don't know the syntax for that kind of function. (Yes, I'm very bad at jass ;P )
Im afraid you didn't answer my question. Either that or I misunderstood
Also, I dont understand
Code:
function Trig_ExampleTrig_Actions takes nothing returns nothing
local unit u = GetTriggerUnit()
if (u == SomeUnit) then
call doStuff()
endif
set u = null
endfunction
why should I set TriggerUnit to a local and then check if it's SomeUnit? All I need to know is that it's the TriggerUnit
Edit: Ive realized I'm not making myself clear (I rarely do) my problem is rewriting the code so that the ifs (or any other condition besides the Trigger Condition. This means that it includes things like "pick every unit in unit group matching CONDITION) are within the "function_TriggerName_Action" function.
The problem lies in this line:
Code:
call ForGroupBJ( GetUnitsInRangeOfLocMatching(150.00, GetSpellTargetLoc(), ( IsUnitEnemy(GetOwningPlayer(u)) == true )
(u = TriggerUnit)
the problem is checking if the units within 150.00 of SpellTargetLoc() are enemies of OwningPlayer(u)) , A Condition
No comments:
Post a Comment