1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. We have recently started the 16th edition of the Mini Mapping Contest. The theme is mini RPG. Do check it out and have fun.
    Dismiss Notice
  4. Choose your ride to damnation in the 5th Special Effect Contest Poll.
    Dismiss Notice
  5. The winners of the 13th Techtree Contest have been announced!
    Dismiss Notice
  6. The 13th Music Contest Poll has begun! Vote for the best tracks in this symphony of frost and flame.
    Dismiss Notice
  7. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[JASS] Item Upgrade Trigger

Discussion in 'Triggers & Scripts' started by chaoslord301, Jan 31, 2009.

  1. chaoslord301

    chaoslord301

    Joined:
    Sep 18, 2007
    Messages:
    105
    Resources:
    0
    Resources:
    0
    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:

    Boots
    Code (vJASS):
    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
     
  2. chaoslord301

    chaoslord301

    Joined:
    Sep 18, 2007
    Messages:
    105
    Resources:
    0
    Resources:
    0
  3. xAbysSx

    xAbysSx

    Joined:
    Aug 20, 2008
    Messages:
    53
    Resources:
    0
    Resources:
    0
    You really dont need all those separate condition functions, just use something like:
    Code (vJASS):
    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.