• 🏆 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!

[JASS] Need help linking trigger

Status
Not open for further replies.

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
hi people ^^

i am still trying hard to get my system working...
since i can't do struct because i sux at coding, i am trying to do it with normal triggers...
but it seems i have problem linking those 2.

[Jass=]
function callRecipe takes nothing returns nothing
local integer i = 0
local integer abi
set udg_hero = GetTriggerUnit()
set udg_owner = GetOwningPlayer(udg_hero)
set abi = GetSpellAbilityId()
loop
if abi == LoadIntegerBJ(1, i, udg_recipe) then
set udg_marker = i
call TriggerExecute( gg_trg_RecipeSystem(udg_hero, udg_owner, udg_marker) )
return
endif
exitwhen i == udg_itemCounter
set i = i + 1
endloop
set abi = 0
set udg_marker = 0
set udg_hero = null
set udg_owner = null
endfunction

//===========================================================================
function InitTrig_RecipeSystem_Check takes nothing returns nothing
set gg_trg_RecipeSystem_Check = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_RecipeSystem_Check, EVENT_PLAYER_UNIT_SPELL_CAST )
call TriggerAddAction( gg_trg_RecipeSystem_Check, function Trig_callRecipe )
endfunction[/code]

[Jass=]
function RecipeMain takes unit udg_hero, player udg_owner, integer udg_marker returns nothing
local integer array id
local integer array ic
local integer array n
local integer array md
local integer i = 1
local integer j = 1
local item ti = null
loop
exitwhen i > 6
set id = GetItemTypeId(UnitItemInSlotBJ(udg_hero, i))
set ic = GetItemCharges(UnitItemInSlotBJ(udg_hero, i))
set ti = UnitItemInSlotBJ(udg_hero, i)
if ( id == LoadIntegerBJ(3, udg_marker, udg_recipe) ) and ( ti != null ) then
set n[1] = ( n[1] + ic )
call RemoveItem( UnitItemInSlotBJ(udg_hero, i) )
elseif ( id == LoadIntegerBJ(4, udg_marker, udg_recipe) ) and ( ti != null ) then
set n[2] = ( n[2] + ic )
call RemoveItem( ti )
elseif ( id == LoadIntegerBJ(5, udg_marker, udg_recipe) ) and ( ti != null ) then
set n[3] = ( n[3] + ic )
call RemoveItem( ti )
elseif ( id == LoadIntegerBJ(6, udg_marker, udg_recipe) ) and ( ti != null ) then
set n[4] = ( n[4] + ic )
call RemoveItem( ti )
elseif ( id == LoadIntegerBJ(7, udg_marker, udg_recipe) ) and ( ti != null ) then
set n[5] = ( n[5] + ic )
call RemoveItem( ti )
elseif ( id == LoadIntegerBJ(8, udg_marker, udg_recipe) ) and ( ti != null ) then
set n[6] = ( n[6] + ic )
call RemoveItem( ti )
endif
set ti = null
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 6
set id = 0
set ic = 0
set i = i + 1
endloop
set md[0] = LoadIntegerBJ(9, udg_marker, udg_recipe)
set md[6] = ModuloInteger(md[0], 10)
set md[0] = ( ( md[0] - md[6] ) / 10 )
set md[5] = ModuloInteger(md[0], 10)
set md[0] = ( ( md[0] - md[5] ) / 10 )
set md[4] = ModuloInteger(md[0], 10)
set md[0] = ( ( md[0] - md[4] ) / 10 )
set md[3] = ModuloInteger(md[0], 10)
set md[0] = ( ( md[0] - md[3] ) / 10 )
set md[2] = ModuloInteger(md[0], 10)
set md[0] = ( ( md[0] - md[2] ) / 10 )
set md[1] = ModuloInteger(md[0], 10)
if ( n[1] >= md[1] ) and ( n[2] >= md[2] ) and ( n[3] >= md[3] ) and ( n[4] >= md[4] ) and ( n[5] >= md[5] ) and ( n[6] >= md[6] ) then
set n[1] = ( n[1] - md[1] )
set n[2] = ( n[2] - md[2] )
set n[3] = ( n[3] - md[3] )
set n[4] = ( n[4] - md[4] )
set n[5] = ( n[5] - md[5] )
set n[6] = ( n[6] - md[6] )
call UnitAddItemByIdSwapped( LoadIntegerBJ(2, udg_marker, udg_recipe), udg_hero )
call DisplayTextToPlayer(udg_owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + LoadStringBJ(10, udg_marker, udg_recipe) ) )
else
call DisplayTextToPlayer(udg_owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz no resourcez for " + LoadStringBJ(10, udg_marker, udg_recipe) ) )
call DisplayTextToPlayer(udg_owner, 0.,0., LoadStringBJ(11, udg_marker, udg_recipe) )
endif
set i = 1
loop
exitwhen i > 6
if ( n > 0 ) then
set j = 1
loop
exitwhen j > n
call UnitAddItemByIdSwapped( LoadIntegerBJ((i + 2), udg_marker, udg_recipe), udg_hero )
set j = j + 1
endloop
endif
set i = i + 1
endloop
set i = 1
loop
exitwhen i > 6
set n = 0
set i = i + 1
endloop
set udg_marker = 0
set udg_owner = null
set udg_hero = null
endfunction

//===========================================================================
function InitTrig_RecipeSystem takes unit udg_hero, player udg_owner, integer udg_marker returns nothing
set gg_trg_RecipeSystem = CreateTrigger( )
call TriggerAddAction( gg_trg_RecipeSystem, function Trig_RecipeMain, udg_hero, udg_owner, udg_marker )
endfunction[/code]

it says too many arguments :
call TriggerAddAction( gg_trg_RecipeSystem, function Trig_RecipeMain, udg_hero, udg_owner, udg_marker )

but i have others with more arguments and it didn't stop them.

EDIT
well it did stop them also.... :(
how to do that? call trigger wich takes variable.....
 
Level 7
Joined
Jan 28, 2012
Messages
266
JASS:
function RecipeMain takes unit udg_hero, player udg_owner, integer udg_marker returns nothing
    local integer array id
    local integer array ic
    local integer array n
    local integer array md
    local integer i = 1
    local integer j = 1 
    local item ti = null
    loop
        exitwhen i > 6
        set id[i] = GetItemTypeId(UnitItemInSlotBJ(udg_hero, i))
        set ic[i] = GetItemCharges(UnitItemInSlotBJ(udg_hero, i))
        set ti = UnitItemInSlotBJ(udg_hero, i)
        if ( id[i] == LoadIntegerBJ(3, udg_marker, udg_recipe) ) and ( ti != null ) then
            set n[1] = ( n[1] + ic[i] )
            call RemoveItem( UnitItemInSlotBJ(udg_hero, i) )
        elseif ( id[i] == LoadIntegerBJ(4, udg_marker, udg_recipe) ) and ( ti != null ) then
            set n[2] = ( n[2] + ic[i] )
            call RemoveItem( ti )
        elseif ( id[i] == LoadIntegerBJ(5, udg_marker, udg_recipe) ) and ( ti != null ) then
            set n[3] = ( n[3] + ic[i] )
            call RemoveItem( ti )
        elseif ( id[i] == LoadIntegerBJ(6, udg_marker, udg_recipe) ) and ( ti != null ) then
            set n[4] = ( n[4] + ic[i] )
            call RemoveItem( ti )
        elseif ( id[i] == LoadIntegerBJ(7, udg_marker, udg_recipe) ) and ( ti != null ) then
            set n[5] = ( n[5] + ic[i] )
            call RemoveItem( ti )
        elseif ( id[i] == LoadIntegerBJ(8, udg_marker, udg_recipe) ) and ( ti != null ) then
            set n[6] = ( n[6] + ic[i] )
            call RemoveItem( ti )
        endif
        set ti = null
        set i = i + 1
    endloop
    set i = 1
    loop
        exitwhen i > 6
        set id[i] = 0
        set ic[i] = 0
        set i = i + 1
    endloop
    set md[0] = LoadIntegerBJ(9, udg_marker, udg_recipe)
    set md[6] = ModuloInteger(md[0], 10)
    set md[0] = ( ( md[0] - md[6] ) / 10 )
    set md[5] = ModuloInteger(md[0], 10)
    set md[0] = ( ( md[0] - md[5] ) / 10 )
    set md[4] = ModuloInteger(md[0], 10)
    set md[0] = ( ( md[0] - md[4] ) / 10 )
    set md[3] = ModuloInteger(md[0], 10)
    set md[0] = ( ( md[0] - md[3] ) / 10 )
    set md[2] = ModuloInteger(md[0], 10)
    set md[0] = ( ( md[0] - md[2] ) / 10 )
    set md[1] = ModuloInteger(md[0], 10)
    if ( n[1] >= md[1] ) and ( n[2] >= md[2] ) and ( n[3] >= md[3] ) and ( n[4] >= md[4] ) and ( n[5] >= md[5] ) and ( n[6] >= md[6] ) then
        set n[1] = ( n[1] - md[1] )
        set n[2] = ( n[2] - md[2] )
        set n[3] = ( n[3] - md[3] )
        set n[4] = ( n[4] - md[4] )
        set n[5] = ( n[5] - md[5] )
        set n[6] = ( n[6] - md[6] )
        call UnitAddItemByIdSwapped( LoadIntegerBJ(2, udg_marker, udg_recipe), udg_hero )
        call DisplayTextToPlayer(udg_owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz crafted " + LoadStringBJ(10, udg_marker, udg_recipe) ) )
    else
        call DisplayTextToPlayer(udg_owner, 0.,0., ( "|c0000c400Troll:|r |c00ffff64Me haz no resourcez for " + LoadStringBJ(10, udg_marker, udg_recipe) ) )
        call DisplayTextToPlayer(udg_owner, 0.,0., LoadStringBJ(11, udg_marker, udg_recipe) )
    endif    
    set i = 1
    loop
        exitwhen i > 6
        if ( n[i] > 0 ) then
            set j = 1
            loop
                exitwhen j > n[i]
                call UnitAddItemByIdSwapped( LoadIntegerBJ((i + 2), udg_marker, udg_recipe), udg_hero )
                set j = j + 1
            endloop            
        endif
        set i = i + 1
    endloop
    set i = 1
    loop
        exitwhen i > 6
        set n[i] = 0
        set i = i + 1
    endloop
    set udg_marker = 0
    set udg_owner = null
    set udg_hero = null 
endfunction

function callRecipe takes nothing returns nothing
    local integer i = 0
    local integer abi 
    set udg_hero = GetTriggerUnit()
    set udg_owner = GetOwningPlayer(udg_hero)
    set abi = GetSpellAbilityId()
    loop
        if abi == LoadIntegerBJ(1, i, udg_recipe) then
            set udg_marker = i
            call RecipeMain(udg_hero, udg_owner, udg_marker) 
            return
        endif
        exitwhen i == udg_itemCounter
        set i = i + 1
    endloop
    set abi = 0
    set udg_marker = 0
    set udg_hero = null
    set udg_owner = null
endfunction
       
//===========================================================================
function InitTrig_RecipeSystem_Check takes nothing returns nothing
    set gg_trg_RecipeSystem_Check = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_RecipeSystem_Check, EVENT_PLAYER_UNIT_SPELL_CAST )
    call TriggerAddAction( gg_trg_RecipeSystem_Check, function Trig_callRecipe )
endfunction
you could do this, or you could get rid of the arguments for Recipe Main, and just use globals
 
Level 12
Joined
Oct 16, 2010
Messages
680
theres no way a trigger takes variable:D

call TriggerAddAction( trigger , function)

when a trigger runs (called by you or fired by an event) it runs the added functions
use globals if you want to pass variables to an other trigger or combine them
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Thanks Ender
but actually i separated them because it didn't work the way you described
but i found a way to merge them again wich might work.
Thanks Lender
it is annoying that trigger don't take variable :p
but i actually luckily merged both trigger the blizzard.j GUI way

i did the :
if ( Trig_D001_Func001C() ) then
and added the boolean function on top....

callRecipe return boolean
end

So Mainrecipe
x
x
if (callRecipe) then
x
x
end

i also added globals since i had no choice....


I need to link another trigger but this is going to be harder....
I need to store integer into a hashtable but i need to do it in an efficient way if possible.

[Jass=]
unction Setup takes nothing returns nothing
call InitHashtableBJ( )
set udg_recipe = GetLastCreatedHashtableBJ()
//Recipe Name | AbiID| ItemID| Item1| Item2| Item3| Item4| Item5| Item6|Charge|stringname|stringtext|
// Variable | ai | i0 | i1 | i2 | i3 | i4 | i5 | i6 | i7 | iname |itext |
// Firecamp
call register1('A05R', 'wlsd','sbch', 'hval', 'clsd', 'bgst', 0, 0, 111100, "", "")
endfunction

//===========================================================================
function InitTrig_SetupRecipe takes nothing returns nothing
set gg_trg_SetupRecipe = CreateTrigger( )
call TriggerRegisterTimerEventSingle( gg_trg_SetupRecipe, 0.00 )
call TriggerAddAction( gg_trg_SetupRecipe, function Trig_Setup )
endfunction
[/code]

[Jass=]
function register1 takes integer ai, integer i0, integer i1,integer i2, integer i3,integer i4, integer i5,integer i6, integer i7, string iname, string itext returns nothing
call SaveIntegerBJ( ai, 1, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( i0, 2, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( i1, 3, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( i2, 4, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( i3, 5, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( i4, 6, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( i5, 7, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( i6, 8, udg_itemCounter, udg_recipe )
call SaveIntegerBJ( i7, 9, udg_itemCounter, udg_recipe )
call SaveStringBJ( iname, 10, udg_itemCounter, udg_recipe )
call SaveStringBJ( itext, 11, udg_itemCounter, udg_recipe )
set udg_itemCounter = udg_itemCounter + 1
endfunction

//===========================================================================
function InitTrig_RegisterRecipe1 takes nothing returns nothing
set gg_trg_RegisterRecipe1 = CreateTrigger( )
call TriggerAddAction( gg_trg_RegisterRecipe1, function Trig_register1 )
endfunction
[/code]

if i do this it says:
Undefined functionTrig_register1
Undefined functionTrig_Setup

i am not sure how to do this.....??
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Arhowk
as usual you are very helpfull thanks a lot...

if you have some time when not writing comment try to past both code in editor and make them work...
if you succeed then that mean you did something that i didn't, and i would be dying to know it is?
saying random stuff without testing, even though most of it is true doesn't help my problem.

if you know how to not use Bj, then instead of saying pfff, just tell me what to put in the code. that would be much faster because that almost 4 day i am working on this system and it still doesn't work...

^^
 

ABM

ABM

Level 7
Joined
Jul 13, 2005
Messages
279
Thanks Arhowk for this constructive help...
i will try to look carefully at his system to see if i can find some clue to help mine.
 
Status
Not open for further replies.
Top