• 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] efficiency trigger!!!

Status
Not open for further replies.
Level 6
Joined
Apr 23, 2011
Messages
182
Hi, i am trying to create along with this system :

http://www.hiveworkshop.com/forums/...tem-133050/?prev=search=inventory&d=list&r=20 made by The Wicther.

A custom stat item gain. Soo for each type of item when is picked up i add custom stats the the hero.

My question is: Is better to create many many triggers or just one with many conditions? Also maybe transform it into jass ?

JASS:
unction Trig_item_stats_Conditions takes nothing returns boolean
    if ( not ( GetItemTypeId(GetOrderTargetItem()) == 'kysn' ) ) then
        return false
    endif
    return true
endfunction

function Trig_item_stats_Actions takes nothing returns nothing
    // Then here I add the custom stats
    call ModifyHeroStat( bj_HEROSTAT_STR, udg_u, bj_MODIFYMETHOD_ADD, 5 )
    call ModifyHeroStat( bj_HEROSTAT_AGI, udg_u, bj_MODIFYMETHOD_ADD, 4 )
endfunction

//===========================================================================
function InitTrig_item_stats takes nothing returns nothing
    set gg_trg_item_stats = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_item_stats, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddCondition( gg_trg_item_stats, Condition( function Trig_item_stats_Conditions ) )
    call TriggerAddAction( gg_trg_item_stats, function Trig_item_stats_Actions )
endfunction



JASS:
function Trig_item_stats_Func002C takes nothing returns boolean
    if ( not ( GetItemTypeId(GetOrderTargetItem()) == 'kysn' ) ) then
        return false
    endif
    return true
endfunction

function Trig_item_stats_Func003C takes nothing returns boolean
    if ( not ( GetItemTypeId(GetOrderTargetItem()) == 'ratf' ) ) then
        return false
    endif
    return true
endfunction

function Trig_item_stats_Actions takes nothing returns nothing
    // With conditions
    if ( Trig_item_stats_Func002C() ) then
        call ModifyHeroStat( bj_HEROSTAT_AGI, udg_u, bj_MODIFYMETHOD_ADD, 4 )
        call ModifyHeroStat( bj_HEROSTAT_STR, udg_u, bj_MODIFYMETHOD_ADD, 5 )
    else
    endif
    if ( Trig_item_stats_Func003C() ) then
        call ModifyHeroStat( bj_HEROSTAT_AGI, udg_u, bj_MODIFYMETHOD_ADD, 700 )
    else
    endif
endfunction

//===========================================================================
function InitTrig_item_stats takes nothing returns nothing
    set gg_trg_item_stats = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_item_stats, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    call TriggerAddAction( gg_trg_item_stats, function Trig_item_stats_Actions )
endfunction

Thanks for your time ^^
 
Level 17
Joined
Feb 11, 2011
Messages
1,860
It's probably better to create one trigger with many conditions. Your JASS can be improved though :p

JASS:
function OnOrder takes nothing returns boolean
    // Store item type:
    local integer itemType = GetItemTypeId(GetOrderTargetItem())
    
    if (itemType == 'kysn') then
        call SetHeroAgi(udg_u, GetHeroAgi(udg_u, true) + 4, true)
        call SetHeroStr(udg_u, GetHeroStr(udg_u, true) + 5, true)
    elseif (itemType == 'ratf') then
        call SetHeroAgi(udg_u, GetHeroAgi(udg_u, true) + 700, true)
    endif
    
    return false
endfunction

function InitTrig_item_stats takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
    // Adding a condition is more efficient than an action.
    // Just make the function return a boolean and return false at the end.
    call TriggerAddCondition(t, Condition(function OnOrder))
endfunction
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
You could create a single function with all the possible stat modifications, and store in the Item Type ID all of them. When you pick the item you retrieve the data from the item and do the modifications, even if they're "0".
 
Level 6
Joined
Apr 23, 2011
Messages
182
okey i get it Mr bean thanks i will do it. But... Just to be specific if i have like 100 items ID it will be okey all in one trigger??

Spartipilo i have like 10 custom stats i dont know how to store all that in item type id.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
JASS:
// This function is to store item data
function StoreItemData takes integer ItemTypeId, real stat1, real stat2, real stat3, real stat4, real stat6, real stat7, real stat8, real stat9, real stat10, returns nothing
    local integer looper = 0
    local real array a

    set a[1] = stat1
    set a[2] = stat2
    set a[3] = stat3
    set a[4] = stat4
    set a[5] = stat5
    set a[6] = stat6
    set a[7] = stat7
    set a[8] = stat8
    set a[9] = stat9
    set a[10] = stat10

    loop
        exitwhen looper == 11
        if a[looper] != 0 then
            call SaveReal(SomeHashtable, ItemTypeId, looper, a[looper])
        endif
        set looper = looper+1
    endloop
endfunction

// This function is to assign the data to each item
function SetItemData takes nothing returns nothing

    call StoreItemData('I000', 0, 12, 1, 0, 0, 0, 5, 0, 2, 2)
    call StoreItemData('Ia2d', 7, 0, 1, 2, 5, 0, 2, 58, 8, 9)
    call StoreItemData('IGlS', 11, 5, 9, 2, 9, 0, 2, 4, 4, 4)

endfunction

Now, when a unit acquire/loose an item, you retrieve the data in a similar way it's stored to apply them to the unit. You just need to add your 100 items in the "SetUnitData" function just the way these 3 are stored. You run "SetItemData" on map init.

I don't know how do you use the data, if they're reals or integers or anything, so I can't help you further with the system.
 
Last edited:
Level 16
Joined
Dec 15, 2011
Messages
1,423
Why are you filtering negative bonuses? That would be kinda awkward for items with negative bonuses don't you think? Oh and btw your code will not compile due to a misplaced comma and a missing bracket. You may want to remind OP of that.

@OP: You will need an acquire/drop trigger and also a trigger for item pawning. I also wanted to know more about your system ;)
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I know Doom, I made it as an example/reference, not to copy/paste. But i didn't tough about negative bonuses. I'll change "a > 0" for "> != 0"

EDIT: Changes made
 
Status
Not open for further replies.
Top