Page 1 of 1

Player Help

Posted: Sat May 21, 2011 8:13 pm
by Race
i have a maze, and i decided to make brown a player too, and when i make the enemy units any of these (neutral hostile/passive/extra or victim), my square patrols act up. (if you need to see how they fuck up i can show you.) it works when i change it back to any player 0-11, but none of the neutral players work. everything else on the map works except for the square patrols. this is one of my square patrol functions...

function CheckUnit1 takes nothing returns boolean
if ( GetUnitTypeId(GetTriggerUnit()) == udg_UnitType[1]) then
return true
else
return false
endif
endfunction

function Move1 takes nothing returns nothing
call IssuePointOrder( GetTriggerUnit(), "move", GetRectCenterX( udg_NextRegion[1] ), GetRectCenterY( udg_NextRegion[1] ))
endfunction
function Move2 takes nothing returns nothing
call IssuePointOrder( GetTriggerUnit(), "move", GetRectCenterX( udg_NextRegion[2] ), GetRectCenterY( udg_NextRegion[2] ))
endfunction
function Move3 takes nothing returns nothing
call IssuePointOrder( GetTriggerUnit(), "move", GetRectCenterX( udg_NextRegion[3] ), GetRectCenterY( udg_NextRegion[3] ))
endfunction
function Move4 takes nothing returns nothing
call IssuePointOrder( GetTriggerUnit(), "move", GetRectCenterX( udg_NextRegion[4] ), GetRectCenterY( udg_NextRegion[4] ))
endfunction

function Square1 takes integer i, rect a, rect b, rect c, rect d returns nothing

local integer y = 1
local integer z = 4
set udg_UnitType[1] = i

loop
exitwhen y > z
set udg_Trigger[y] = CreateTrigger()
call TriggerAddCondition( udg_Trigger[y], Condition( function CheckUnit1 ) )
set y = y + 1
endloop

call TriggerRegisterEnterRectSimple( udg_Trigger[1], a)
call TriggerRegisterEnterRectSimple( udg_Trigger[2], b)
call TriggerRegisterEnterRectSimple( udg_Trigger[3], c)
call TriggerRegisterEnterRectSimple( udg_Trigger[4], d)

set udg_NextRegion[1] = b
set udg_NextRegion[2] = c
set udg_NextRegion[3] = d
set udg_NextRegion[4] = a

call TriggerAddAction( udg_Trigger[1], function Move1 )
call TriggerAddAction( udg_Trigger[2], function Move2 )
call TriggerAddAction( udg_Trigger[3], function Move3 )
call TriggerAddAction( udg_Trigger[4], function Move4 )

endfunction

not sure why changing the player to a neutral player would fuck anything up but i guess it does...

Re: Player Help

Posted: Sun May 22, 2011 9:01 am
by 3ICE
Why does it look so GUI-ish?
Use proper JASS, converted triggers are so unreadable and ugly.

EDIT1: For example this entire useless function:

Code: Select all

function CheckUnit1 takes nothing returns boolean
if ( GetUnitTypeId(GetTriggerUnit()) == udg_UnitType[1]) then
return true
else
return false
endif
endfunction
and this condition referencing it

Code: Select all

call TriggerAddCondition( udg_Trigger[y], Condition( function CheckUnit1 ) )
Should really be just an if-check at the beginning of Move1 Move2 etc:

Code: Select all

if GetUnitTypeId(GetTriggerUnit()) == udg_UnitType[1]then
EDIT2: I remember reading about similar issues years ago. In all solutions I saw, the effort required to turn off the neutral AI or make it obey triggered orders was too much. This is why everyone sticks to brown-controlled enemies instead of debugging why neutral won't do what it is told.

EDIT3: Bad topic title. I'd have used "Neutral player won't take orders".

EDIT4: Use points instead of regions as the argument. Recalculating the center of the region all the time is a waste of CPU power. Calculate it once at map init if you must, but the best solution would be just using the x and y coordinates and deleting those useless regions.

Code: Select all

function Square1 takes integer i, rect a, rect b, rect c, rect d returns nothing
to

Code: Select all

function Square takes integer u, point a, point b, point c, point d returns nothing
EDIT5: With StarCraft 2 we finally have access to points in the terrain editor, not just regions. This is a huge improvement. Be gone, t_reg Center of Region!

EDIT6: Why is udg_UnitType an array when all you ever use is the second index: udg_UnitType[1] (udg_UnitType[0] would be the first index)

EDIT7: Realized you can't use point arguments as the rects are actually needed for the t_uni unit enters region event. But you should still only calculate the center of those regions once (when the Square function is called) and store the results in a variable for later use.

EDIT8: the parameter "integer i" should really be "integer u" as it references a unit-type, not an index / counter.