| 11-01-2007, 04:10 AM | #1 | |
I need someone to do a little coding. Most of the code is provided it just needs to be modified... Reading the known jass bugs I found this... Quote:
JASS:function Trig_Attack_Command takes nothing returns nothing call IssuePointOrderLocBJ( GetEnumUnit(), "attack", GetUnitLoc(udg_Hero[21]) ) endfunction function Trig_Attack_Lowest_Actions takes nothing returns nothing local real array L local integer A = 1 local integer B = 1 local integer C = 0 local integer D = 1 local integer E = 0 loop exitwhen D > 10 set L[D] = GetUnitStateSwap(UNIT_STATE_LIFE, udg_Hero[D]) set D = D+1 endloop loop exitwhen C == 10 if A == 11 then set A = 1 endif if B == 11 then set B = 1 endif if L[A] > 0 then if L[A] <= L[b] and L[b] > 0 then set B = B + 1 set C = C + 1 elseif L[b] == 0 then set B = B + 1 set C = C + 1 set E = E + 1 else set A = A + 1 set B = 1 set C = 0 set E = 0 endif else set A = A + 1 set B = 1 set C = 0 set E = E + 1 if E == 10 then set C = 10 call DisplayTimedTextToForce( GetPlayersAll(), 30, "All Heros Dead" ) endif endif set udg_Hero[21] = udg_Hero[A] endloop call ForGroupBJ( GetUnitsOfPlayerAll(Player(11)), function Trig_Attack_Command ) endfunction //=========================================================================== function InitTrig_Attack_Lowest takes nothing returns nothing set gg_trg_Attack_Lowest = CreateTrigger( ) call TriggerRegisterTimerEventPeriodic( gg_trg_Attack_Lowest, 30.00 ) call TriggerAddAction( gg_trg_Attack_Lowest, function Trig_Attack_Lowest_Actions ) endfunction JASS:function Trig_Attack_Command takes nothing returns nothing call IssuePointOrderLocBJ( GetEnumUnit(), "attack", F) ) endfunction function Trig_Attack_Lowest_Actions takes nothing returns nothing local real array L local integer A = 1 local integer B = 1 local integer C = 0 local integer D = 1 local integer E = 0 local location F = GetUnitLoc(udg_Hero[21]) local group G = CreateGroup() call GroupEnumUnitsOfPlayer(g, Player(11), null) loop exitwhen D > 10 set L[D] = GetUnitState(udg_Hero[D], UNIT_STATE_LIFE) set D = D+1 endloop loop exitwhen C == 10 if A == 11 then set A = 1 endif if B == 11 then set B = 1 endif if L[A] > 0 then if L[A] <= L[b] and L[b] > 0 then set B = B + 1 set C = C + 1 elseif L[b] == 0 then set B = B + 1 set C = C + 1 set E = E + 1 else set A = A + 1 set B = 1 set C = 0 set E = 0 endif else set A = A + 1 set B = 1 set C = 0 set E = E + 1 if E == 10 then set C = 10 call DisplayTimedTextToForce( GetPlayersAll(), 30, "All Heros Dead" ) endif endif set udg_Hero[21] = udg_Hero[A] endloop call ForGroup( G, function Trig_Attack_Command ) call DestroyGroup(G) set G = null call RemoveLocation(F) set F = null endfunction //=========================================================================== function InitTrig_Attack_Lowest takes nothing returns nothing set gg_trg_Attack_Lowest = CreateTrigger( ) call TriggerRegisterTimerEvent( gg_trg_Attack_Lowest, 30.00, true ) call TriggerAddAction( gg_trg_Attack_Lowest, function Trig_Attack_Lowest_Actions ) endfunction |
| 11-01-2007, 10:52 AM | #2 |
If you need optimizing, then I'm your man. call TriggerRegisterTimerEventPeriodic( gg_trg_Attack_Lowest, 30.00 ) Is a BJ, and it's equal to: TriggerRegisterTimerEvent( gg_trg_Attack_Lowest, 30.00, true ) There's a leak here: call ForGroupBJ( GetUnitsOfPlayerAll(Player(11)), function Trig_Attack_Command ) You have two options:
First JASS:function Trig_Attack_Lowest_Actions takes nothing returns nothing // ... // ... // ... set bj_wantDestroyGroup = true ForGroupBJ( GetUnitsOfPlayerAll(Player(11)), function Trig_Attack_Command ) endfunction Second JASS:function Trig_Attack_Lowest_Actions takes nothing returns nothing // ... local group g = GetUnitsOfPlayerAll(Player(11)) // ... // ... // ... call ForGroup( g, function Trig_Attack_Command ) call DestroyGroup(g) set g = null endfunction And GetUnitsOfPlayerAll is a BJ, that line could be written like this: JASS:// ... local group g = CreateGroup() call GroupEnumUnitsOfPlayer(g, Player(11), null) ForGroup (g, ...) //... GetPlayersAll is also a BJ and it returns bj_FORCE_ALL_PLAYERS You have a leak here: call IssuePointOrderLocBJ( GetEnumUnit(), "attack", GetUnitLoc(udg_Hero[21]) ) But first we can make that a native: IssuePointOrderLoc( GetEnumUnit(), "attack", GetUnitLoc(udg_Hero[21]) ) Because it does the same bloody thing anyways, it's just faster. GetUnitLoc(udg_Hero[21] is a leak, you need to store it in a location variable, and then destroy it and set it to null afterwards: JASS:function Trig_Attack_Command takes nothing returns nothing local location l = GetUnitLoc(udg_Hero[21]) call IssuePointOrderLocBJ( GetEnumUnit(), "attack", l ) endfunction call RemoveLocation(l) set l = null endfunction This is also crap: GetUnitStateSwap(UNIT_STATE_LIFE, udg_Hero[D]) Better use a native instead of those swap BJs: GetUnitState(udg_Hero[D], UNIT_STATE_LIFE) |
| 11-01-2007, 09:00 PM | #3 |
I tried combining the code and this is what i came up with... JASS:function Trig_Attack_Command takes nothing returns nothing call IssuePointOrderLocBJ( GetEnumUnit(), "attack", udg_F) set udg_I = udg_I + 1 if udg_I > 100 then call TriggerSleepAction(0.0) set udg_I = 0 endif endfunction function Trig_Attack_Lowest_Actions takes nothing returns nothing local real array L local integer A = 1 local integer B = 1 local integer C = 0 local integer D = 1 local integer E = 0 local location F = GetUnitLoc(udg_Hero[21]) local group G = CreateGroup() call GroupEnumUnitsOfPlayer(G, Player(11), null) loop exitwhen D > 10 set L[D] = GetUnitState(udg_Hero[D], UNIT_STATE_LIFE) set D = D+1 endloop loop exitwhen C == 10 if A == 11 then set A = 1 endif if B == 11 then set B = 1 endif if L[A] > 0 then if L[A] <= L[b] and L[b] > 0 then set B = B + 1 set C = C + 1 elseif L[b] == 0 then set B = B + 1 set C = C + 1 set E = E + 1 else set A = A + 1 set B = 1 set C = 0 set E = 0 endif else set A = A + 1 set B = 1 set C = 0 set E = E + 1 if E == 10 then set C = 10 call DisplayTimedTextToForce( GetPlayersAll(), 30, "All Heros Dead" ) endif endif set udg_Hero[21] = udg_Hero[A] endloop set udg_F = F set udg_I = 0 call ForGroup( G, function Trig_Attack_Command ) call DestroyGroup(G) set G = null call RemoveLocation(F) set F = null endfunction //=========================================================================== function InitTrig_Attack_Lowest takes nothing returns nothing set gg_trg_Attack_Lowest = CreateTrigger( ) call TriggerRegisterTimerEvent( gg_trg_Attack_Lowest, 30.00, true ) call TriggerAddAction( gg_trg_Attack_Lowest, function Trig_Attack_Lowest_Actions ) endfunction And a quick question, Are all BJ's bad? |
| 11-01-2007, 11:17 PM | #4 |
The most of them are pointless functions like so: JASS:function IsUnitHiddenBJ takes unit whichUnit returns boolean return IsUnitHidden(whichUnit) endfunction JASS:function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing local integer index set index = 0 loop call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null) set index = index + 1 exitwhen index == bj_MAX_PLAYER_SLOTS endloop endfunction JASS:function MultiboardSetItemStyleBJ takes multiboard mb, integer col, integer row, boolean showValue, boolean showIcon returns nothing local integer curRow = 0 local integer curCol = 0 local integer numRows = MultiboardGetRowCount(mb) local integer numCols = MultiboardGetColumnCount(mb) local multiboarditem mbitem = null // Loop over rows, using 1-based index loop set curRow = curRow + 1 exitwhen curRow > numRows // Apply setting to the requested row, or all rows (if row is 0) if (row == 0 or row == curRow) then // Loop over columns, using 1-based index set curCol = 0 loop set curCol = curCol + 1 exitwhen curCol > numCols // Apply setting to the requested column, or all columns (if col is 0) if (col == 0 or col == curCol) then set mbitem = MultiboardGetItem(mb, curRow - 1, curCol - 1) call MultiboardSetItemStyle(mbitem, showValue, showIcon) call MultiboardReleaseItem(mbitem) endif endloop endif endloop endfunction |
| 11-02-2007, 02:12 AM | #5 |
Multiboard BJs are horrible. It is better to make your own than use theirs (all the loops). And it is better still to use the natives directly in the code. |
| 11-02-2007, 08:08 AM | #6 | |
Yup... instead, the natives for multiboard are much more easier to use than the BJs. Quote:
|
| 11-02-2007, 09:06 AM | #7 | ||
Quote:
Amen! I'm glad somebody shares my vision. You can just nullify in the end, it's more organized that way. You still didn't replace IssuePointOrderLocBJ with IssuePointOrder, it's easy to replace, I think even the parameters aren't mixed up. Quote:
This almost doesn't make a difference at all, this happens once, and it's not that big of a deal if it's a BJ (though I replace that with natives anyways because I see BJs as evil. Even more with TESH, which makes them red) |
| 11-02-2007, 02:06 PM | #8 |
Ok, i replaced the BJ for IssuePointOrder, and in takes X and Y not a Point/Location so I to get those values. I lso kind of renamed my variables for readablilty. JASS:function Trig_Attack_Command takes nothing returns nothing call IssuePointOrder( GetEnumUnit(), "attack", udg_HeroLocX, udg_HeroLocY) set udg_CounterF = udg_CounterF + 1 if udg_CounterF > 100 then call TriggerSleepAction(0.0) set udg_CounterF = 0 endif endfunction function Trig_Attack_Lowest_Actions takes nothing returns nothing local real array Life local integer HeroIndexA = 1 local integer HeroIndexB = 1 local integer CounterC = 0 local integer CounterD = 1 local integer CounterE = 0 local location HeroLoc = GetUnitLoc(udg_Hero[21]) local group G = CreateGroup() local real HeroLocX = GetLocationX(HeroLoc) local real HeroLocY = GetLocationY(HeroLoc) set udg_HeroLocX = HeroLocX set udg_HeroLocY = HeroLocY call GroupEnumUnitsOfPlayer(G, Player(11), null) loop exitwhen CounterD > 10 set Life[CounterD] = GetUnitState(udg_Hero[CounterD], UNIT_STATE_LIFE) set CounterD = CounterD + 1 endloop loop exitwhen CounterC == 10 if HeroIndexA == 11 then set HeroIndexA = 1 endif if HeroIndexB == 11 then set HeroIndexB = 1 endif if Life[HeroIndexA] > 0 then if Life[HeroIndexA] <= Life[HeroIndexB] and Life[HeroIndexB] > 0 then set HeroIndexB = HeroIndexB + 1 set CounterC = CounterC + 1 elseif Life[HeroIndexB] == 0 then set HeroIndexB = HeroIndexB + 1 set CounterC = CounterC + 1 set CounterE = CounterE + 1 else set HeroIndexA = HeroIndexA + 1 set HeroIndexB = 1 set CounterC = 0 set CounterE = 0 endif else set HeroIndexA = HeroIndexA + 1 set HeroIndexB = 1 set CounterC = 0 set CounterE = CounterE + 1 if CounterE == 10 then set CounterC = 10 call DisplayTimedTextToForce( GetPlayersAll(), 30, "All Heros Dead" ) endif endif set udg_Hero[21] = udg_Hero[HeroIndexA] endloop set udg_CounterF = 0 call ForGroup( G, function Trig_Attack_Command ) call DestroyGroup(G) set G = null call RemoveLocation(HeroLoc) set HeroLoc = null endfunction //=========================================================================== function InitTrig_Attack_Lowest takes nothing returns nothing set gg_trg_Attack_Lowest = CreateTrigger( ) call TriggerRegisterTimerEvent( gg_trg_Attack_Lowest, 30.00, true ) call TriggerAddAction( gg_trg_Attack_Lowest, function Trig_Attack_Lowest_Actions ) endfunction Edit: I am using shorter names for myself, I just figured it may help you guys out if I gave them full names. |
| 11-02-2007, 02:53 PM | #9 |
Name your variables with 2-3 letters max. (Location = l, Unit = u, Caster = c, Target = t, Timer = t.......). It's much easier to type and much faster (also the readability is better). Forget about the naming method you used for globals in GUI. |
| 11-02-2007, 08:46 PM | #10 |
Is there a list of natives in world editor? When I write my code and I dont know what the line of code for the function is I make a new trigger get the gui function and convert it the use that line for what ever my purpose is. eg. I need a units mana. gui -> units mana -> convert to jass = GetUnitStateSwap(UNIT_STATE_MANA, *) add this line into my code and continue.... The problem is that appearantly gui always uses bj's and I dont know any natives. ( Well really I dont know most of the bjs either lol i just convert one when I need it) |
| 11-02-2007, 10:00 PM | #11 |
Look for common.j in War3patch.mpq. It contains all native types. |
| 11-03-2007, 06:47 AM | #12 |
Either download JASSCraft or look here: http://82.170.159.98/?p=jass |
