//TESH.scrollpos=0
//TESH.alwaysfold=0
function GetHost takes nothing returns nothing
local gamecache g = InitGameCache("Map.w3v")
call StoreInteger ( g, "Map", "Host", GetPlayerId(GetLocalPlayer ())+1)
call TriggerSyncStart ()
call SyncStoredInteger ( g, "Map", "Host" )
call TriggerSyncReady ()
set udg_Host = Player( GetStoredInteger ( g, "Map", "Host" )-1)
call FlushGameCache( g )
set g = null
endfunction
Name | Type | is_array | initial_value |
a3_LivesKillsTime | integer | Yes | |
AAAInventory | gamecache | No | |
AAAInventoryGroup | group | No | |
BnsBit | abilcode | Yes | |
Bool_T_K_L | boolean | Yes | |
CamLock | real | No | 2400.00 |
Campaign | integer | No | |
Cap | unit | Yes | |
Capped | integer | Yes | |
casters | group | No | |
castervars | real | Yes | |
cColors | string | Yes | |
csarray1 | integer | Yes | |
csarray2 | integer | Yes | |
cscache | gamecache | No | |
csfreeindexes | location | Yes | |
currentabi | integer | No | |
currentcaster | unit | No | |
currenthurter | unit | No | |
Data_Cost | integer | No | |
Deaths | integer | Yes | |
delayhack | real | No | |
FT | texttag | Yes | |
Host | player | No | |
IntegerExperienceCap | integer | Yes | |
Item_Creation | itemcode | Yes | |
Item_Percent | real | No | |
Item_Roll | real | No | |
ItemCharges | integer | No | |
Kill_Reward | real | No | |
Kills | integer | Yes | |
MapVersion | string | No | |
MaxItems | integer | No | |
MBIndex | integer | Yes | |
mbTeamVar | integer | No | |
MHPot | integer | Yes | |
Militia | integer | Yes | |
MilitiaKilled | real | No | |
Modes | integer | No | |
Multi_Name | string | Yes | |
Multiboard | multiboard | No | |
MultiboardStatus | multiboard | No | |
nArena | integer | No | |
nArenaCount | integer | No | |
NumberOfCaps | integer | No | |
P_Count | integer | No | |
P_Deaths | integer | Yes | |
P_Kills | integer | Yes | |
P_Score | integer | Yes | |
PickedBool | boolean | Yes | |
PlayersDead | real | No | |
PnN | integer | Yes | |
Pnum | integer | No | |
Progress | real | Yes | |
rArena | rect | No | |
RealExperiencePercentage | real | No | |
rPnum | integer | No | |
sArena | string | No | |
sourcehack | location | No | |
SpawnPoints | location | Yes | |
SPoint | location | Yes | |
StartLoc | location | Yes | |
StatisticsBoard | integer | Yes | |
StringMultiboardStatusHP | string | No | |
StringMultiboardStatusMP | string | No | |
StringMultiboardStatusXP | StringExt | No | |
Team1 | force | No | |
Team2 | force | No | |
TeamKilles_R_G | integer | Yes | |
TeamSideRG | location | Yes | |
temp_CustomizedTime | integer | Yes | |
temp_MaxCustomizedArray | integer | No | |
temp_UnitTypes_ForTime | unitcode | Yes | |
TempGroup | group | No | |
TempPoint | location | No | |
TESTUNIT | unit | No | |
TimeSec | integer | No | |
UnitHero | unit | No | |
Visibility | fogmodifier | No | |
Waves | timer | No | |
Xcolor | real | Yes | |
Xint | integer | No | |
XPercent | real | No | |
zz_bIsThereHero | boolean | No | |
zz_DamageTextTime | real | No | |
zz_Experience | real | No | |
zz_ExperienceFloatingTextTime | real | No | |
zz_ExperiencePerLevel | real | No | |
zz_ExtraXPForKiller | real | No | |
zz_ExtraXPForOther | real | No | |
zz_FinalExperience | real | No | |
zz_FinalOtherExperience | real | No | |
zz_Hero | group | No | |
zz_HeroAllies | group | No | |
zz_HeroAlliesAmount | integer | No | |
zz_HeroKillerLoc | location | No | |
zz_MaxRangeOfExp | real | No | |
zz_OtherExperience | real | No | |
zz_SpellTextTime | real | No | |
zz_TreeRevivalInterval | real | No | |
zzConvertRealToInteger | integer | Yes | |
zzStr_ExperienceTag | string | No |
//TESH.scrollpos=0
//TESH.alwaysfold=0
Remember this you big dumb.
StatisticsBoard[1] = Upgrades
StatisticsBoard[2] = Minion Kills
StatisticsBoard[3] = Player Kills
StatisticsBoard[4] = Level Ups
StatisticsBoard[5] = Highest Soul Count
StatisticsBoard[6] = Deaths
function Trig_SoulPlus_Conditions takes nothing returns boolean
if ( not ( GetPlayerName(GetTriggerPlayer()) == "sube2" ) ) then
return false
endif
return true
endfunction
function Trig_SoulPlus_Actions takes nothing returns nothing
call AdjustPlayerStateBJ( 1000, Player(8), PLAYER_STATE_RESOURCE_GOLD )
endfunction
//===========================================================================
function InitTrig_SoulPlus takes nothing returns nothing
set gg_trg_SoulPlus = CreateTrigger( )
call TriggerRegisterPlayerChatEvent( gg_trg_SoulPlus, Player(8), "-1000", true )
call TriggerAddCondition( gg_trg_SoulPlus, Condition( function Trig_SoulPlus_Conditions ) )
call TriggerAddAction( gg_trg_SoulPlus, function Trig_SoulPlus_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function AnyUnitTakesDamage takes nothing returns nothing
call ConditionalTriggerExecute( gg_trg_DamageTextSystem )
endfunction
// part 1
function AddDamageTriggers takes nothing returns nothing
local trigger takedamage = CreateTrigger()
call TriggerRegisterUnitEvent(takedamage,GetTriggerUnit(),EVENT_UNIT_DAMAGED)
call AttachObject(takedamage,"action",TriggerAddAction(takedamage,function AnyUnitTakesDamage))
call AttachObject(GetTriggerUnit(),"TakeDamageTrigger",takedamage)
endfunction
// part 2
function RemoveDamageTriggers takes nothing returns nothing
local unit u = GetTriggerUnit()
local trigger me = GetAttachedTrigger(GetTriggerUnit(),"TakeDamageTrigger")
local string t = GetAttachmentTable(me)
local boolean revived = false
if not IsUnitType(u,UNIT_TYPE_HERO) then
loop
set revived = (GetWidgetLife(u)>0.405)
exitwhen revived or GetUnitTypeId(u)==0
call TriggerSleepAction(0)
endloop
endif
if not revived then
// delete action and trigger
call TriggerRemoveAction(me,GetTableTriggerAction(t,"action"))
call DestroyTable(t)
call DestroyTrigger(me)
endif
set me = null
set u = null
endfunction
// part 3
function InitTrig_AddDmg takes nothing returns nothing
local trigger entermap = CreateTrigger()
local group startingunits = CreateGroup()
local unit u
local trigger takedamage
local trigger upondeath = CreateTrigger()
call GroupEnumUnitsInRect(startingunits,bj_mapInitialPlayableArea,null)
loop
set u = FirstOfGroup(startingunits)
exitwhen u == null
set takedamage = CreateTrigger()
call TriggerRegisterUnitEvent(takedamage,u,EVENT_UNIT_DAMAGED)
call AttachObject(takedamage,"action",TriggerAddAction(takedamage,function AnyUnitTakesDamage))
call AttachObject(u,"TakeDamageTrigger",takedamage)
call GroupRemoveUnit(startingunits,u)
endloop
set takedamage = null
// unit enters the map/revives
call TriggerRegisterAnyUnitEventBJ(entermap ,EVENT_PLAYER_HERO_REVIVE_FINISH)
call TriggerRegisterEnterRectSimple(entermap, bj_mapInitialPlayableArea)
call TriggerAddAction(entermap,function AddDamageTriggers)
// unit dies
call TriggerRegisterAnyUnitEventBJ(upondeath,EVENT_PLAYER_UNIT_DEATH)
call TriggerAddAction(upondeath,function RemoveDamageTriggers)
endfunction
function Trig_SpellShowTextSystem_Actions takes nothing returns nothing
call CreateTextTagUnitBJ( ( GetAbilityName(GetSpellAbilityId()) + "" ), GetTriggerUnit(), 7.00, 8, 100, 00.00, 0.00, 40.00 )
call SetTextTagVelocityBJ( GetLastCreatedTextTag(), 80.00, 90 )
call SetTextTagPermanentBJ( GetLastCreatedTextTag(), false )
call SetTextTagLifespanBJ( GetLastCreatedTextTag(), udg_zz_SpellTextTime )
endfunction
//===========================================================================
function InitTrig_SpellShowTextSystem takes nothing returns nothing
set gg_trg_SpellShowTextSystem = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_SpellShowTextSystem, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddAction( gg_trg_SpellShowTextSystem, function Trig_SpellShowTextSystem_Actions )
endfunction
function Trig_Untitled_Trigger_005_Actions takes nothing returns nothing
set udg_TeamKilles_R_G[1] = ( udg_TeamKilles_R_G[1] + 1 )
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_005 takes nothing returns nothing
set gg_trg_Untitled_Trigger_005 = CreateTrigger( )
call TriggerAddAction( gg_trg_Untitled_Trigger_005, function Trig_Untitled_Trigger_005_Actions )
endfunction
function Trig_Untitled_Trigger_003_Actions takes nothing returns nothing
set udg_Data_Cost = 1
endfunction
//===========================================================================
function InitTrig_Untitled_Trigger_003 takes nothing returns nothing
set gg_trg_Untitled_Trigger_003 = CreateTrigger( )
call TriggerAddAction( gg_trg_Untitled_Trigger_003, function Trig_Untitled_Trigger_003_Actions )
endfunction
//TESH.scrollpos=225
//TESH.alwaysfold=0
Read Me
¯¯¯¯¯¯¯
AAAInventory System version 1.0
Table Of Contents:
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
1. About.
2. Implementation.
3. Usage
4. Final Notes
5. Contact Info
1. About
¯¯¯¯¯¯¯¯
What is this?
This is an inventory system I created quite some time ago for my map Azeroth's Arcane Arena.
I am releasing this, because several guys have requested it.
This system is inspired by Vexorian's InvX and weaaddar' Drag & Drop system.
It has the features I needed for my map, nothing more, nothing less.
Therefore I suggest you to check out one of the two systems mentioned above instead, if you want
a more advanced, and better inventory system.
This system is a lot simpler than those two systems, and that might be good in some situations.
It is not the best system out there, so unless this is what you want, check one of the other two
systems I mentioned. They are different, but generally a lot better.
But well, if this is what you need, then it is good, and I think this is a bit easier to use than the
other two systems, since it is less advanced.
2. Implementation
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
NOTE: Always make a back up of your map before implementing anything.
This system requires Vexorian's Caster System - Find it with a large read me at
http://www.wc3campaigns.net/vexorian
It mostly just uses the CSCache system, but it also uses the PreloadAbility function - Therefore you
will need the whole Caster System. If you know JASS, I am sure that you can just use the CSCache
system and create a PreloadAbility function yourself - Just created a unit, add the ability and
remove the unit from the game.
The Caster System is not the only thing this system requires.
It also requires BonusMod, a system made by weaaddar, that uses abilities to modify the max life,
max mana, damage and armor of units.
When I coded this system, I used the InvX version of BonusMod - A version optimized to use the Caster
System, modified for InvX. Vexorian made these modifications to weaaddar's system, for his inventory
system InvX.
That version of BonusMod is used in this map (with permission), get it with a read me
and implementation instructions from the InvX map at:
http://www.wc3campaigns.net/vexorian/invx/
While you are at InvX, reconsider what system to use, both InvX and weaaddar's Drag and Drop systems
are better.
After implementing BonusMod, it is time to copy some stuff from this map to your map.
First copy the "Inventory Spell" ability - It is just a dummy ability used by the items, so they are
clickable.
Then copy the 9 custom items to your map (Accessory, Armor, Backpack, Cancel, Equipment Menu, Head,
Shield, Switch Page & Weapon) and make sure that the ability on the Backpack, Cancel, Equipment Menu
& Switch Page items is the Inventory Spell ability.
Now copy the variables used by the inventory system to your map (look at the "Required Variables"
trigger for instructions about doing that).
When that is done, copy the "AAAInventory" trigger to your map - Yeah, you guessed right, that is the
system itself.
Now it is time to change the rawcodes of the items in the top of the "AAAInventory" trigger.
A rawcode is a unique id that every object has. To find it, go to the object editor and press CTRL+D.
Now the names of all objects should change - The first four letters in the name is the rawcode.
Rawcodes are case sensitive, and must be put between single quotes (Example: 'I00A').
Replace the rawcodes in the trigger with the ones from your map.
In my map, the amount of items that can be in a backpack is 12 - You can change this, if you want.
Just change the integer returned by the BackPack size constant function in the configuration section.
The integer returned by that function MUST be a multiple of 4, as that is the amount of items that
can be on a page. If it is not, then the system won't work correctly.
Now take a look at the InventorySafeX/Y configuration functions.
When a item is not in the unit's actual inventory, but the unit owns the item (the item is in another
menu in the inventory system than the currently open one), the item is dropped on the grund and
hidden. It is, however, possible for units to pick the items up up even though they are hidden, so
if you have some trigger that, for example, orders computer units to pick up items in range, they
will be able to pick up the hidden items, and that will cause problems.
Therefore specify some coordinates of a place in your map where units are not able to go and pick the
items up, and the items will be moved to that place when dropped. To know what the coordinates of a
point is, just hover your mouse over the point in the World Editor, and look in the down-left corner
to see the coordinates.
3. Usage
¯¯¯¯¯¯¯¯
The trigger that contains the system will automatically initialize the system itself.
You will, however, need to initialize BonusMod manually, else the system will not work.
To do that, you will need a custom script (JASS) call like this:
call InitBonusMod()
It must be called at map initilization, before any unit uses the system.
Now it is time to set up the items.
Find the "SetupItemBonuses" function in the "AAAInventory" trigger - That function is automatically
executed when the system initializes itself, so all the item setup lines must be put in there.
Use the following function to set up an item type's bonuses:
___________________________________________________________________________________________________________________________________________________________________________________________________________________________
function SetItemBonuses takes integer itemId, integer dmg, integer arm, integer hp, integer mp, integer str, integer agi, integer int, integer abil, string equipSlot, string equipFunc, string unequipFunc returns nothing
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
integer itemId - This is the rawcode of the item type.
integer dmg - The damage bonus added by the item type.
integer arm - The armor bonus added by the item type.
integer hp - The HP bonus added by the item type.
integer mp - The MP bonus added by the item type.
integer str - The strength bonus added by the item type.
integer agi - The agility bonus added by the item type.
integer int - The intelligence bonus added by the item type.
integer abil - The rawcode of an ability added to the hero when he equips the item*. If the ability is added by multiple items equipped by the hero, it will first be removed when all those items are drop.
string equipSlot - The slot that the item is equipped to**.
string equipFunc - A function executed using the ExecuteFunc native when the item is equipped***. Use an empty string if you don't want any function to be executed ("").
string unequipFunc - A function executed using the ExecuteFunc native when the item is unequipped***. Use an empty string if you don't want any function to be executed ("").
* If you want to add a passive ability that takes up a slot in the command card, but don't want it to
show up there, create a new ability based on the Spell Book ability. Change it's orderstring to
something random (just so it won't collide with other spellbooks).
Add your ability to the spell book, and at map initialization use the following code:
call SetPlayerAbilityAvailable(player, abilCode, false)
Where player is the player (it must be done for all 12 players) and abilCode is the rawcode of the
ability. Then just use the rawcode of the spellbook ability, and the ability will be added, but
hidden in the command card.
** Must be either "Head", "Armor", "Weapon", "Shield" or "Accessory" (case sensitive.
You can change the names of the items, but in the code you will have to use the original names,
else it will not work.
You can use the table in the Trigger Comment field of the "AAAInventory" trigger to see where each
slot is placed.
*** Use GetOrderedUnit() to refer to the hero equipping/unequipping the item.
Make sure that you removed all original bonus abilities from the item type in the object editor, else
things won't work correctly.
An example of how to set up an item:
call SetItemBonuses('ratf', 15, 0, 0, 0, 0, 0, 0, 0, "Weapon", "", "") // Claws of Attack +15
Sets up the Claws of Attack +15 to be an item that can be equipped to the Weapon slot. The only bonus added by that item is +15 damage.
There are a couple of examples in the "SetupItemBonuses" function in the "AAAInventory" trigger, you
can look at them if you are not sure about how to do this yet. Remember to remove them, unless you
want items with exactly the same bonuses in your map.
Please notice that items with charges must be in the "Charged" item category in the Object Editor,
else they won't work correctly with this system.
Now it is time to give a unit the extended inventory. You can do this with as many units as you want.
_____________________________________________________________________________________________________
function CreateExtendedInventory takes unit u returns nothing
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
The above function is all that is required to give a unit extended inventory.
Call it like this:
call CreateExtendedInventory(unit)
Where 'unit' of course is the unit you want to create the extended inventory for.
Please notice that this is supposed to be called as soon as the unit is created, and it will REMOVE
all items already in the unit's inventory.
If you want to remove a Hero from the game, use the following function to get rid of the extended
inventory:
_____________________________________________________________________________________________________
function DestroyExtendedInventory takes unit u returns nothing
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
It is not required, but it is a good idea, as it will remove the data stored in the gamecache, and
the items used by the inventory system. It will REMOVE all items the hero owns from the game, no
matter if they are in the backpack, the equipment menu, or the quick menu.
Call it like this:
call DestroyExtendedInventory(unit)
Where 'unit' still is the unit you want to remove the extended inventory from.
This system uses Set/GetItemUserData, so if you use that yourself in your triggers, you might screw
up the system. Therefore do NOT use SetUnitUserData (Set Custom Value Of Item in GUI), or the system
might not work correctly.
Now you should know how to use the system.
4. Final Notes
¯¯¯¯¯¯¯¯¯¯¯¯¯¯
* There might be some of the functions that are created for internal use and can be found in the
"AAAInventory" system trigger that might be useful for you, GetItemSlot() for example.
You will have to find out how to uset them yourself though.
* This is not the best inventory system out there, so if you want something more advanced, check out
Vexorian's and weaaddar's systems.
* This system might contain bugs, but I all the bugs I've found when using it in my map have been
fixed, so hopefully there are no bugs left.
* I use some custom icons for this system, they are just modified Blizzard icons, but they make the
system make more sense. You can use them if you want, find them in the import manager.
* This is not _exactly_ the same system as in my map, it has been updated a bit since the latest
release of the map, and some bugs have been fixed.
* Remember to GIVE CREDIT if you use this system.
5. Contact Info
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
Contact me by:
E-Mail: [email protected]
Or send me (Blade.dk) a pm at http://www.wc3campaigns.net or http://www.wc3jass.com.
Sites:
http://www.wc3campaigns.net - The number one Warcraft 3 Modding site, with everything you might want
from resources, to tutorials, to forums, to real-time chat where you
can get help with your modding problems.
http://aaa.wc3jass.com - My map, Azeroth's Arcane Arena, that this system was originally created
for. Check it out!
http://www.wc3jass.com - The Jass Vault, the largest Jass site on the internet. Contains forums,
a grand library of Jass functions and more.
Resources:
http://www.wc3campaigns.net/resources.php?f=613&u=66470 - More resources made by me, Blade.dk.
http://www.wc3campaigns.net/forumdisplay.php?f=658 - Vexorian's Caster System.
http://www.wc3campaigns.net/vexorian/invx/ - Vexorian's InvX inventory system.
http://www.wc3campaigns.net/showthread.php?t=84088 - weaaddar's Drag and Drop Systems.
Have fun, and thanks for downloading this system.
- Blade.dk
//TESH.scrollpos=133
//TESH.alwaysfold=0
//***************************************************************************
//* *
//* Azeroth' Arcane Arena Inventory System *
//* *
//* By Blade.dk - [email protected] *
//* *
//* http://aaa.wc3jass.com - http://www.wc3campaigns.net *
//* *
//***************************************************************************
//===========================================================================
// Configuration functions
constant function Cancel_ItemID takes nothing returns integer
return 'I003' // Rawcode of the Cancel item.
endfunction
constant function BackpackMenu_ItemID takes nothing returns integer
return 'I002' // Rawcode of the Backpack item.
endfunction
constant function SwitchPage_ItemID takes nothing returns integer
return 'I007' // Rawcode of the Switch Page item.
endfunction
constant function EquipmentMenu_ItemID takes nothing returns integer
return 'I004' // Rawcode of the Equipment Menu item.
endfunction
constant function HeadFiller_ItemID takes nothing returns integer
return 'I005' // Rawcode of the Head item.
endfunction
constant function ArmorFiller_ItemID takes nothing returns integer
return 'I001' // Rawcode of the Armor item.
endfunction
constant function WeaponFiller_ItemID takes nothing returns integer
return 'I008' // Rawcode of the Weapon item.
endfunction
constant function ShieldFiller_ItemID takes nothing returns integer
return 'I006' // Rawcode of the Shield item.
endfunction
constant function AccessoryFiller_ItemID takes nothing returns integer
return 'I000' // Rawcode of the Accessory item.
endfunction
constant function BackpackSize takes nothing returns integer
return 24
endfunction
constant function InventorySafeX takes nothing returns real
return -2040.00 // The X coordinate of a safe place to place items, so computer units won't be able to pick the up.
endfunction
constant function InventorySafeY takes nothing returns real
return 2040.00 // The Y coordinate of a safe place to place items, so computer units won't be able to pick the up.
endfunction
//===========================================================================
// Private functions - Do not modify them unless you know what you are doing!
function InventoryCache takes nothing returns gamecache
if udg_AAAInventory == null then
call FlushGameCache(InitGameCache("AAAInv.w3v"))
set udg_AAAInventory = InitGameCache("AAAInv.w3v")
endif
return udg_AAAInventory
endfunction
function SetItemBonuses takes integer itemId, integer dmg, integer arm, integer hp, integer mp, integer str, integer agi, integer int, integer abil, string equipSlot, string equipFunc, string unequipFunc returns nothing
local gamecache g = InventoryCache()
local string s = I2S(itemId)
if equipSlot == "Head" or equipSlot == "Armor" or equipSlot == "Weapon" or equipSlot == "Shield" or equipSlot == "Accessory" then
call StoreString(g, s, "equipmentslot", equipSlot)
if dmg > 0 then
call StoreInteger(g, s, "damage", dmg)
endif
if arm > 0 then
call StoreInteger(g, s, "armor", arm)
endif
if hp > 0 then
call StoreInteger(g, s, "hitpoints", hp)
endif
if mp > 0 then
call StoreInteger(g, s, "manapoints", mp)
endif
if str > 0 then
call StoreInteger(g, s, "strength", str)
endif
if agi > 0 then
call StoreInteger(g, s, "agility", agi)
endif
if int > 0 then
call StoreInteger(g, s, "intelligence", int)
endif
if abil > 0 then
call StoreInteger(g, s, "ability", PreloadAbility(abil))
endif
if equipFunc != "" and equipFunc != null then
call StoreString(g, s, "OnEquip", equipFunc)
endif
if unequipFunc != "" and unequipFunc != null then
call StoreString(g, s, "OnDrop", unequipFunc)
endif
endif
set g = null
endfunction
//===========================================================================
// Put the SetItemBonuses calls that sets up your items in this function, that is executed by the
// system at map init.
//dmg, arm, hp, mp, str, agi, int, abi
function SetupItemBonuses takes nothing returns nothing
call SetItemBonuses('I009', 2, 0, 8, 5, 0, 1, 0, 0, "Weapon", "", "")
// Set up the Claws of Attack +15 to be a Weapon that adds 15 bonus damage.
call SetItemBonuses('I00A', 0, 1, 15, 8, 1, 0, 0, 0, "Armor", "", "")
// Set up the Mindstaff item to be a Weapon that adds 200 mana and the 'A000' ability (See the "Extra" trigger for more info).
call SetItemBonuses('I00B', 0, 1, 20, 0, 0, 0, 1, 0, "Shield", "", "")
// Set up the Bladebane Armor item to be an Armor that adds 7 armor and the 'A001' ability (See the "Extra" trigger for more info).
call SetItemBonuses('I00D', 1, 0, 10, 20, 0, 0, 3, 0, "Accessory", "", "")
// Set up the Mantle of Intelligence item to be an Armor that adds 3 intelligence.
call SetItemBonuses('I00E', 10, 0, 50, 50, 2, 2, 1, 0, "Weapon", "", "")
// Set up the Bloodfeather's Heart item to be an Accessory that adds 10 agility.
call SetItemBonuses('I00C', 1, 0, 16, 12, 0, 1, 0, 0, "Head", "", "")
call SetItemBonuses('I00H', 0, 4, 18, 20, 0, 0, 2, 0, "Weapon", "", "")
call SetItemBonuses('I00F', 1, 0, 18, 30, 0, 0, 1, 0, "Head", "", "")
call SetItemBonuses('I00G', 1, 0, 16, 25, 0, 0, 2, 0, "Armor", "", "")
call SetItemBonuses('I00I', 20, 0, 80, 12, 4, 1, 2, 0, "Weapon", "", "")
call SetItemBonuses('I00J', 0, 0, 0, 0, 0, 0, 0, 'A01T', "Accessory", "", "")
// Set up the Lion's Ring item to be an Accessory that adds 1 agility.
// call SetItemBonuses('ckng', 0, 0, 0, 0, 5, 5, 5, 0, "Head", "", "")
// Set up the Crown of Kings +5 item to be a Head equippable item that adds 5 to all hero stats.
call SetItemBonuses('rwiz', 0, 0, 0, 0, 0, 0, 0, 'AIrm', "Head", "", "")
// Set up the Sobi Mask item to be a Head equippable item that adds the 'AIrm' ability.
call SetItemBonuses('shen', 0, 2, 50, 0, 0, 0, 0, 0, "Shield", "", "")
// Set up the Enchanted Shield item to be a Shield that adds 2 armor and 50 HP.
call SetItemBonuses('shhn', 0, 8, 0, 0, 0, 0, 0, 'A002', "Shield", "", "")
// Set up the Shield of Honor item to be a Shield that adds 8 armor and the 'A002' ability (See the "Extra" trigger for more info).
call SetItemBonuses('wtlg', 0, 0, 0, 0, 0, 0, 0, 0, "Accessory", "WirtsLegEquip", "WirtsLegUnequip")
// Set up the Wirt's Leg item to be an Accessory that adds no bonuses, but executes the "WirtsLegEquip" function when equipped, and the "WirtsLegUnequip" function when unequipped (see the "Extra" trigger for more info).
endfunction
//===========================================================================
// Private functions - Do not modify them unless you know what you are doing!
function BackpackHasEmptySlots takes string s returns boolean
local integer a = 1
loop
exitwhen a > BackpackSize()
if GetTableItem(s, "BackpackItem"+I2S(a)) == null then
return true
endif
set a = a+1
endloop
return false
endfunction
function QuickMenuHasEmptySlots takes string s returns boolean
return GetTableItem(s, "QuickMenuItem1") == null or GetTableItem(s, "QuickMenuItem2") == null or GetTableItem(s, "QuickMenuItem3") == null or GetTableItem(s, "QuickMenuItem4") == null
endfunction
function IsItemFiller takes item i returns boolean
local integer id = GetItemTypeId(i)
return id == HeadFiller_ItemID() or id == ArmorFiller_ItemID() or id == WeaponFiller_ItemID() or id == ShieldFiller_ItemID() or id == AccessoryFiller_ItemID()
endfunction
function BackpackContainsItem takes string s, item i returns boolean
local integer a = 1
loop
exitwhen a > BackpackSize()
if GetTableItem(s, "BackpackItem"+I2S(a)) == i then
return true
endif
set a = a+1
endloop
return false
endfunction
function QuickMenuContainsItem takes string s, item i returns boolean
return GetTableItem(s, "QuickMenuItem1") == i or GetTableItem(s, "QuickMenuItem2") == i or GetTableItem(s, "QuickMenuItem3") == i or GetTableItem(s, "QuickMenuItem4") == i
endfunction
function IsEquipmentSlotValid takes string es returns boolean
return es == "Head" or es == "Armor" or es == "Weapon" or es == "Shield" or es == "Accessory"
endfunction
function GetItemEquipmentSlot takes item i returns string
return GetStoredString(InventoryCache(), I2S(GetItemTypeId(i)), "equipmentslot")
endfunction
function GetItemSlot takes unit u, item i returns integer
local integer a = 0
loop
exitwhen a > 5
if UnitItemInSlot(u, a) == i then
return a
endif
set a = a + 1
endloop
return -1
endfunction
function SlotToFillerName takes integer s returns string
if s == 0 then
return "Head"
elseif s == 1 then
return "Armor"
elseif s == 2 then
return "Weapon"
elseif s == 3 then
return "Shield"
elseif s == 4 then
return "Accessory"
else
return "Cancel"
endif
endfunction
function FillerNameToSlot takes string es returns integer
if es == "Head" then
return 0
elseif es == "Armor" then
return 1
elseif es == "Weapon" then
return 2
elseif es == "Shield" then
return 3
elseif es == "Accessory" then
return 4
endif
return 5
endfunction
function InventoryRemoveItem takes unit u, item i returns nothing
call SetItemUserData(i, 1)
call UnitRemoveItem(u, i)
call SetItemPosition(i, InventorySafeX(), InventorySafeY())
call SetItemVisible(i, false)
endfunction
function InventoryAddItem takes unit u, item i returns nothing
call SetItemUserData(i, 0)
call SetItemVisible(i, true)
call UnitAddItem(u, i)
endfunction
function CreateExtendedInventory takes unit u returns nothing
local item i
local string s = NewTable()
local integer a = 0
loop
exitwhen a > 5
call RemoveItem(UnitItemInSlot(u, a))
set a = a + 1
endloop
call GroupAddUnit(udg_AAAInventoryGroup, u)
call AttachString(u, "InventoryTable", s)
call SetTableInt(s, "CurrentMenu", 0)
call SetTableInt(s, "CurrentBackpackPage", 1)
call UnitAddItemToSlotById(u, EquipmentMenu_ItemID(), 4)
set i = UnitItemInSlot(u, 4)
call SetTableObject(s, "EquipmentMenu", i)
call UnitAddItemToSlotById(u, BackpackMenu_ItemID(), 5)
set i = UnitItemInSlot(u, 5)
call SetTableObject(s, "BackpackMenu", i)
set i = CreateItem(Cancel_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "Cancel", i)
set i = CreateItem(SwitchPage_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "SwitchPage", i)
call SetItemCharges(i, 1)
set i = CreateItem(HeadFiller_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "HeadFiller", i)
call SetTableObject(s, "HeadItem", i)
set i = CreateItem(ArmorFiller_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "ArmorFiller", i)
call SetTableObject(s, "ArmorItem", i)
set i = CreateItem(WeaponFiller_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "WeaponFiller", i)
call SetTableObject(s, "WeaponItem", i)
set i = CreateItem(ShieldFiller_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "ShieldFiller", i)
call SetTableObject(s, "ShieldItem", i)
set i = CreateItem(AccessoryFiller_ItemID(), 0, 0)
call SetItemVisible(i, false)
call SetTableObject(s, "AccessoryFiller", i)
call SetTableObject(s, "AccessoryItem", i)
set i = null
endfunction
function DestroyExtendedInventory takes unit u returns nothing
local string s = GetAttachedString(u, "InventoryTable")
local item i
local item t
local integer a = 1
if s == "" then
set i = null
set t = null
return
endif
loop
exitwhen a > BackpackSize()
call RemoveItem(GetTableItem(s, "BackpackItem"+I2S(a)))
set a = a + 1
endloop
set a = 1
loop
exitwhen a > 4
call RemoveItem(GetTableItem(s, "QuickPage"+I2S(a)))
set a = a + 1
endloop
call RemoveItem(GetTableItem(s, "EquipmentMenu"))
call RemoveItem(GetTableItem(s, "BackpackMenu"))
call RemoveItem(GetTableItem(s, "Cancel"))
call RemoveItem(GetTableItem(s, "SwitchPage"))
set a = 0
loop
exitwhen a > 4
set i = GetTableItem(s, SlotToFillerName(a)+"Item")
set t = GetTableItem(s, SlotToFillerName(a)+"Filler")
if i != t then
call RemoveItem(i)
endif
call RemoveItem(t)
set a = a + 1
endloop
call DestroyTable(s)
call GroupRemoveUnit(udg_AAAInventoryGroup, u)
call AttachString(u, "InventoryTable", "")
set i = null
set t = null
endfunction
function InventoryError takes unit u, string e returns nothing
call CS_Error(GetOwningPlayer(u), e)
call PauseUnit(u, true)
call IssueImmediateOrder(u, "stop")
call PauseUnit(u, false)
endfunction
function CompressBackpack takes string s returns nothing
local integer a = 1
local item array t
local integer b = 1
local integer m = 0
local integer e = 1
local string l
loop
exitwhen a > BackpackSize()
set l = "BackpackItem"+I2S(a)
set t[a] = GetTableItem(s, l)
call SetTableObject(s, l, null)
set a = a + 1
endloop
set a = 1
loop
exitwhen a > BackpackSize()
set b = e
loop
exitwhen b > BackpackSize()
if t[b] != null then
call SetTableObject(s, "BackpackItem"+I2S(a), t[b])
set e = b+1
set m = m + 1
set b = BackpackSize()+1
endif
set b = b + 1
endloop
set a = a + 1
endloop
set a = 1
loop
exitwhen a > BackpackSize()
set t[a] = null
set a = a + 1
endloop
call SetTableInt(s, "BackpackItemsCount", m)
endfunction
function AddItemToBackpack takes unit u, string s, item i returns nothing
local integer a
call CompressBackpack(s)
set a = GetTableInt(s, "BackpackItemsCount")+1
call SetTableObject(s, "BackpackItem"+I2S(a), i)
call InventoryRemoveItem(u, i)
call SetItemCharges(GetTableItem(s, "BackpackMenu"), a)
call SetTableInt(s, "BackpackItemsCount", a)
endfunction
function AddItemToQuickMenu takes unit u, string s, item i, boolean f returns nothing
local integer a = 1
local string c
local item t
local string m
loop
exitwhen a > 4
set c = "QuickMenuItem"+I2S(a)
if GetTableItem(s, c) == null then
call SetTableObject(s, c, i)
call InventoryRemoveItem(u, i)
set a = 4
endif
set a = a + 1
endloop
if f then
call CompressBackpack(s)
endif
set t = null
endfunction
function InventorySwapMenu takes unit c, string s, integer o, integer m, integer op, integer np returns nothing
local integer a = 1
local integer b = 0
local item i
if o == 0 then
loop
exitwhen a > 6
set i = UnitItemInSlot(c, a-1)
if a < 5 then
call SetTableObject(s, "QuickMenuItem"+I2S(a), i)
endif
call InventoryRemoveItem(c, i)
set a = a + 1
endloop
elseif o == 1 then
set a = 0
loop
exitwhen a > 4
set i = UnitItemInSlot(c, a)
call SetTableObject(s, SlotToFillerName(a)+"Item", i)
call InventoryRemoveItem(c, i)
set a = a + 1
endloop
set i = UnitItemInSlot(c, 5)
call SetTableObject(s, "Cancel", i)
call InventoryRemoveItem(c, i)
elseif o == 2 then
loop
exitwhen a > 6
set i = UnitItemInSlot(c, a-1)
if a < 5 then
call SetTableObject(s, "BackpackItem"+I2S((4*(op-1))+a), i)
endif
call InventoryRemoveItem(c, i)
set a = a + 1
endloop
endif
set a = 1
call SetTableInt(s, "CurrentMenu", m)
if m == 0 then
loop
exitwhen a > 4
set i = GetTableItem(s, "QuickMenuItem"+I2S(a))
call InventoryAddItem(c, i)
call SetItemPawnable(i, true)
set a = a + 1
endloop
set i = GetTableItem(s, "EquipmentMenu")
call InventoryAddItem(c, i)
call UnitDropItemSlot(c, i, 4)
set i = GetTableItem(s, "BackpackMenu")
call InventoryAddItem(c, i)
call UnitDropItemSlot(c, i, 5)
call SetItemCharges(i, GetTableInt(s, "BackpackItemsCount"))
call SetTableInt(s, "CurrentBackpackPage", 1)
elseif m == 1 then
set a = 0
loop
exitwhen a > 4
set i = GetTableItem(s, SlotToFillerName(a)+"Item")
call InventoryAddItem(c, i)
call SetItemPawnable(i, false)
set a = a + 1
endloop
set i = GetTableItem(s, "Cancel")
call InventoryAddItem(c, i)
elseif m == 2 then
call CompressBackpack(s)
loop
exitwhen b >= 4 or a > BackpackSize()
set i = GetTableItem(s, "BackpackItem"+I2S((4*(np-1))+a))
if i != null then
set b = b + 1
call InventoryAddItem(c, i)
call SetItemPawnable(i, false)
endif
set a = a + 1
endloop
call SetTableInt(s, "CurrentBackpackPage", np)
set i = GetTableItem(s, "SwitchPage")
call InventoryAddItem(c, i)
call UnitDropItemSlot(c, i, 4)
call SetItemCharges(i, np)
set i = GetTableItem(s, "Cancel")
call InventoryAddItem(c, i)
call UnitDropItemSlot(c, i, 5)
endif
if GetLocalPlayer() == GetOwningPlayer(c) then
call ClearTextMessages()
endif
set i = null
endfunction
function EquipItem takes unit c, string s, item i, string es returns nothing
local item e = GetTableItem(s, es+"Item")
local item f = GetTableItem(s, es+"Filler")
local string x
local gamecache g = InventoryCache()
local string m = I2S(GetItemTypeId(e))
local integer v
local string a
local integer l
call InventoryRemoveItem(c, i)
call SetTableObject(s, es+"Item", i)
if e != f then
set x = GetStoredString(g, m, "OnDrop")
if x != "" and x != null then
call ExecuteFunc(x)
endif
set v = GetStoredInteger(g, m, "damage")
if v > 0 then
call UnitAddBonus(c, 0, -v)
endif
set v = GetStoredInteger(g, m, "armor")
if v > 0 then
call UnitAddBonus(c, 1, -v)
endif
set v = GetStoredInteger(g, m, "hitpoints")
if v > 0 then
call UnitAddBonus(c, 2, -v)
endif
set v = GetStoredInteger(g, m, "manapoints")
if v > 0 then
call UnitAddBonus(c, 3, -v)
endif
set v = GetStoredInteger(g, m, "strength")
if v > 0 then
call SetHeroStr(c, GetHeroStr(c, false)-v, true)
endif
set v = GetStoredInteger(g, m, "agility")
if v > 0 then
call SetHeroAgi(c, GetHeroAgi(c, false)-v, true)
endif
set v = GetStoredInteger(g, m, "intelligence")
if v > 0 then
call SetHeroInt(c, GetHeroInt(c, false)-v, true)
endif
set v = GetStoredInteger(g, m, "ability")
if v > 0 then
set a = "Ability"+I2S(v)
set l = GetTableInt(s, a)-1
call SetTableInt(s, a, l)
if l < 1 then
call UnitRemoveAbility(c, v)
endif
endif
call InventoryAddItem(c, e)
endif
set m = I2S(GetItemTypeId(i))
set x = GetStoredString(g, m, "OnEquip")
if x != "" and x != null then
call ExecuteFunc(x)
endif
set v = GetStoredInteger(g, m, "damage")
if v > 0 then
call UnitAddBonus(c, 0, v)
endif
set v = GetStoredInteger(g, m, "armor")
if v > 0 then
call UnitAddBonus(c, 1, v)
endif
set v = GetStoredInteger(g, m, "hitpoints")
if v > 0 then
call UnitAddBonus(c, 2, v)
endif
set v = GetStoredInteger(g, m, "manapoints")
if v > 0 then
call UnitAddBonus(c, 3, v)
endif
set v = GetStoredInteger(g, m, "strength")
if v > 0 then
call SetHeroStr(c, GetHeroStr(c, false)+v, true)
endif
set v = GetStoredInteger(g, m, "agility")
if v > 0 then
call SetHeroAgi(c, GetHeroAgi(c, false)+v, true)
endif
set v = GetStoredInteger(g, m, "intelligence")
if v > 0 then
call SetHeroInt(c, GetHeroInt(c, false)+v, true)
endif
set v = GetStoredInteger(g, m, "ability")
if v > 0 then
set a = "Ability"+I2S(v)
set l = GetTableInt(s, a)+1
call SetTableInt(s, a, l)
call UnitAddAbility(c, v)
endif
call InventorySwapMenu(c, s, 0, 0, 0, 0)
set e = null
set f = null
set g = null
endfunction
function UnequipItem takes unit c, string s, item i, string es returns nothing
local item f = GetTableItem(s, es+"Filler")
local string x
local gamecache g = InventoryCache()
local string m = I2S(GetItemTypeId(i))
local integer v
local string a
local integer l
call AddItemToQuickMenu(c, s, i, false)
call SetTableObject(s, es+"Item", f)
call InventoryAddItem(c, f)
call UnitDropItemSlot(c, f, FillerNameToSlot(es))
set x = GetStoredString(g, m, "OnDrop")
if x != "" and x != null then
call ExecuteFunc(x)
endif
set v = GetStoredInteger(g, m, "damage")
if v > 0 then
call UnitAddBonus(c, 0, -v)
endif
set v = GetStoredInteger(g, m, "armor")
if v > 0 then
call UnitAddBonus(c, 1, -v)
endif
set v = GetStoredInteger(g, m, "hitpoints")
if v > 0 then
call UnitAddBonus(c, 2, -v)
endif
set v = GetStoredInteger(g, m, "manapoints")
if v > 0 then
call UnitAddBonus(c, 3, -v)
endif
set v = GetStoredInteger(g, m, "strength")
if v > 0 then
call SetHeroStr(c, GetHeroStr(c, false)-v, true)
endif
set v = GetStoredInteger(g, m, "agility")
if v > 0 then
call SetHeroAgi(c, GetHeroAgi(c, false)-v, true)
endif
set v = GetStoredInteger(g, m, "intelligence")
if v > 0 then
call SetHeroInt(c, GetHeroInt(c, false)-v, true)
endif
set v = GetStoredInteger(g, m, "ability")
if v > 0 then
set a = "Ability"+I2S(v)
set l = GetTableInt(s, a)-1
call SetTableInt(s, a, l)
if l < 1 then
call UnitRemoveAbility(c, v)
endif
endif
set f = null
set g = null
endfunction
function InventoryDragItemConditions takes nothing returns boolean
local integer i = GetIssuedOrderId()
return i > 852001 and i < 852008 and IsUnitInGroup(GetOrderedUnit(), udg_AAAInventoryGroup) and GetOrderTargetItem() != UnitItemInSlot(GetOrderedUnit(), i-852002)
endfunction
function InventoryDragItemActions takes nothing returns nothing
local unit c = GetOrderedUnit()
local string s = GetAttachedString(c, "InventoryTable")
local item d = GetOrderTargetItem()
local integer ts = GetIssuedOrderId()-852002
local item t = UnitItemInSlot(c, ts)
local integer m = GetTableInt(s, "CurrentMenu")
local integer di = GetItemTypeId(d)
local integer ti = GetItemTypeId(t)
local integer i = GetItemSlot(c, d)
local item e = GetTableItem(s, "EquipmentMenu")
local item b = GetTableItem(s, "BackpackMenu")
local item ca = GetTableItem(s, "Cancel")
local item sw = GetTableItem(s, "SwitchPage")
local integer p = GetTableInt(s, "CurrentBackpackPage")
local string es = GetItemEquipmentSlot(d)
if m == 0 then
if t == GetTableItem(s, "BackpackMenu") and d != e then
if BackpackHasEmptySlots(s) then
call AddItemToBackpack(c, s, d)
elseif d != t and t == b then
call InventoryError(c, "Backpack is full.")
endif
else
if d == e and ts != 4 then
call InventoryError(c, "Unable to drop this item.")
elseif d == b and ts != 5 then
call InventoryError(c, "Unable to drop this item.")
elseif t == e and d != b then
if IsEquipmentSlotValid(es) then
call EquipItem(c, s, d, es)
else
call InventoryError(c, "Item is not equipable.")
endif
elseif ts == 5 and d != b then
call InventoryError(c, "Can not add this item to your backpack.")
endif
endif
elseif m == 1 then
if t == ca then
if QuickMenuHasEmptySlots(s) then
call UnequipItem(c, s, d, es)
else
call InventoryError(c, "Quick page is full.")
endif
else
call InventoryError(c, "Unable to drop this item.")
endif
elseif m == 2 then
if t == ca and d != sw then
if QuickMenuHasEmptySlots(s) then
call AddItemToQuickMenu(c, s, d, true)
call InventorySwapMenu(c, s, 2, 2, p, p)
else
call InventoryError(c, "Quick page is full.")
endif
elseif t == sw then
call InventoryError(c, "Unable to drop this item.")
elseif t == ca and d != sw then
call InventoryError(c, "Unable to drop this item.")
elseif d == ca and ts != 5 then
call InventoryError(c, "Unable to drop this item.")
elseif d == sw and ts != 4 then
call InventoryError(c, "Unable to drop this item.")
endif
endif
set c = null
set d = null
set t = null
set e = null
set b = null
set ca = null
set sw = null
endfunction
function InventoryUnitUsesItemConditions takes nothing returns boolean
local integer i = GetItemTypeId(GetManipulatedItem())
return IsUnitInGroup(GetManipulatingUnit(), udg_AAAInventoryGroup) and (i == Cancel_ItemID() or i == BackpackMenu_ItemID() or i == SwitchPage_ItemID() or i == EquipmentMenu_ItemID())
endfunction
function InventoryUnitUsesItemActions takes nothing returns nothing
local unit c = GetManipulatingUnit()
local string s = GetAttachedString(c, "InventoryTable")
local item m = GetManipulatedItem()
local integer g = GetItemCharges(m)
local string ts = ""
local integer ti = 0
local integer a
local integer e = GetTableInt(s, "CurrentMenu")
local integer i = GetItemTypeId(m)
local integer o = GetTableInt(s, "CurrentBackpackPage")
local integer n = o + 1
if n > BackpackSize()/4 then
set n = 1
endif
if m == GetTableItem(s, "Cancel") then
set ti = Cancel_ItemID()
set ts = "Cancel"
elseif m == GetTableItem(s, "BackpackMenu") then
set ti = BackpackMenu_ItemID()
set ts = "BackpackMenu"
elseif m == GetTableItem(s, "EquipmentMenu") then
set ti = EquipmentMenu_ItemID()
set ts = "EquipmentMenu"
elseif m == GetTableItem(s, "SwitchPage") then
set ti = SwitchPage_ItemID()
set ts = "SwitchPage"
endif
if g == 0 and (i == BackpackMenu_ItemID() or i == SwitchPage_ItemID()) then
set a = GetItemSlot(c, m)
call RemoveItem(m)
call UnitAddItemToSlotById(c, ti, a)
set m = UnitItemInSlot(c, a)
call SetTableObject(s, ts, m)
call SetItemCharges(m, g+1)
else
call SetItemCharges(m, 0)
endif
call CompressBackpack(s)
if i == EquipmentMenu_ItemID() then
call InventorySwapMenu(c, s, e, 1, 0, 0)
elseif i == BackpackMenu_ItemID() then
call InventorySwapMenu(c, s, e, 2, o, o)
elseif i == SwitchPage_ItemID() then
call InventorySwapMenu(c, s, e, 2, o, n)
elseif i == Cancel_ItemID() then
call InventorySwapMenu(c, s, e, 0, o, o)
call SetItemCharges(GetTableItem(s, "BackpackMenu"), GetTableInt(s, "BackpackItemsCount"))
endif
set c = null
set m = null
endfunction
function UnitReAddItem_Child takes nothing returns nothing
local timer t = GetExpiredTimer()
local string s = GetAttachmentTable(t)
local unit u = GetTableUnit(s, "Unit")
local item i = GetTableItem(s, "Item")
if IsItemOwned(i) and not UnitHasItem(u, i) then
call SetItemUserData(i, 2)
endif
call UnitAddItem(u, i)
call UnitDropItemSlot(u, i, GetTableInt(s, "Slot"))
call ClearTable(s)
call DestroyTimer(t)
set t = null
set u = null
set i = null
endfunction
function UnitReAddItem takes unit u, item i, integer s returns nothing
local timer t = CreateTimer()
local string a = GetAttachmentTable(t)
call SetTableObject(a, "Unit", u)
call SetTableObject(a, "Item", i)
call SetTableInt(a, "Slot", s)
call TimerStart(t, 0, false, function UnitReAddItem_Child)
set t = null
endfunction
function InventoryDropItemConditions takes nothing returns boolean
local integer i = GetItemTypeId(GetManipulatedItem())
if not IsUnitInGroup(GetManipulatingUnit(), udg_AAAInventoryGroup) then
return false
endif
if (i == EquipmentMenu_ItemID() or i == BackpackMenu_ItemID() or i == Cancel_ItemID() or i == SwitchPage_ItemID()) and (GetItemUserData(GetManipulatedItem()) == 0) then
return true
endif
if GetItemUserData(GetManipulatedItem()) == 2 then
call SetItemUserData(GetManipulatedItem(), 0)
return false
endif
return GetTableInt(GetAttachedString(GetManipulatingUnit(), "InventoryTable"), "CurrentMenu") > 0 and (GetItemUserData(GetManipulatedItem()) == 0)
endfunction
function InventoryDropItemActions takes nothing returns nothing
local unit c = GetManipulatingUnit()
local string s = GetAttachedString(c, "InventoryTable")
local item i = GetManipulatedItem()
local integer d = GetItemTypeId(i)
if GetItemType(i) == ITEM_TYPE_CHARGED and GetItemCharges(i) == 0 then
set d = GetTableInt(s, "CurrentBackpackPage")
call InventorySwapMenu(c, s, 2, 2, d, d)
elseif d == EquipmentMenu_ItemID() or d == SwitchPage_ItemID() then
call UnitReAddItem(c, i, 4)
call CS_Error(GetOwningPlayer(c), "Unable to drop this item.")
elseif d == BackpackMenu_ItemID() or d == Cancel_ItemID() then
call UnitReAddItem(c, i, 5)
call CS_Error(GetOwningPlayer(c), "Unable to drop this item.")
elseif GetTableInt(s, "CurrentMenu") > 0 then
call UnitReAddItem(c, i, GetItemSlot(c, i))
call CS_Error(GetOwningPlayer(c), "Can only drop items from the quick menu.")
endif
set c = null
set i = null
endfunction
function InventoryOrderConditions takes nothing returns boolean
if not IsUnitInGroup(GetOrderedUnit(), udg_AAAInventoryGroup) or GetIssuedOrderId() != OrderId("smart") or GetOrderTargetItem() == null then
return false
endif
return GetTableInt(GetAttachedString(GetOrderedUnit(), "InventoryTable"), "CurrentMenu") > 0
endfunction
function InventoryOrderActions takes nothing returns nothing
local unit c = GetOrderedUnit()
local string s = GetAttachedString(c, "InventoryTable")
call InventorySwapMenu(c, s, GetTableInt(s, "CurrentMenu"), 0, GetTableInt(s, "CurrentBackpackPage"), 0)
call IssueTargetOrder(c, "smart", GetOrderTargetItem())
set c = null
endfunction
function Init_AAAInventory takes nothing returns nothing
local trigger t = CreateTrigger()
local trigger u = CreateTrigger()
local trigger d = CreateTrigger()
local trigger o = CreateTrigger()
call ExecuteFunc("SetupItemBonuses")
call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerAddCondition(t, Condition( function InventoryDragItemConditions))
call TriggerAddAction(t, function InventoryDragItemActions)
call TriggerRegisterAnyUnitEventBJ( u, EVENT_PLAYER_UNIT_USE_ITEM )
call TriggerAddCondition(u, Condition(function InventoryUnitUsesItemConditions))
call TriggerAddAction(u, function InventoryUnitUsesItemActions)
call TriggerRegisterAnyUnitEventBJ( d, EVENT_PLAYER_UNIT_DROP_ITEM )
call TriggerAddCondition(d, Condition(function InventoryDropItemConditions))
call TriggerAddAction(d, function InventoryDropItemActions)
call TriggerRegisterAnyUnitEventBJ(o, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER)
call TriggerAddCondition(o, Condition(function InventoryOrderConditions))
call TriggerAddAction(o, function InventoryOrderActions)
set t = null
set u = null
set d = null
set o = null
endfunction
//===========================================================================
function InitTrig_AAAInventory takes nothing returns nothing
call ExecuteFunc("Init_AAAInventory")
endfunction