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

[JASS] Item Upgrade Trigger

Status
Not open for further replies.
Level 4
Joined
Sep 18, 2007
Messages
104
Ok before we begin, I am just starting JASS, so don't be to harsh for my ignorance.

Well made a GUI item system that upgrades an item everytime you buy said item. I converted the system to JASS and tried optimizing it but I ran into problems and now the items won't combine properly.

Here's the trigger:

JASS:
globals
	integer ItemInt = 0
	effect SFX
	real x
	real y
	constant string STRING = "Abilities\\Spells\\Demon\\DarkPortal\\DarkPortalTarget.mdl"
	constant string ATTACH = "overhead"
	constant integer ITEM1 = 'I000'
	constant integer ITEM2 = 'I001'
	constant integer ITEM3 = 'I002'
endglobals
	
scope Boots initializer Init

private function Conditions takes nothing returns boolean
    if ( not ( GetItemTypeId(GetManipulatedItem()) == ITEM1 ) ) then
        return false
	endif
    return true
endfunction

private function Trig_Boots_ItemInt takes nothing returns boolean
    if ( not (ItemInt == 2) ) then
        return false
    endif
    return true
endfunction

private function Trig_Boots_Check takes nothing returns boolean
    if (not (GetItemTypeId(UnitItemInSlot(GetManipulatingUnit(), GetForLoopIndexA())) == ITEM1 ) ) then 
        return false
    endif
    return true
endfunction

private function Trig_Boots_1 takes nothing returns boolean
    return (GetItemTypeId(UnitItemInSlot(GetManipulatingUnit(), GetForLoopIndexA())) == ITEM1 )
endfunction

private function Trig_Boots_2 takes nothing returns boolean
    return GetItemTypeId(UnitItemInSlot(GetManipulatingUnit(), GetForLoopIndexA())) == ITEM2
endfunction

private function Trig_Boots_Func002Func001C takes nothing returns boolean
    if ( not GetBooleanOr( Trig_Boots_1(), Trig_Boots_2() ) ) then
        return false
    endif
    return true
endfunction

private function Actions takes nothing returns nothing
    set ItemInt = 0
    set bj_forLoopAIndex = 1
    set bj_forLoopAIndexEnd = 6
    loop
        exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
        if ( Trig_Boots_Func002Func001C() ) then
            if ( Trig_Boots_Check() ) then
                set ItemInt = ( ItemInt + 1 )
                if ( Trig_Boots_ItemInt() ) then
					set x = GetUnitX(GetManipulatingUnit())
				    set y = GetUnitY(GetManipulatingUnit())
					call AddSpecialEffectTarget( STRING, GetManipulatingUnit(), ATTACH )
					set SFX = GetLastCreatedEffectBJ()
					call RemoveItem( GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), ITEM1) )
                    call RemoveItem( GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), ITEM1) )
                    call CreateItem( ITEM2, x, y )
                    call UnitAddItem( GetManipulatingUnit(), GetLastCreatedItem() )
                    call DisplayTimedTextToPlayer(Player(0),0,0,60,"Debug1")
					call DestroyEffect(SFX)
					set x = 0
					set y = 0
                else
                endif
            else
			    set x = GetUnitX(GetManipulatingUnit())
				set y = GetUnitY(GetManipulatingUnit())
				call AddSpecialEffectTarget( STRING, GetManipulatingUnit(), ATTACH )
				set SFX = GetLastCreatedEffectBJ()
				call RemoveItem( GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), ITEM1) )
                call RemoveItem( GetItemOfTypeFromUnitBJ(GetManipulatingUnit(), ITEM2) )
                call CreateItem( ITEM3, x, y )
                call UnitAddItem( GetManipulatingUnit(), GetLastCreatedItem() )
                call DisplayTimedTextToPlayer(Player(0),0,0,60,"Debug2")
				call DestroyEffect(SFX)
				set x = 0
				set y = 0
            endif
        else
        endif
        set bj_forLoopAIndex = bj_forLoopAIndex + 1
    endloop
endfunction

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

endscope
 
Level 3
Joined
Aug 20, 2008
Messages
54
You really dont need all those separate condition functions, just use something like:
JASS:
scope Boots initializer Init
private function Combine takes nothing returns nothing
    if (UnitHasItemOfType(GetManipulatingUnit()), ITEM1) == true then
        if (UnitHasItemOfType(GetManipulatingUnit()), ITEM2) == true then
            //Do the rest of whats in your actions, those two mean the unit must have both items for the trigger to work.
        endif
    endif
endfunction

//===========================================================================
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition(t, Condition(function Conditions))
call TriggerAddAction(t, function Actions)
set t = null
//Dont forget to null t
endfunction

endscope
And also you dont need to use the "else" actions...
Oh and youre also using ITEM1 and ITEM2 for the recipe, your Creating ITEM2 and not ITEM3, and you should give the item to the unit instead of making it at its location.
 
Status
Not open for further replies.
Top