- 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?
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
Last edited: