HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How to get the unit being trained

07-01-2007, 03:42 PM#1
Troll-Brain
Is there a way to get the unit type is being trained ?
I see only this damn crazy boring thing :
Give for each type of unit a different cost of food and then guess wich unit type is being trained, and finally set the unit food to the wanted value
07-01-2007, 03:59 PM#2
Alexander244
In GUI:
(Unit-type of (Trained unit))

eg:
Trigger:
Some Trigger
Collapse Events
Unit - A unit Finishes training a unit
Conditions
Collapse Actions
Set UnitType = (Unit-type of (Trained unit))
07-01-2007, 04:13 PM#3
Troll-Brain
No i said being trained not finish trained
If it was so easy i wouldn't ask it ...
07-01-2007, 04:22 PM#4
Histenchist
This?

Trigger:
This is really hard
Collapse Events
Unit - A unit Begins training a unit
Conditions
Collapse Actions
Set TrainUnit_Temp = (Trained unit)
07-01-2007, 04:40 PM#5
Troll-Brain
Trained unit == null with this event
so this is very useless

Just read the comment in gui with this function and please stop thinking im so stupid. Thx
07-01-2007, 04:51 PM#6
Alexander244
You mean you want to be able to pick a stucture and see what it is training?
If so something like this should work:
Variables:
Name:Type:
ArrayNextinteger
TrainingUnit-Typearray
Trigger:
SomeTrigger
Collapse Events
Unit - A unit Begins training a unit
Conditions
Collapse Actions
Set ArrayNext = ArrayNext + 1
Unit - Set the custom value of (Triggering unit) to ArrayNext
Set Training[ArrayNext] = (Trained unit-type)
Trigger:
Collapse SomeOtherTrigger
Collapse Events
//Whatever event you need to find the UNIT being trained data for
Conditions
Actions
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
(Custom value of (UNIT)) Equal to 0
Collapse Then - Actions
Set UnitType = No Unit
Collapse Else - Actions
Set UnitType = (Unit-Type of (Training[(Custom value of (UNIT))]))
Trigger:
LastTrigger
Collapse Events
Unit - A unit Finishes training a unit
Conditions
Collapse Actions
Set ArrayNext = ArrayNext - 1
Unit - Set the custom value of (Triggering unit) to 0

Edit: Updated so it actually works
07-01-2007, 04:55 PM#7
Troll-Brain
No, no and no.
// EVENT_PLAYER_UNIT_TRAIN_FINISH
constant native GetTrainedUnit takes nothing returns unit

this works only with this event ...
07-01-2007, 04:56 PM#8
Histenchist
Found a much easier way;

Trigger:
Untitled Trigger 001
Collapse Events
Unit - A unit Begins training a unit
Collapse Conditions
(Trained unit-type) Equal to Peasant
Collapse Actions
Game - Display to (All players) the text: Yep, this works
07-01-2007, 05:05 PM#9
Troll-Brain
Hmm had you really try it ?
It doesn't works for me ...

Trigger:
Déclencheur sans titre 001
Collapse Evénements
Unité - A unit Begins training an unit
Conditions
Collapse Actions
Set U = (Trained unit)
Set UT = (Unit-type of (Trained unit))
Custom script: call BJDebugMsg("Unit = " + I2S(H2I(udg_U)))
Custom script: call BJDebugMsg("Unit Type = "+I2S(udg_UT))

It displays :
Unit = 0
Unit Type = 0
07-01-2007, 05:17 PM#10
Histenchist
yes it works, look what it responds to.
Click image for larger version

Name:	Works.JPG
Views:	24
Size:	55.5 KB
ID:	26658
Attached Images
File type: jpgWorks.JPG (55.5 KB)
07-01-2007, 05:56 PM#11
Troll-Brain
Collapse JASS:
function Trig_D__clencheur_sans_titre_001_Conditions takes nothing returns boolean
    if ( not ( GetUnitTypeId(GetTriggerUnit()) == 'hpea' ) ) then
        return false
    endif
    return true
endfunction

function Trig_D__clencheur_sans_titre_001_Actions takes nothing returns nothing
    call DisplayTextToForce( GetPlayersAll(), "aha" )
    call DisplayTextToForce( GetPlayersAll(), GetUnitName(GetTrainedUnit()) )
endfunction

//===========================================================================
function InitTrig_D__clencheur_sans_titre_001 takes nothing returns nothing
    set gg_trg_D__clencheur_sans_titre_001 = CreateTrigger(  )
    call TriggerRegisterUnitEvent( gg_trg_D__clencheur_sans_titre_001, gg_unit_htow_0000, EVENT_UNIT_TRAIN_START )
    call TriggerAddCondition( gg_trg_D__clencheur_sans_titre_001, Condition( function Trig_D__clencheur_sans_titre_001_Conditions ) )
    call TriggerAddAction( gg_trg_D__clencheur_sans_titre_001, function Trig_D__clencheur_sans_titre_001_Actions )
endfunction

I convert it in jass cause the gui is not in english
It displays "aha" and nothing else

And see that :


sorry but it really doesn't work for me.

GetTrainedUnit() == null in all case.
I've tried what you said

So please attach a map and i will try
07-01-2007, 06:12 PM#12
Alexander244
I will put it in Jass, so language does not stop you:
Collapse JASS:
GetTrainedUnitType() //This will return the unit-type for a begins/cancels/finishes training event.
GetTrainedUnit() //This returns the actual unit, which does not exist until the finishes training event.
//Things are so much easier in JASS.
07-01-2007, 06:13 PM#13
Histenchist
Build a peasant in the test map and you will see.
Peasant Test.w3x
Attached Files
File type: w3xPeasant Test.w3x (12.4 KB)
07-01-2007, 06:45 PM#14
Troll-Brain
Ok thx.
GetTrainedUnitType() is the function i wanted.
sorry i didn't search in jass, only in gui ...
And i didn't see (Trained unit type)

@ Hitenchist :
the problem wasn't the event but how to get the unit type.

Next time i will see better that, before ask for something so easy >.<