TriggerHappy
...
- Reaction score
- 341
Attach v0.01
TriggerHappy187
If it weren't for the (Item Attachment Management System) in the title you would've came here thinking this was another Struct/Timer attachment system. Well , its not even close to one. But then what is Attach? It's basically an item attachment management system. Have you ever wanted to create a Role Playing Game that using item attachments but you had two heroes with different attacking hands.
For Example , you attach a sword to the villager and he attacks with his left hand. Then the orc picks up the same sword but he attacks with his right hand. This system can specify what hand is the units weapon and which is his offhand easily.
Demo Usage
Trigger:
- AS Grab Item
- Events
- Unit - A unit Acquires an item
- Conditions
- Actions
- Custom script: local Attach a
- Custom script: if IsUnitRegistered(GetTriggerUnit()) == true then
- Custom script: call AttachEffect(GetTriggerUnit(), GetManipulatedItem())
- Custom script: else
- Custom script: call a.create(GetTriggerUnit())
- Custom script: call AttachEffect(GetTriggerUnit(), GetManipulatedItem())
- Custom script: endif
- Events
Other Uses
Setting Items
Dropping Items
Trigger:
- AS Set Items
- Events
- Time - Elapsed game time is 0.00 seconds
- Conditions
- Actions
- -------- Claws of attack --------
- Custom script: call AddItemEffect('ratf',"Objects\\InventoryItems\\HumanCaptureFlag\\HumanCaptureFlag.mdl", "weapon")
- Events
Dropping Items
Trigger:
- AS Drop Item
- Events
- Unit - A unit Loses an item
- Conditions
- Actions
- Custom script: local Attach a
- Custom script: if IsUnitRegistered(GetTriggerUnit()) == true then
- Custom script: call DettachEffect(GetTriggerUnit(), GetManipulatedItem())
- Custom script: else
- Custom script: call a.create(GetTriggerUnit())
- Custom script: call DettachEffect(GetTriggerUnit(), GetManipulatedItem())
- Custom script: endif
- Events
Source Code :
JASS:
library Attach
globals
private integer COUNT = 0
private integer ITEM_COUNT = 0
private integer array ITEM
private string array ITEM_TYPE
private string array ITEM_EFFECT
endglobals
struct Attach
unit u
string weapon = "left hand"
string offhand = "right hand"
effect cur_weapon
effect cur_offhand
static method create takes unit u returns Attach
local Attach a = Attach.allocate()
set a.u = u
set COUNT = COUNT + 1
return a
endmethod
endstruct
function IsUnitRegistered takes unit u returns boolean
local integer i = 0
local Attach a
loop
exitwhen i > COUNT
set a = i
if a.u == u then
return true
endif
set i = i + 1
endloop
return false
endfunction
function SetWeapon takes unit u, string weapon returns nothing
local integer i = 0
local Attach a
loop
exitwhen i > COUNT
set a = i
if a.u == u then
set a.weapon = weapon
endif
set i = i + 1
endloop
endfunction
function SetOffhand takes unit u, string offhand returns nothing
local integer i = 0
local Attach a
loop
exitwhen i > COUNT
set a = i
if a.u == u then
set a.weapon = offhand
endif
set i = i + 1
endloop
endfunction
function AttachEffect takes unit u, item itm returns nothing
local integer i = 0
local integer i2 = 0
local Attach a
loop
exitwhen i > COUNT
set a = i
if a.u == u then
loop
exitwhen i2 > COUNT
if GetItemTypeId(itm) == ITEM[i2] then
if ITEM_TYPE[i2] == "weapon" then
set a.cur_weapon = AddSpecialEffectTarget(ITEM_EFFECT[i2], a.u, a.weapon)
elseif ITEM_TYPE[i2] == "offhand" then
set a.cur_offhand = AddSpecialEffectTarget(ITEM_EFFECT[i2], a.u, a.offhand)
endif
endif
set i2 = i2 + 1
endloop
endif
set i = i + 1
endloop
endfunction
function DettachEffect takes unit u, item itm returns nothing
local integer i = 0
local integer i2 = 0
local Attach a
loop
exitwhen i > COUNT
set a = i
if a.u == u then
loop
exitwhen i2 > COUNT
if GetItemTypeId(itm) == ITEM[i2] then
if ITEM_TYPE[i2] == "weapon" then
call DestroyEffect(a.cur_weapon)
elseif ITEM_TYPE[i2] == "offhand" then
call DestroyEffect(a.cur_offhand)
endif
endif
set i2 = i2 + 1
endloop
endif
set i = i + 1
endloop
endfunction
function SetItemEffect takes integer itm, string fx returns nothing
local integer i = 0
loop
exitwhen i > ITEM_COUNT
if itm == ITEM<i> then
set ITEM<i> = itm
set ITEM_EFFECT<i> = fx
endif
set i = i + 1
endloop
endfunction
function AddItemEffect takes integer itm, string fx, string attachtype returns nothing
set ITEM[ITEM_COUNT] = itm
set ITEM_EFFECT[ITEM_COUNT] = fx
if attachtype == "weapon" then
set ITEM_TYPE[ITEM_COUNT] = attachtype
elseif attachtype == "offhand" then
set ITEM_TYPE[ITEM_COUNT] = attachtype
endif
set COUNT = COUNT + 1
endfunction
endlibrary
</i></i></i>