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

Item Reproduction System

Status
Not open for further replies.
Level 7
Joined
Feb 26, 2005
Messages
210
I'm trying a bit of an experiment for a map I am making. Instead of regenerating health and mana; I want heroes to require the use of healing items. So that a hero will not have to keep running back to shops to stay in the fight I want these items to generate in the hero's inventory periodically. The greater the Strength/Intelligence the faster the item generation.

I've already eliminated regeneration through advanced settings; the hard part is implementing the rest of the system. It will require JASS loops to be efficient. Here is the code so far:
JASS:
function Trig_Item_Reproduction_Conditions takes nothing returns boolean
    if ( not ( IsUnitType(GetSoldUnit(), UNIT_TYPE_HERO) == true ) ) then
        return false
    endif
    return true
endfunction

function Trig_Item_Reproduction_Actions takes nothing returns nothing
    local unit u = GetSoldUnit()
    loop
        call TriggerSleepAction( 15.00 )
        if GetUnitState(u, UNIT_STATE_LIFE) > 0 and UnitInventorySizeBJ(u) > UnitInventoryCount(u) then
            call UnitAddItemByIdSwapped( 'pghe', u )
        endif
    endloop
endfunction

//===========================================================================
function InitTrig_Item_Reproduction takes nothing returns nothing
    set gg_trg_Item_Reproduction = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Item_Reproduction, EVENT_PLAYER_UNIT_SELL )
    call TriggerAddCondition( gg_trg_Item_Reproduction, Condition( function Trig_Item_Reproduction_Conditions ) )
    call TriggerAddAction( gg_trg_Item_Reproduction, function Trig_Item_Reproduction_Actions )
endfunction
This code will give permanent item reproduction but is severely flawed. The loop needs to reset upon the hero's death, the timing of the loop needs to be Strength based, and I need a way for a simultaneous mana pot loop.
 
JASS:
globals
    integer array COUNTER
    unit array HERO
    integer IMAX = 0
endglobals

function setup takes nothing returns nothing
    set HERO[0] = gg_unit_Hpal_0000
    set HERO[1] = gg_unit_Hpal_0001
    set HERO[2] = gg_unit_Hpal_0002
    set HERO[3] = gg_unit_Hpal_0003
    set IMAX = 3
endfunction

function Trig_Test_Actions takes nothing returns nothing
    local integer i = 0
    
    loop
    exitwhen i > IMAX
    
        if GetUnitState(HERO[i], UNIT_STATE_LIFE) > 0 then
            set COUNTER[i] = COUNTER[i] + GetHeroInt(HERO[i], true)
            
            if COUNTER[i] > 1000 then
                set COUNTER[i] = COUNTER[i] - 1000
                call UnitAddItem(HERO[i], CreateItem('pghe', GetUnitX(HERO[i]), GetUnitY(HERO[i])))
            endif
            
        endif
        
    endloop
endfunction

//===========================================================================
function InitTrig_Test takes nothing returns nothing
    set gg_trg_Test = CreateTrigger( )
    call TriggerRegisterTimerEvent(gg_trg_Test, 1.00, true)
    call TriggerAddAction(gg_trg_Test, function Trig_Test_Actions )
    call setup()
endfunction

Just calculate exactly how many stats hero has, you can edit loop interval
call TriggerRegisterTimerEvent(gg_trg_Test, 1, true)

or Create your own formula here
set COUNTER[i] = COUNTER[i] + GetHeroInt(HERO[i], true)

Well just test it and see how will it work :)
 
Status
Not open for further replies.
Top