• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Trigger] Unit group trigger/Income.

Status
Not open for further replies.
Level 4
Joined
Jul 22, 2012
Messages
72
Ok this is my trigger to make a unit group on control points because I have 145 different units Which are different control points, that get replaced when they die. So that way I can use one simple trigger to make income using unit group. Which I really don't know how to do anyway but I'm sure I can find that out.

Events
map Initalization
Conditions
Or - Any (Conditions) are true
Conditions
(Unit-type of (Triggering unit)) Equal to Undercity (30g/min)
(Unit-type of (Triggering unit)) Equal to Tomb of Saragaras (30g/min)
(Unit-type of (Triggering unit)) Equal to Icecrown Citadel (30g/min)
Actions
Unit Group - Add (Triggering unit) to Controlpoint30g


Will this work and will it leak?
And if you could make the income per minute trigger using unit group for me that would be nice.
 
Last edited:
Level 20
Joined
Jul 14, 2011
Messages
3,213
4 Triggers. I don't know how to create them all in a single one :(

Income Functions
JASS:
globals
    hashtable IncomeHash = InitHashtable()
    integer array IncomeAmount
    integer IncomeIndex = 0
    group IncomeGroup = CreateGroup()
endglobals

// Store Income Data
function IncomeData takes integer UnitType, integer Income returns nothing
    call SaveInteger(IncomeHash, UnitType, 0, IncomeIndex)
    call SaveBoolean(IncomeHash, UnitType, 1, true)
    set IncomeAmount[IncomeIndex] = Income
    set IncomeIndex = IncomeIndex+1
    call BJDebugMsg("Income Data Saved")
endfunction

// Retrieve Income 
function RetrieveIncome takes unit EnumUnit returns nothing
    local integer Index = LoadInteger(IncomeHash, GetUnitTypeId(EnumUnit), 0)
    local player p = GetOwningPlayer(EnumUnit)
    local integer state = GetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD)
    local integer income = IncomeAmount[Index]
    local texttag tt = CreateTextTag()
    
    call SetPlayerState(p, PLAYER_STATE_RESOURCE_GOLD, state + income)
    
    call SetTextTagText(tt, "+"+I2S(income), 0.023)
    call SetTextTagColor(tt, 255, 215, 0, 255)
    call SetTextTagPos(tt, GetUnitX(EnumUnit), GetUnitY(EnumUnit), 0)
    call SetTextTagPermanent(tt, false)
    call SetTextTagVelocity(tt, 0, 0.05)
    call SetTextTagLifespan(tt, 2)
    call SetTextTagFadepoint(tt, 1)
    
    set tt = null
    set p = null
endfunction

Income Unit Check
JASS:
function Income_UnitCheck takes nothing returns nothing
    if LoadBoolean(IncomeHash, GetUnitTypeId(GetTriggerUnit()), 1) == true then
        call GroupAddUnit(IncomeGroup, GetTriggerUnit())
    endif
    call BJDebugMsg("Unit gives income")
endfunction

//===========================================================================
function InitTrig_IncomeUnitCheck takes nothing returns nothing
    set gg_trg_IncomeUnitCheck = CreateTrigger(  )
    call TriggerRegisterEnterRectSimple( gg_trg_IncomeUnitCheck , bj_mapInitialPlayableArea )
    call TriggerAddAction( gg_trg_IncomeUnitCheck , function Income_UnitCheck )
endfunction

Income UnitDead
JASS:
// Remove Dead Units from Group
function Income_UnitDied takes nothing returns nothing
    call GroupRemoveUnit(IncomeGroup, GetTriggerUnit())
    call BJDebugMsg("Unit Died so it's Removed")
endfunction

//===========================================================================
function InitTrig_Income_UnitDead takes nothing returns nothing
    set gg_trg_Income_UnitDead = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Income_UnitDead, EVENT_PLAYER_UNIT_DEATH)
    call TriggerAddAction( gg_trg_Income_UnitDead, function Income_UnitDied)
endfunction

Income Periodic

JASS:
// Group Actions
function Income_GroupActions takes nothing returns nothing
    call RetrieveIncome(GetEnumUnit())
endfunction

// Group action call
function Income_Periodic_Actions takes nothing returns nothing
    call ForGroup(IncomeGroup, function Income_GroupActions)
    call BJDebugMsg("Periodic Triggered")
endfunction

//===========================================================================
function InitTrig_Income_Periodic takes nothing returns nothing
    set gg_trg_Income_Periodic = CreateTrigger(  )
    call TriggerRegisterTimerEvent(gg_trg_Income_Periodic, 5, true)
    call TriggerAddAction( gg_trg_Income_Periodic, function Income_Periodic_Actions )
endfunction

Implementation
  • Untitled Trigger 001
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Custom script: call IncomeData('Hpal', 20)
For testing purposes
  • Untitled Trigger 002
    • Events
      • Player - Player 1 (Red) skips a cinematic sequence
    • Conditions
    • Actions
      • Unit - Create 1 Paladin for Player 1 (Red) at (Player 1 (Red) start location) facing Default building facing degrees
 

Attachments

  • IncomeSys.w3x
    17.9 KB · Views: 33
Last edited:
Status
Not open for further replies.
Top