• 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] Armor and attack type changing system right here!

Status
Not open for further replies.
Level 37
Joined
Mar 6, 2006
Messages
9,243
Just finished coding it. I'm thinking of uploading it to the spell section.

You can pick up items and when you use the item, your attack or defence type changes depending on the item.

One can use any unit as the base unit. I'm using a Lich as the base unit in the test map.

I'm going to use this in my Powerslave map, and I think it is a very useful system for RPGs and I have not seen one before.

Comments, suggestions?

JASS:
library transformation initializer InitTrig_Transform

    globals
        private constant integer ABILID = 'A008'
        private constant integer BUFFID = 'Bbsk'
        private constant integer ORDERID = 852180
        private constant integer ITEMID = 'I000'
    
        hashtable TransHT = InitHashtable()
    endglobals
    
        //////////////////////////////////////////
        //      Attack Types    Armor Types     //
        //      1 = Normal      0 = Unarmored   //
        //      2 = Pierce      1 = Light       //
        //      3 = Siege       2 = Medium      //
        //      4 = Magic       3 = Heavy       //
        //      5 = Chaos       4 = Fortified   //
        //      6 = Spells      5 = Hero        //
        //      7 = Hero                        //
        //////////////////////////////////////////

    private function InitItems takes nothing returns nothing
        // Attack types
        call SaveInteger(TransHT, 'I000', 0, 0) // None
        call SaveInteger(TransHT, 'I000', 0, 10) // Normal
        call SaveInteger(TransHT, 'I001', 0, 20) // Pierce
        
        // Defence types
        call SaveInteger(TransHT, 'I002', 0, 0) // Unarmored
        call SaveInteger(TransHT, 'I002', 0, 2) // Medium
        call SaveInteger(TransHT, 'I003', 0, 3) // Heavy
        
        // Ability levels
        call SaveInteger(TransHT, 0, 0, 1)  // None Unarmored
        call SaveInteger(TransHT, 2, 0, 2)  // None Medium
        call SaveInteger(TransHT, 3, 0, 3)  // None Heavy
        call SaveInteger(TransHT, 10, 0, 4) // Normal Unarmored
        call SaveInteger(TransHT, 12, 0, 5) // Normal Medium
        call SaveInteger(TransHT, 13, 0, 6) // Normal Heavy
        call SaveInteger(TransHT, 20, 0, 7) // Pierce Unarmored
        call SaveInteger(TransHT, 22, 0, 8) // Pierce Medium
        call SaveInteger(TransHT, 23, 0, 9) // Pierce Heavy
    endfunction
    
    // Initializes units for the system
    function InitTransUnit takes unit u returns nothing
        local item it = UnitAddItemById(u, ITEMID)
        call UnitUseItem(u, it)
        call RemoveItem(it)
        set it = null
    endfunction
    
    // Updates attack and defence types
    private function Update takes unit u, integer lev returns nothing
        call SetPlayerAbilityAvailable(GetTriggerPlayer(), ABILID, true)
        call UnitRemoveAbility(u, ABILID)
        call UnitAddAbility(u, ABILID)
        call SetUnitAbilityLevel(u, ABILID, lev)
        call IssueImmediateOrderById(u, ORDERID)
        call SetPlayerAbilityAvailable(GetTriggerPlayer(), ABILID, false)
    endfunction
    
    private function UseIt takes nothing returns nothing
        local unit u
        local integer id
        local integer lev
        local item it = GetManipulatedItem()
        local integer ityp = GetItemTypeId(it)
        local integer ind = LoadInteger(TransHT, ityp, 0)
        // If ind is 0, then the item will not change armor of attack type
        if ind != 0 then
            set u = GetTriggerUnit()
            set id = GetHandleId(u)
            // If ind is greater than 9, it changes attack, otherwise armor
            if ind > 9 then
                if ityp != GetItemTypeId(LoadItemHandle(TransHT, id, 2)) then
                    // Store new attack type
                    call SaveInteger(TransHT, id, 0, ind)
                    // Store current attack item
                    call SaveItemHandle(TransHT, id, 2, it)
                    // Load current defence level and calculate new ability level
                    set lev = LoadInteger(TransHT, ind + LoadInteger(TransHT, id, 1), 0)
                    call Update(u, lev)
                endif
            elseif ityp != GetItemTypeId(LoadItemHandle(TransHT, id, 3)) then
                // Store new defence type
                call SaveInteger(TransHT, id, 1, ind)
                // Store current defence item
                call SaveItemHandle(TransHT, id, 3, it)
                // Load current defence level and calculate new ability level
                set lev = LoadInteger(TransHT, ind + LoadInteger(TransHT, id, 0), 0)
                call Update(u, lev)
            endif
            call UnitRemoveAbility(u, BUFFID)
            set u = null
        endif
        set it = null
    endfunction
    
    private function LoseIt takes nothing returns nothing
        local unit u = GetTriggerUnit()
        local integer id = GetHandleId(u)
        
        // Is current active attack type item
        if GetManipulatedItem() == LoadItemHandle(TransHT, id, 2) then
            call SaveInteger(TransHT, id, 0, 0)
            call RemoveSavedHandle(TransHT, id, 2)
            call Update(u, LoadInteger(TransHT, id, 1))
        // Is current active defence type item
        elseif GetManipulatedItem() == LoadItemHandle(TransHT, id, 3) then
            call SaveInteger(TransHT, id, 1, 6)
            call RemoveSavedHandle(TransHT, id, 3)
            call Update(u, LoadInteger(TransHT, id, 0))
        endif
        
        set u = null
    endfunction

    private function InitTrig_Transform takes nothing returns nothing
        local integer i = 0
        
        local trigger t1 = CreateTrigger()
        local trigger t2 = CreateTrigger()
        call TriggerAddAction(t1, function UseIt)
        call TriggerAddAction(t2, function LoseIt)
        
        loop
            call TriggerRegisterPlayerUnitEvent(t1, Player(i), EVENT_PLAYER_UNIT_USE_ITEM, null)
            call TriggerRegisterPlayerUnitEvent(t2, Player(i), EVENT_PLAYER_UNIT_DROP_ITEM, null)
            exitwhen i == 15
            set i = i + 1
        endloop
        
        call InitItems()
    endfunction
    
