HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Need some triggering help

01-12-2003, 04:28 AM#1
Guest
Ok, without giving to much info away, i need some help with my latest project. Ok, i have three balls (wisps). Each player controls a one unit. Players can grab and drop the balls. Each player can only hold one ball at a time. I need some way of keeping track of who has balls, its really easy with just one ball, but i cant seem to figure it out with 3 balls.

The way i needed it to work is: I have an array that will hold 3 units, the ones holding a ball. When a unit attacks a ball, the ball is removed, and the unit is added to the first empty slot in the array. When the ball is dropped (by ordering a ball carrier to attack the ground), the unit is removed from the array, and a ball is created.

The part i have the most trouble with "When a unit attacks a ball, the ball is removed, and the unit is added to the first empty slot in the array" I can figure out how to check which slots are empty and only add it to the first empty slot it finds.

Any help is much appreciated
01-12-2003, 05:13 AM#2
Guest
Wait, can you explain how exactly the game works? When what unit attacks what unit, what will happen? Tell me the workings and exactly what you want, and ill try to help.
01-12-2003, 01:51 PM#3
Guest
Ok, when a villager unit attacks a wisp (no damage is caused), the wisp is removed and a special effect is placed on the villager to indicate he has a "ball" (a wisp). When that villager is ordered to attack the ground, the ball is droped ie: a new wisp is created and the effect on the villager is removed.

Heres what the trigger i need help with looks like if it only handled one ball:

E:
Unit - A unit ownened by Neutral Passive is attacked
C:
BallCarrier Not Equal To (Attacking Unit)
A:
Set BallCarrier = (Attacking Unit)
Unit - Remove (Attacked Unit) from the game

Now i need to rewrite that trigger so that it would work if there are 3 possible balls players can pick up. Each villager can only carry one ball at a time. Does that Explain it better?
01-12-2003, 09:41 PM#4
Myster Mystery
Hmm, you could try making a boolean variable for each guy indicating if he is currently holding a ball and then put conditions stating that the variable can't be on, or something like that. Just play around with booleans. Or maybe have a unit variable, one for each ball, and when someone picks up the ball the variable is set to that person, and have conditions stoping him from picking up another... Am I making sense?
01-12-2003, 11:00 PM#5
algumacoisaqq
Here's a Custom trigger I've written some time ago to manage an array of 4 workers I had. Since the workers would be ocnsntantly dying, changing tasks, etc, I had to keep track of the four ones that would be the workers to do special stuff. That would be your ball units, I guess.

To add them to the array:
Quote:

set udg_CornField1Workers[udg_CornField1WorkersIndex] = GetTriggerUnit()
set udg_CornField1WorkersIndex = ( udg_CornField1WorkersIndex + 1 )



To remove them from the array:
Quote:

function Trig_Unassign_Worker_Custom_Func005001001 takes nothing returns boolean
return ( GetTriggerUnit() == udg_CornField1Workers[0] )
endfunction

function Trig_Unassign_Worker_Custom_Func005001002 takes nothing returns boolean
return ( GetTriggerUnit() == udg_CornField1Workers[1] )
endfunction

function Trig_Unassign_Worker_Custom_Func005001 takes nothing returns boolean
return GetBooleanOr( Trig_Unassign_Worker_Custom_Func005001001(), Trig_Unassign_Worker_Custom_Func005001002() )
endfunction

function Trig_Unassign_Worker_Custom_Func005002001 takes nothing returns boolean
return ( GetTriggerUnit() == udg_CornField1Workers[2] )
endfunction

function Trig_Unassign_Worker_Custom_Func005002002 takes nothing returns boolean
return ( GetTriggerUnit() == udg_CornField1Workers[3] )
endfunction

function Trig_Unassign_Worker_Custom_Actions takes nothing returns nothing
if ( Trig_Unassign_Worker_Custom_Func001001() ) then
set udg_CornField1Workers[0] = udg_CornField1Workers[1]
set udg_CornField1Workers[1] = udg_CornField1Workers[2]
set udg_CornField1Workers[2] = udg_CornField1Workers[3]
set udg_CornField1Workers[3] = null
set udg_CornField1WorkersIndex = ( udg_CornField1WorkersIndex - 1 )
endif
if ( GetTriggerUnit() == udg_CornField1Workers[1] ) then
set udg_CornField1Workers[1] = udg_CornField1Workers[2]
set udg_CornField1Workers[2] = udg_CornField1Workers[3]
set udg_CornField1Workers[3] = null
set udg_CornField1WorkersIndex = ( udg_CornField1WorkersIndex - 1 )
endif
if ( GetTriggerUnit() == udg_CornField1Workers[2] ) then
set udg_CornField1Workers[2] = udg_CornField1Workers[3]
set udg_CornField1Workers[3] = null
set udg_CornField1WorkersIndex = ( udg_CornField1WorkersIndex - 1 )
endif
if ( GetTriggerUnit() == udg_CornField1Workers[3] ) then
set udg_CornField1Workers[3] = null
set udg_CornField1WorkersIndex = ( udg_CornField1WorkersIndex - 1 )
endif

endfunction


