TriggerHappy
...
- Reaction score
- 341
Advanced Equipment System
TriggerHappy187
Documentation
JASS:
//***************************************************************************
//*
//* Equipment System - By TriggerHappy187
//*
//***************************************************************************
//*
//* Installation
//* + Copy the Equipment System folder to your map
//* + Copy all of the abilities, and items into your map
//* + Make sure you have the bonus mod in your map (just copy the bonus folder)
//* + If you don't want to copy the abilitys, just enable the bonus plugins trigger, though it will increase save time.
//***************************************************************************
//*
//* Documentation
//* This equipment system allows your unit to have regular items
//* and items that are "equipped".
//*
//***************************************************************************
//*
//* The Functions
//*
//* EquipmentItem registers an item for the system.
//*
//* UnitExtendEquipment registers a unit for the system.
//*
//***************************************************************************
Requires
- JNGP or JassHelper
- Bonus. (included in demo)
Usage
There are only two public functions in this system, and thats all you will need.
- JASS:
function EquipmentItem
This function is used to register an item for the system, it lets you specify the item type, and bonuses. - JASS:
function UnitExtendEquipment
registers a unit for the system.
Code
JASS:
//***************************************************************************
//*
//* Equipment System - By TriggerHappy187
//*
//***************************************************************************
//*
//* Installation
//* + Copy the Equipment System folder to your map
//* + Copy all of the abilities, and items into your map
//* + Make sure you have the bonus mod in your map (just copy the bonus folder)
//* + If you don't want to copy the abilitys, just enable the bonus plugins trigger, though it will increase save time.
//***************************************************************************
//*
//* Documentation
//* This equipment system allows your unit to have regular items
//* and items that are "equipped".
//*
//***************************************************************************
//*
//* The Functions
//*
//* EquipmentItem registers an item for the system.
//*
//* UnitExtendEquipment registers a unit for the system.
//*
//***************************************************************************
library EQSys initializer Init requires Bonus
globals
private constant integer OPEN_INV = 039;I000039;
private constant integer CLOSE_INV = 039;I001039;
private constant integer WEAPON = 039;I002039;
private constant integer ARMOR = 039;I006039;
private constant integer ACCESSORY = 039;I005039;
private constant integer OFFHAND = 039;I003039;
private constant integer HELMET = 039;I004039;
endglobals
globals
private gamecache g
integer EQUIPMENT_WEAPON = 0
integer EQUIPMENT_ARMOR = 1
integer EQUIPMENT_ACCESSORY = 3
integer EQUIPMENT_OFFHAND = 4
integer EQUIPMENT_HELMET = 2
private integer array gettype
private integer array thetype
endglobals
private function U2I takes unit u returns integer
return u
return 0
endfunction
private function GetUnitId takes unit u returns string
return I2S(U2I(u)-0x100000)
endfunction
private function Conditions1 takes nothing returns boolean
return GetItemTypeId(GetManipulatedItem()) == OPEN_INV
endfunction
private function Conditions2 takes nothing returns boolean
return GetItemTypeId(GetManipulatedItem()) == CLOSE_INV
endfunction
private struct data
integer array itm[6]
integer array inv[6]
trigger open = CreateTrigger()
trigger close = CreateTrigger()
boolean inInv = false
boolean hasRoom
static method openBag takes nothing returns nothing
local unit u = GetTriggerUnit()
local data d = GetStoredInteger(g, "struct", GetUnitId(u))
local integer i = 0
set d.hasRoom = false
loop
exitwhen i == 6
set d.inv<i> = GetItemTypeId(UnitItemInSlot(u, i))
if GetItemName(UnitItemInSlot(u, i)) == null then
set d.hasRoom = true
endif
call RemoveItem(UnitItemInSlot(u, i))
call UnitDropItemSlot(u, UnitAddItemById(u, d.itm<i>), i)
call SetItemDroppable(UnitItemInSlot(u, i), false)
set i = i + 1
endloop
set d.inInv = true
call UnitDropItemSlot(u, UnitAddItemById(u, CLOSE_INV), 5)
endmethod
static method closeBag takes nothing returns nothing
local unit u = GetTriggerUnit()
local data d = GetStoredInteger(g, "struct", GetUnitId(u))
local integer i = 0
call RemoveItem(UnitItemInSlot(u, 5))
loop
exitwhen i == 6
set d.itm<i> = GetItemTypeId(UnitItemInSlot(u, i))
call RemoveItem(UnitItemInSlot(u, i))
call UnitDropItemSlot(u, UnitAddItemById(u, d.inv<i>), i)
call SetItemDroppable(UnitItemInSlot(u, i), false)
set i = i + 1
endloop
set d.inInv = false
endmethod
static method create takes unit u returns data
local data d = data.allocate()
local item i
call StoreInteger(g, "struct", GetUnitId(u), d)
call TriggerRegisterUnitEvent(d.open, u, EVENT_UNIT_USE_ITEM)
call TriggerAddAction(d.open, function data.openBag)
call TriggerAddCondition(d.open, Condition(function Conditions1))
call TriggerRegisterUnitEvent(d.close, u, EVENT_UNIT_USE_ITEM)
call TriggerAddAction(d.close, function data.closeBag)
call TriggerAddCondition(d.close, Condition(function Conditions2))
set d.itm[0] = WEAPON
set d.itm[1] = ARMOR
set d.itm[2] = HELMET
set d.itm[3] = ACCESSORY
set d.itm[4] = OFFHAND
set i = CreateItem(OPEN_INV, 0, 0)
call UnitAddItem(u, i)
call UnitDropItemPoint(u, UnitItemInSlot(u, 5), GetUnitX(u), GetUnitY(u))
call UnitDropItemSlot(u, i, 5)
set i = null
return d
endmethod
endstruct
private struct bonus
integer str
integer agi
integer int
integer dmg
integer def
integer hp
integer mp
integer spd
integer type
endstruct
function UnitExtendEquipment takes unit u returns nothing
local data d = data.create(u)
endfunction
function EquipmentItem takes integer rawID, integer s,integer str, integer agi, integer int, integer dmg, integer def, integer hp, integer mp, integer spd returns nothing
local bonus b = bonus.create()
set b.str = str
set b.agi = agi
set b.int = int
set b.dmg = dmg
set b.def = def
set b.hp = hp
set b.mp = mp
set b.spd = spd
set b.type = s
call StoreInteger(g, "bonus", I2S(rawID), b)
endfunction
private function GetItemNameById takes integer id returns string
local item i = CreateItem(id, 0, 0)
local string s = GetItemName(i)
set i = null
return s
endfunction
private function GetOpenSlot takes data d returns integer
local integer i = 0
loop
exitwhen i == 6
if d.inv<i> == 0 then
return i
endif
set i = i + 1
endloop
return -1
endfunction
private function Equip takes nothing returns nothing
local unit u = GetTriggerUnit()
local integer i = GetItemTypeId(GetManipulatedItem())
local bonus b = GetStoredInteger(g, "bonus", I2S(i))
local data d = GetStoredInteger(g, "struct", GetUnitId(u))
if b == 0 or d == 0 then
return
endif
if d.inInv == false then
if d.itm[b.type] == thetype[b.type] then
set d.itm[b.type] = i
set Bonus_Armor<u> = Bonus_Armor<u> + b.def
set Bonus_Damage<u> = Bonus_Damage<u> + (b.dmg/5)
set Bonus_Life<u> = Bonus_Life<u> + (b.hp/100)
set Bonus_Mana<u> = Bonus_Mana<u> + (b.mp/100)
set Bonus_Str<u> = Bonus_Str<u> + (b.str)
set Bonus_Agi<u> = Bonus_Agi<u> + (b.agi)
set Bonus_Int<u> = Bonus_Int<u> + (b.int)
set Bonus_AttackSpeed<u> = Bonus_AttackSpeed<u> + (b.spd/5)
call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, "|cffffcc00Equipment:|r " + GetItemName(GetManipulatedItem()) + " has been equipped")
call RemoveItem(GetManipulatedItem())
else
call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, "|cffffcc00Equipment:|r You already have " + GetItemNameById(d.itm[b.type]) + " equipped")
endif
else
if d.hasRoom then
set i = GetOpenSlot(d)
if i != -1 then
set d.inv<i> = GetItemTypeId(GetManipulatedItem())
else
call CreateItem(GetItemTypeId(GetManipulatedItem()), GetUnitX(u), GetUnitY(u))
endif
else
call CreateItem(GetItemTypeId(GetManipulatedItem()), GetUnitX(u), GetUnitY(u))
endif
call DisplayTextToPlayer(GetOwningPlayer(u), 0, 0, "|cffffcc00Equipment:|r " + GetItemName(GetManipulatedItem()) + " has been unequipped")
call RemoveItem(GetManipulatedItem())
call UnitAddItemById(u, thetype[b.type])
set d.itm[b.type] = thetype[b.type]
set Bonus_Armor<u> = Bonus_Armor<u> - b.def
set Bonus_Damage<u> = Bonus_Damage<u> - (b.dmg/5)
set Bonus_Life<u> = Bonus_Life<u> - (b.hp/100)
set Bonus_Mana<u> = Bonus_Mana<u> - (b.mp/100)
set Bonus_Str<u> = Bonus_Str<u> - (b.str)
set Bonus_Agi<u> = Bonus_Agi<u> - (b.agi)
set Bonus_Int<u> = Bonus_Int<u> - (b.int)
set Bonus_AttackSpeed<u> = Bonus_AttackSpeed<u> - (b.spd/5)
endif
set u = null
endfunction
private function Init takes nothing returns nothing
local trigger t = CreateTrigger()
call FlushGameCache(InitGameCache("eqsys"))
set g = InitGameCache("eqsys")
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_USE_ITEM )
call TriggerAddAction(t, function Equip)
set thetype[0] = WEAPON
set thetype[1] = ARMOR
set thetype[2] = HELMET
set thetype[3] = ACCESSORY
set thetype[4] = OFFHAND
endfunction
endlibrary
</u></u></u></u></u></u></u></u></u></u></u></u></u></u></u></u></i></u></u></u></u></u></u></u></u></u></u></u></u></u></u></u></u></i></i></i></i></i>