Declaring Groups / Integers In One "Trigger", Using Them In Another

WolfieeifloW

WEHZ Helper
Reaction score
372
Up to this point, I've just been using "private constant <type> <name>".
But now I need to know how to declare a variable in one trigger object (scope I guess they're called) and carry it over to another.
Here's my code (at least, the parts that you guys need to see):
JASS:
globals
    private constant group crushedGroup
    private constant integer ability_ACid = &#039;A001&#039;
    private constant integer ability_ACBid = &#039;A002&#039;
    private constant integer buff_ACid = &#039;B001&#039;
    private constant integer buff_ACdid = &#039;B000&#039;
    private constant integer ability_ACdid = &#039;A000&#039;
    private constant integer dummyCaster = &#039;n000&#039;
    private constant integer dummyBuffer = &#039;n001&#039;
endglobals

How do I change those to be usable in other scopes?

EDIT: Also, how do I initialize that group?
 

Waaaaagh

I lost all my rep and my title being a jerk
Reaction score
70
change 'private' to 'public', and then, in other scopes, prefix it with whatever the scope is those things are declared in.

JASS:
set DeclarationScope_crushedGroup = CreateGroup()
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Where do I set that group?
Or do I change the line I have to that?

JASS:
// +----------------------------------------------------------+
// |                                                          |
// |       -=-=- Armor Crush by Wolfie[NoCT] v1.0 -=-=-       |
// |                                                          |
// +----------------------------------------------------------+
// |   -=-=- Version History -=-=-                            |
// |                                                          |
// |      Version 1.0                                         |
// |         - Initial version                                |
// |                                                          |
// +----------------------------------------------------------+

scope ArmorCrush initializer ACInit

// +-------------------------------------+
// |       -=-=- MODIFY HERE -=-=-       |
// |       -=-=- MODIFY HERE -=-=-       |
// |       -=-=- MODIFY HERE -=-=-       |
// +-------------------------------------+

globals
    public constant group crushedGroup
    public constant integer ability_ACid = &#039;A001&#039;
    public constant integer ability_ACBid = &#039;A002&#039;
    public constant integer buff_ACid = &#039;B001&#039;
    public constant integer buff_ACdid = &#039;B000&#039;
    public constant integer ability_ACdid = &#039;A000&#039;
    public constant integer dummyCaster = &#039;n000&#039;
    public constant integer dummyBuffer = &#039;n001&#039;
    private constant integer crushMin = 1
    private constant integer crushMax = 100
    private constant integer crushChance = 15
    private constant integer crushStack = 3
    private constant sound crushSound = gg_snd_Feedback
    private constant integer crushSoundVolume = 100
    private constant string crushSFX = &quot;Abilities\\Spells\\Items\\ResourceItems\\ResourceEffectTarget.mdl&quot;
    private constant string crushAttach = &quot;overhead&quot;
    private constant attacktype attackType = ATTACK_TYPE_NORMAL
    private constant damagetype damageType = DAMAGE_TYPE_NORMAL
    private constant real crushReturn = 0.02
    private constant real tOffset = 0
    private constant real tSize = 10
    private constant real tRed = 0
    private constant real tGreen = 0
    private constant real tBlue = 100
    private constant real tTrans = 0
    private constant real tLife = 3
    private constant real tAge = 2
    private constant real tVelocity = 75
    private constant real tDegrees = 90
    private constant string buffCommand = &quot;innerfire&quot;
endglobals

// +---------------------------------------+
// |       -=-=- END OF MODIFY -=-=-       |
// |       -=-=- END OF MODIFY -=-=-       |
// |       -=-=- END OF MODIFY -=-=-       |
// +---------------------------------------+

private function Conditions takes nothing returns boolean
    if (GetRandomInt(crushMin, crushMax) &lt;= crushChance) then
        return true
    else
        return false
    endif
    if GetUnitAbilityLevel(GetTriggerUnit(), buff_ACid) &gt; 0 then
        return true
    else
        return false
    endif
endfunction

private function CGConditions takes nothing returns boolean
    if IsUnitInGroup(GetAttacker(), crushedGroup) then
        return true
    else
        return false
    endif
endfunction

private function CVConditions takes nothing returns boolean
    if (GetUnitUserData(GetAttacker()) &lt; crushStack) then
        return true
    else
        return false
    endif
endfunction

private function Actions takes nothing returns nothing
    local location tempPoint = GetUnitLoc(GetAttacker())
    local integer array damageAttacker

    call AddSpecialEffectTargetUnitBJ(crushAttach, GetAttacker(), crushSFX)
    call DestroyEffect(GetLastCreatedEffectBJ())
    call PlaySoundOnUnitBJ(crushSound, crushSoundVolume, GetAttacker())
    set damageAttacker[0] = R2I(GetUnitStateSwap(UNIT_STATE_LIFE, GetAttacker()))
    call UnitDamageTargetBJ(GetAttackedUnitBJ(), GetAttacker(), (GetUnitStateSwap(UNIT_STATE_LIFE, GetAttackedUnitBJ()) * (crushReturn * I2R(GetUnitAbilityLevelSwapped(ability_ACid, GetAttackedUnitBJ())))), attackType, damageType)
    call CreateNUnitsAtLoc(1, dummyCaster, GetOwningPlayer(GetAttackedUnitBJ()), tempPoint, bj_UNIT_FACING)
    call UnitApplyTimedLifeBJ(2.00, &#039;BTLF&#039;, GetLastCreatedUnit())
    set damageAttacker[1] = R2I(GetUnitStateSwap(UNIT_STATE_LIFE, GetAttacker()))
    set damageAttacker[2] = (damageAttacker[0] - damageAttacker[1])
    call CreateTextTagUnitBJ((I2S(damageAttacker[2]) + &quot;!&quot; ), GetAttacker(), tOffset, tSize, tRed, tGreen, tBlue, tTrans)
    call SetTextTagPermanentBJ(GetLastCreatedTextTag(), false)
    call SetTextTagLifespanBJ(GetLastCreatedTextTag(), tLife)
    call SetTextTagFadepointBJ(GetLastCreatedTextTag(), tAge)
    call SetTextTagVelocityBJ(GetLastCreatedTextTag(), tVelocity, tDegrees)
    if (CVConditions()) then
        call SetUnitUserData(GetAttacker(), (GetUnitUserData(GetAttacker()) + 1))
        call SetUnitAbilityLevelSwapped(ability_ACdid, GetLastCreatedUnit(), (GetUnitUserData(GetAttacker()) * GetUnitAbilityLevelSwapped(ability_ACid, GetAttackedUnitBJ())))
        call IssueTargetOrder(GetLastCreatedUnit(), buffCommand, GetAttacker())
        if (CGConditions()) then
            call GroupAddUnitSimple(GetAttacker(), crushedGroup)
        else
        endif
    else
    endif
    call RemoveLocation(tempPoint)
endfunction

//===========================================================================
private function ACInit takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(trig, Condition(function Conditions))
    call TriggerAddAction(trig, function Actions)
endfunction

endscope

JASS:
// +----------------------------------------------------------+
// |                                                          |
// |       -=-=- Armor Crush by Wolfie[NoCT] v1.0 -=-=-       |
// |                                                          |
// +----------------------------------------------------------+
// |   -=-=- Version History -=-=-                            |
// |                                                          |
// |      Version 1.0                                         |
// |         - Initial version                                |
// |                                                          |
// +----------------------------------------------------------+

scope CGRemoval initializer CGRInit

private function Conditions takes nothing returns boolean
    if IsUnitGroupEmptyBJ(crushedGroup) then
        return false
    else
        return true
    endif
endfunction

private function BuffConditions takes nothing returns boolean
    if GetUnitAbilityLevel(GetTriggerUnit(), buff_ACdid) &gt; 0 then
        return true
    else
        return false
    endif
endfunction

private function GroupRemoveActions takes nothing returns nothing
    if (BuffConditions()) then
        call GroupRemoveUnitSimple(GetEnumUnit(),crushedGroup)
        call SetUnitUserData(GetEnumUnit(), 0)
    else
    endif
endfunction

private function Actions takes nothing returns nothing
    call ForGroupBJ(crushedGroup, function GroupRemoveActions)
endfunction

//===========================================================================
private function CGRInit takes nothing returns nothing
    local trigger trig = CreateTrigger()
    call TriggerRegisterTimerEventPeriodic(trig, 1.50)
    call TriggerAddCondition(trig, Condition(function Conditions))
    call TriggerAddAction(trig, function Actions)
endfunction

endscope
 

quraji

zap
Reaction score
144
To use public globals declared inside the ArmorCrush scope in another scope, add 'ArmorCrush_' to the variable name.

For example, you'd change this:

JASS:
private function Conditions takes nothing returns boolean
    if IsUnitGroupEmptyBJ(crushedGroup) then
        return false
    else
        return true
    endif
endfunction

to this:
JASS:
private function Conditions takes nothing returns boolean
    if IsUnitGroupEmptyBJ(ArmorCrush_crushedGroup) then
        return false
    else
        return true
    endif
endfunction
 

WolfieeifloW

WEHZ Helper
Reaction score
372
Yeah, I fixed that but forgot to edit the post.
I still need to know how to declare that unit group though.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
If those constants aren't used outside of your system by the end user, instead of making the variables public, just add all the triggers into the scope (well it's now a library if you choose to use my optimizations to your code :D). This will avoid naming conflicts etc.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top