• 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.

[General] Help on code simplification

Status
Not open for further replies.
Level 5
Joined
Feb 22, 2013
Messages
161
Well, first of all, I am an on and off active member on here considering school and other personal things involved in my life.. But I am willing and wanting sooo badly to pursue my education and career in programming but it is irritating me because there are certain things in a code where simplification and efficiency corrections can be made but I can't figure it out sometimes and that frustrates me quite a bit.. I am a senior in High School and I have taken Java programming classes that helped me somewhat in this, but they can only do so much. Soooo, I am needing help from the hive so I can maybe improve on my skills, whether help can be provided or not, it does not matter to me.

Besides all of that, I want judgement on work I am currently doing for a bossfight I am developing for 4 players.. the bossfight what I have currently programmed in is that the bosses will switch from being invulnerable every 60 seconds after one of them loses 75% of their health or below. I want to know what can make the coding more efficient and simplified when I go and make the final outcome of this bossfight in general.

Thank you guys, and sorry for the long read :grin:

P.S. this map is a test map for certain mechanics for the bosses, I just recently started the making, so the only mechanic is the one I explained above.
 

Attachments

  • HanselGretel Boss.w3x
    334.2 KB · Views: 35
Level 5
Joined
Feb 22, 2013
Messages
161
Here are the three currently used for the fight so far.

Trigger 1: HealthReached
JASS:
function Trig_HealthReached_Actions takes nothing returns boolean
    local real currentHanselHP = GetUnitState(udg_Hansel, UNIT_STATE_LIFE)
    local real maxHanselHP = GetUnitState(udg_Hansel, UNIT_STATE_MAX_LIFE)
    local real currentGretelHP = GetUnitState(udg_Gretel, UNIT_STATE_LIFE)
    local real maxGretelHP = GetUnitState(udg_Gretel, UNIT_STATE_MAX_LIFE)
    local real percentHansel = currentHanselHP / maxHanselHP * 100.00
    local real percentGretel = currentGretelHP / maxGretelHP * 100.00
    
    if (percentHansel <= 75.00) then
        call BJDebugMsg("Hansel reached below 75%.")
        call DisableTrigger(GetTriggeringTrigger())
        set udg_boolHansel = true
        if TriggerEvaluate(gg_trg_Barrier) then
            call TriggerExecute(gg_trg_Barrier)
        endif
        if TriggerEvaluate(gg_trg_Enrager) then
            call TriggerExecute(gg_trg_Enrager)
        endif
        call TimerStart(udg_switchTimer, 60.00, false, null)
    endif
    if (percentGretel <= 75.00) then
        call BJDebugMsg("Gretel reached below 75%.")
        call DisableTrigger(GetTriggeringTrigger())
        set udg_boolGretel = true
        if TriggerEvaluate(gg_trg_Barrier) then
            call TriggerExecute(gg_trg_Barrier)
        endif
        if TriggerEvaluate(gg_trg_Enrager) then
            call TriggerExecute(gg_trg_Enrager)
        endif
        call TimerStart(udg_switchTimer, 60.00, false, null)
    endif

        
    return false
endfunction

//===========================================================================
function InitTrig_HealthReached takes nothing returns nothing
    set gg_trg_HealthReached = CreateTrigger()
    
    call TriggerRegisterTimerEvent(gg_trg_HealthReached, 0.0325, true)
    call TriggerAddCondition(gg_trg_HealthReached, Condition(function Trig_HealthReached_Actions))
    
    set gg_trg_HealthReached = null
endfunction

Trigger 2: Barrier
JASS:
function Trig_Barrier_Actions takes nothing returns nothing
    
    if udg_boolHansel == true then
        call PauseUnit(udg_Hansel, true)
        call SetUnitInvulnerable(udg_Hansel, true)
        call SetUnitAnimation(udg_Hansel, "Stand Channel")
        set udg_barrierFX = AddSpecialEffectTarget("Abilities\\Spells\\Undead\\AntiMagicShell\\AntiMagicShell.mdl", udg_Hansel, "chest")
    endif
    if udg_boolGretel == true then
        call PauseUnit(udg_Gretel, true)
        call SetUnitInvulnerable(udg_Gretel, true)
        call SetUnitAnimation(udg_Gretel, "Stand Channel")
        set udg_barrierFX = AddSpecialEffectTarget("Abilities\\Spells\\Undead\\AntiMagicShell\\AntiMagicShell.mdl", udg_Gretel, "chest")
    endif
endfunction

//===========================================================================
function InitTrig_Barrier takes nothing returns nothing
    set gg_trg_Barrier = CreateTrigger(  )
    call TriggerAddAction( gg_trg_Barrier, function Trig_Barrier_Actions )
    
    call Preload("Abilities\\Spells\\Undead\\AntiMagicShell\\AntiMagicShell.mdl")
endfunction

Trigger 3: CleanUpSwitch
JASS:
function Trig_CleanUpSwitch_Actions takes nothing returns nothing

    call DestroyEffect(udg_barrierFX)
    if udg_boolHansel == true then
        call PauseUnit(udg_Hansel, false)
        call SetUnitInvulnerable(udg_Hansel, false)
        call SetUnitAnimation(udg_Hansel, "stand")
        set udg_boolHansel = false
        set udg_boolGretel = true
        call BJDebugMsg("boolHansel is now false.")
        if TriggerEvaluate(gg_trg_Barrier) then
            call TriggerExecute(gg_trg_Barrier)
        endif
        if TriggerEvaluate(gg_trg_Enrager) then
            call TriggerExecute(gg_trg_Enrager)
        endif
    elseif udg_boolGretel == true then
        call PauseUnit(udg_Gretel, false)
        call SetUnitInvulnerable(udg_Gretel, false)
        call SetUnitAnimation(udg_Gretel, "stand")
        set udg_boolGretel = false
        set udg_boolHansel = true
        call BJDebugMsg("boolGretel is now false.")
        if TriggerEvaluate(gg_trg_Barrier) then
            call TriggerExecute(gg_trg_Barrier)
        endif
        if TriggerEvaluate(gg_trg_Enrager) then
            call TriggerExecute(gg_trg_Enrager)
        endif
    endif

    call TimerStart(udg_switchTimer, 60.00, false, null)
endfunction

//===========================================================================
function InitTrig_CleanUpSwitch takes nothing returns nothing
    set gg_trg_CleanUpSwitch = CreateTrigger(  )
    call TriggerRegisterTimerExpireEvent( gg_trg_CleanUpSwitch, udg_switchTimer )
    call TriggerAddAction( gg_trg_CleanUpSwitch, function Trig_CleanUpSwitch_Actions )
endfunction
 
Status
Not open for further replies.
Top