• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[JASS] Set construction progress for structures

Status
Not open for further replies.
Level 3
Joined
Apr 1, 2005
Messages
53
Hey there,

Can't find anything that would be helping me. I have following trigger:

JASS:
function Trig_Fast_Construction_Actions takes nothing returns nothing
    call UnitSetConstructionProgress(GetConstructingStructure(), 99)
endfunction

function InitTrig_Fast_Construction takes nothing returns nothing
    local trigger trig = CreateTrigger()
    local integer i = 0
    
    loop
        exitwhen i > 11
        call TriggerRegisterPlayerUnitEvent(trig, Player(i), EVENT_PLAYER_UNIT_CONSTRUCT_START, null)  
        set i = i + 1
    endloop
    
    call TriggerAddAction(trig, function Trig_Fast_Construction_Actions)

    set trig = null
endfunction

It's converted from GUI, but I then edited it to fit my needs. Still, the problem is that the progress is never set to my specified percent. I tried GetConstructingStructure, GetTriggerUnit and GetEventTargetUnit. I believe it could be due to the PLAYER_UNIT_EVENT, that he needs a player input and can't just pick the unit itself.
Help anyone?
 
Level 3
Joined
Apr 1, 2005
Messages
53
Ehm, what? I don't what a timer or any time it needs to build. I want to set the construction progress of a structure that is constructed to 99%, so that construction speed is boosted.
 
Level 16
Joined
Oct 12, 2008
Messages
1,570
So he should do something like this:
JASS:
globals
    unit ConstructingStruc
    timer tim = CreateTimer()
endglobals
function Actions2 takes nothing returns nothing
    call UnitSetConstructionProgress(ConstructingStruc, 99)
endfunction
function Actions takes nothing returns nothing
    set ConstructingStruc = GetConstructingStructure()
    call TimerStart(tim, 0.001, false, Actions2)
endfunction
function Init takes nothing returns nothing
    // initialize event and so on here
endfunction
Should that work?
 
Level 3
Joined
Apr 1, 2005
Messages
53
I don't get it. Why would I need a timer for this? Shouldn't the event be fired when the event occurs? I have no problems anywhere, just with this one trigger. Could you explain?
Also, why are globals not safe?
 
Level 22
Joined
Dec 31, 2006
Messages
2,216
I believe this will work (Haven't tested):
JASS:
function H2I takes handle h returns integer
    return h
    return 0
endfunction

function I2U takes integer i returns unit
    return i
    return null
endfunction

function Actions2 takes nothing returns nothing
    local timer t = GetExpiredTimer()
    local unit u = I2U(R2I(TimerGetTimeout(t)*2147483648.))
    call UnitSetConstructionProgress(u, 99)
    call DestroyTimer(t)
    set t = null
    set u = null
endfunction

function Actions takes nothing returns nothing
    local timer t = CreateTimer()
    local unit u = GetConstructingStructure()
    call TimerStart(t, H2I(u)/2147483648., false, Actions2)
    set t = null
    set u = null
endfunction

function Init takes nothing returns nothing
    local trigger t = CreateTrigger()
    local player p
    local integer i = 0
    loop
        exitwhen i == bj_MAX_PLAYER_SLOTS
        set p = Player(i)
        call TriggerRegisterPlayerUnitEvent(trig, p, EVENT_PLAYER_UNIT_CONSTRUCT_START, null)
        set i = i + 1
        set p = null
    endloop
    call TriggerAddAction(t, function Actions)
    set t = null
endfunction
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
I don't get it. Why would I need a timer for this? Shouldn't the event be fired when the event occurs? I have no problems anywhere, just with this one trigger. Could you explain?
Also, why are globals not safe?
No, events fire before they occur, so you have to let the thread complete (0 second timer) before you do anything directly relating to the event.

Imagine it as something like this:

Code:
void killUnit() {
    killUnitEvents();
    //do stuff to kill the unit here
}
 
Level 3
Joined
Apr 1, 2005
Messages
53
Then I'll try it with timer. But why is it that I don't need timers in my other triggers? What makes this case here so special?
 
Status
Not open for further replies.
Top