Anyway, this can be very confusing, but you can use it as reference if you want.

Well, here is what is happening here.
In the assign function, the triggering unit is stored in the position of the workers array (udg_CornField1Workers) at the first empty slot, with is the one that corresponds to the Index variable (udg_CornField1WorkersIndex).

In the begining, the index is 0, so the worker is placed in the first slot, and the index is moved to the second slot. Then, when the second worker is placed on the array, it will be placed on the second slot, because index was added.

Sometimes, however, a worker will get out of this array, So we use the second function. Basiclly, what this function do is check if the Triggering unit is in the array. If the unit is, then we check in wich slot of the array he is. if it's the first one, we move the second one to the first slot, and the third one to the second slot, then we do Index = Index - 1. This way, when we add another worker, he will be placed on third slot, and the guy we wanted to remove from the arrays is out.

If we get the guy from the second slot, then we keep the guy in first slot where he is, and place the guy on the third slot at the second slot, and do Index = Index - 1. This way, the third slot is always free when somebody leaves the array. Same goes when the third slot guy goes away.

I know this is a little confusing, but that's how i've done. I don't know if that's the way you are planning to deal with this, but if you want, I can send you the map.

[edit]

I was bored, so I converted it to something more familiar to what you want. I havn't tested these custom triggers however, but they were based on the ones I use.

Here's the assign trigger:

Quote:
function Trig_HelpGuy_Conditions takes nothing returns boolean
if ( not ( udg_BallCarrier[0] != GetAttacker() ) ) then
return false
endif
if ( not ( udg_BallCarrier[1] != GetAttacker() ) ) then
return false
endif
if ( not ( udg_BallCarrier[2] != GetAttacker() ) ) then
return false
endif
return true
endfunction

function Trig_HelpGuy_Actions takes nothing returns nothing
set udg_BallCarrier[udg_BallIndex] = GetAttacker()
endfunction

//===========================================================================
function InitTrig_HelpGuy takes nothing returns nothing
set gg_trg_HelpGuy = CreateTrigger( )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_HelpGuy, Player(bj_PLAYER_NEUTRAL_VICTIM), EVENT_PLAYER_UNIT_ATTACKED )
call TriggerAddCondition( gg_trg_HelpGuy, Condition( function Trig_HelpGuy_Conditions ) )
call TriggerAddAction( gg_trg_HelpGuy, function Trig_HelpGuy_Actions )
endfunction

and the unassign trigger:

Quote:
function Trig_DropBall_Conditions takes nothing returns boolean
if ( not ( GetTriggerUnit() == udg_BallCarrier[0] ) ) then
return false
endif
if ( not ( GetTriggerUnit() == udg_BallCarrier[1] ) ) then
return false
endif
if ( not ( GetTriggerUnit() == udg_BallCarrier[2] ) ) then
return false
endif
return true
endfunction

function Trig_DropBall_Actions takes nothing returns nothing

if ( GetTriggerUnit() == udg_BallCarrier[0] ) then
set udg_BallCarrier[0] = udg_BallCarrier[1]
set udg_BallCarrier[1] = udg_BallCarrier[2]
set udg_BallCarrier[2] = null
set udg_BallIndex = udg_BallIndex - 1
endif
if ( GetTriggerUnit() == udg_BallCarrier[1] ) then
set udg_BallCarrier[1] = udg_BallCarrier[2]
set udg_BallCarrier[2] = null
set udg_BallIndex = udg_BallIndex - 1
endif
if ( GetTriggerUnit() == udg_BallCarrier[2] ) then
set udg_BallCarrier[2] = null
set udg_BallIndex = udg_BallIndex - 1
endif

endfunction

//===========================================================================
function InitTrig_DropBall takes nothing returns nothing
set gg_trg_DropBall = CreateTrigger( )
call TriggerRegisterPlayerUnitEventSimple( gg_trg_DropBall, Player(0), EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER )
call TriggerAddCondition( gg_trg_DropBall, Condition( function Trig_DropBall_Conditions ) )
call TriggerAddAction( gg_trg_DropBall, function Trig_DropBall_Actions )
endfunction
(of course you will need more conditions to this, right now, the unit will drop the ball if any order targeting a point is given to him, like a attack-move order, a move order, a patrol order, tec.)
01-13-2003, 01:49 AM#6
Guest
EEK!:whoa2::whoa2:

I dont know crap about that....
/me begins decyphering code....

uhhh... it doesnt look that hard to understand (i have plenty of programing experience) but can that be converted to worldedit triggers? or do i have to import them to my map as it is?

Well, thanx for the help, at least its a finger in the right direction :D
01-13-2003, 11:22 AM#7
algumacoisaqq
Sorry, but I don't know how to do that in triggers. I prefers triggers too, but I had to use JASS here, because I couldn't do that with triggers. Pretty much al that is happening is that there is a if/then/else trigger, but we use it to do several actions instead of just one.
01-13-2003, 08:22 PM#8
Guest
algumacoisaqq, ur a genius! I managed to decypher that jass code convert it to the triggers works pretty well so far, Ill give u credit on the map. Thanx a lot!