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

VJass Optimization and / or alternative

Status
Not open for further replies.
Level 10
Joined
Feb 7, 2005
Messages
409
Hey guys, I'm using a VJass system but am myself not very good at it, the system works as follows: unit uses item, create ability for unit based on item, move item to other hero labelled "equipment" so far everything works fine so I'll leave that out, my problem is when they equip a ranged weapon. In order to convert their attack from melee to ranged I replace the unit entirely, my dilemma is that I need different units when equipping the same item to turn into different ranged copies.

e.x. Agility primary hero equips bow, replace primary hero with agility primary bow user
Strength primary hero equips bow, replace primary hero with strength bow user

I decided to use point values for this, and when equipping and unequipping a ranged weapon it works fine, the problem appears when you try to equip a ranged weapon while already having a ranged weapon equipped.

here's the code in VJass for unequipping a ranged weapon (equipping is the same except the unit replaced is a different variable)

JASS:
        if onehandinteger[i] == 15 then
            call ReplaceUnitBJ( dat.owner, udg_MeleeUnit[GetUnitPointValue(dat.owner) - 100], bj_UNIT_STATE_METHOD_MAXIMUM )
            call SaveEffectHandle(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 8, LoadEffectHandle(udg_Hash_Fashion, udg_FashionHandle, 8) )
            call SaveEffectHandle(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 17, LoadEffectHandle(udg_Hash_Fashion, udg_FashionHandle, 17) )
            call SaveEffectHandle(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 0, LoadEffectHandle(udg_Hash_Fashion, udg_FashionHandle, 0) )
            call SaveEffectHandle(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 5, LoadEffectHandle(udg_Hash_Fashion, udg_FashionHandle, 5) )
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 1, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 1))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 2, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 2))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 3, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 3))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 4, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 4))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 6, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 6))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 7, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 7))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 9, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 9))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 10, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 10))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 11, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 11))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 12, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 12))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 13, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 13))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 14, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 14))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 15, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 15))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 16, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 16))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 18, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 18))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 19, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 19))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 20, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 20))
            call SaveStr(udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 21, LoadStr(udg_Hash_Fashion, udg_FashionHandle, 21))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 22, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 22))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 23, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 23))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 24, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 24))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 25, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 25))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 26, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 26))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 27, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 27))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 28, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 28))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 29, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 29))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 30, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 30))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 31, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 31))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 32, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 32))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 33, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 33))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 34, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 34))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 35, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 35))
            call SaveBoolean( udg_Hash_Fashion, GetHandleId(GetLastReplacedUnitBJ()), 37, LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 37))
            if ( LoadBoolean(udg_Hash_Fashion, udg_FashionHandle, 37) == true ) then
                call SetUnitVertexColor( GetLastReplacedUnitBJ(), 100, 100, 100, 50 )   
            endif
            call TransferEquipment(dat.owner, GetLastReplacedUnitBJ())
            call FlushChildHashtable(udg_Hash_Fashion, udg_FashionHandle)
            call SetHeroStr(GetLastReplacedUnitBJ(),str,true)
            call SetHeroAgi(GetLastReplacedUnitBJ(),agi,true)
            call SetHeroInt(GetLastReplacedUnitBJ(),int,true)
            call TriggerExecute( gg_trg_HeroAbilityFix )
            call TriggerExecute( gg_trg_HeroAnimationFix )
            set udg_HeroUnit[GetConvertedPlayerId(GetOwningPlayer(dat.owner))] = GetLastReplacedUnitBJ()
            set dat.owner = GetLastReplacedUnitBJ()
            call SelectUnitForPlayerSingle(dat.owner, GetOwningPlayer(dat.owner))
        endif

I know this is probably needlessly long, in short what it does is register if the weapon is ranged (the onehandinteger check) then replaces the unit, transfers all hashtable data, transfers inventory, flushes data, sets stats, executes animation and ability fix triggers, transfers variable data then selects the unit.

Now, for equipping to work each ranged unit must have different point values, however these point values clash when equipping another ranged weapon, causing your character to turn into say an int primary or str primary when you're agility, I need a work around that doesn't use as much code as I've already used. (the above code is used about 5 times throughout the trigger, heh)
 
Status
Not open for further replies.
Top