endlibrary
 

Attachments

  • ArmorDefenceChange.w3x
    24.7 KB · Views: 57
Last edited:
It was only a matter of time when someone will face that problem, problem about changing attack/defense types.

I'm glad that it was you :D
Since I just learnt the basic of vJass, I don't know much about ways for improving efficiency in that script language, so I dont see/cant help with it, if something could be improved ;/

For sure it will be usefull for many multiplayer maps. The next cool thing the map can contain!

By the way Maker, PLEASE write what to do in map, at the begining via message. Most people just dl, and check/open without reading instructions here, hoping for tips inside :p
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
The jass code is insignificant, what matters is the basic mechanic you build on or strategy you pursue. Since you had not told of it here, I had to take a look into the map.

You morph the unit into other unit types, which contain a combination of the wanted attack and defense type. Of course, this won't just affect atk/def but all other stats of the unit and what else comes with morphing. The map transformed the Lich into a unit with Footman model. If you wanted to keep the model, each unit type would need its own set of corresponding alternative types, featuring different atk/def, resulting in a mass of object editor objects.

There are still more problems, for example, you order the unit to cast Metamorphose, which will interrupt current other orders.

Actually, I think everyone had already thought of changing atk/def by changing the unit type.
 
Level 7
Joined
Feb 9, 2010
Messages
298
Hey fellows does that mean that I can use this thing just to change the armor type or I have to morph/change the unit also?!:vw_wtf:
I got confused!!!

My question is - Can I use it to solve this problem?

When a time based spell is cast (ex.: Slow) the affected unit's armor changes to another type for the duration of the spell. After the spell's duration is up, this unit's armor returns to the "original" armor type of the Unit.

Or in case it is easier:

Need a system/way any damage taken by the unit affected by the spell should be reduced to 0 for the duration of the spell only.

Any questions?
 
Status
Not open for further replies.
Top