//===========================================================================
//========== MCI Portable Mini Inventory ENGINE by ScorpioT1000 ===========
//===========================================================================
function TriggerRegisterAnyUnitEventAntiBJ takes trigger trig, playerunitevent whichEvent returns nothing
local integer index
set index = 0
loop
call TriggerRegisterPlayerUnitEvent(trig, Player(index), whichEvent, null)
set index = index + 1
exitwhen index == bj_MAX_PLAYER_SLOTS
endloop
endfunction
// ===
function MCI_IsUnitInventory takes unit u returns boolean
local integer i = 0
loop
exitwhen (udg_MCI_Inventory[i] == u) or i>=udg_MCI_UnitNum
set i=i+1
endloop
if udg_MCI_Inventory[i] == u then
return true
endif
return false
endfunction
function MCI_UnitWithInventory takes unit u returns boolean
local integer i = 0
loop
exitwhen (udg_MCI_Unit[i] == u) or i>=udg_MCI_UnitNum
set i=i+1
endloop
if udg_MCI_Unit[i] == u then
return true
endif
return false
endfunction
//
function MCI_UnitToInv takes unit hero returns unit
local integer i = 0
loop
exitwhen (udg_MCI_Unit[i] == hero) or i>=udg_MCI_UnitNum
set i=i+1
endloop
if udg_MCI_Unit[i] == hero then
return udg_MCI_Inventory[i]
endif
return null
endfunction
function MCI_InvToUnit takes unit inv returns unit
local integer i = 0
loop
exitwhen (udg_MCI_Inventory[i] == inv) or i>=udg_MCI_UnitNum
set i=i+1
endloop
if udg_MCI_Inventory[i] == inv then
return udg_MCI_Unit[i]
endif
return null
endfunction
//
function MCI_PrepareUnit takes unit u returns nothing
local integer i = 2
local item itm
loop
exitwhen i > 7
if UnitItemInSlot(u,i-2) == null then
set itm = CreateItem(udg_MCI_ItemType[i], 0, 0)
call UnitAddItem(u, itm)
endif
set i=i+1
endloop
set itm = null
endfunction
function MCI_PrepareUnits takes nothing returns nothing
local integer i = 0
loop
exitwhen i >= udg_MCI_UnitNum
call MCI_PrepareUnit(udg_MCI_Unit[i])
set i=i+1
endloop
endfunction
//===========================================================================
//===========================================================================
//===========================================================================
// ================== MCI PickUp ==================
function Trig_MCIPickUp_new_Actions takes nothing returns nothing
//init
local unit hero = GetTriggerUnit()
local unit inv = MCI_UnitToInv(hero)
local item itm = GetOrderTargetItem()
local integer index = 1
local integer i = 1
local integer slots = 0
local real x = GetUnitX(hero)
local real y = GetUnitY(hero)
local real ix = GetItemX(itm)
local real iy = GetItemY(itm)
local real speed = GetUnitMoveSpeed(hero)
local real dist = SquareRoot(Pow((ix-x),2)+Pow((iy-y),2)) //distance
//go to item
if ( dist >= (udg_MCI_GlobalValue[2] - 50.00) ) then
call IssuePointOrder(hero,"move",ix,iy)
call TriggerSleepAction(dist/speed)
endif
call IssueTargetOrder(inv,"smart",itm)
//check slots
set i = 0
loop
exitwhen i > 5
if (UnitItemInSlot(inv,i) == null) then
set slots=slots+1
endif
set i=i+1
endloop
if (slots==0) then
call DisplayTimedTextToPlayer(GetOwningPlayer(hero),0.,0.,1.50,udg_MCI_Text[1])
endif
set hero = null
set itm = null
set inv = null
endfunction
function Trig_MCIPickUp_new_Conditions takes nothing returns boolean
if GetOrderTargetItem() == null then
return false
elseif GetItemType(GetOrderTargetItem()) == ITEM_TYPE_POWERUP then
return false
elseif GetIssuedOrderId() == OrderId("attack") then
return false
else
return MCI_UnitWithInventory(GetTriggerUnit())
endif
return true
endfunction
// ================== MCI PickUp END ==================
// ================== MCI Using ==================
function Trig_MCIUse_Actions takes nothing returns nothing
//init
local unit hero = GetTriggerUnit()
local unit inv
local item itm = GetManipulatedItem()
local integer tdummy
local item idummy
local item temp
local integer index = 1
local integer i = 1
local integer itmLevel = GetItemLevel(itm)
local integer slots = 0
if MCI_IsUnitInventory(hero) then
set inv = hero
set hero = MCI_InvToUnit(hero)
//check slots
loop
exitwhen i > 6
if ( itmLevel==i+1 ) then
//check dummy-item
set idummy = UnitItemInSlot(hero,i-1)
set tdummy = GetItemTypeId(idummy)
if (udg_MCI_ItemType[i+1] != tdummy) then
call RemoveItem(idummy)
set temp = CreateItem(GetItemTypeId(itm),0.,0.)
call UnitAddItem(hero,temp)
call RemoveItem(itm)
set temp = CreateItem(tdummy,0.,0.)
call UnitAddItem(inv,temp)
else
call RemoveItem(idummy)
set temp = CreateItem(GetItemTypeId(itm),0.,0.)
call UnitAddItem(hero,temp)
call RemoveItem(itm)
endif
endif
set i=i+1
endloop
elseif MCI_UnitWithInventory(hero) then
set inv = MCI_UnitToInv(hero)
//check slots
set i=1
loop
exitwhen i>6
set idummy = UnitItemInSlot(inv,i-1)
if (idummy==null) then
set slots=slots+1
endif
set i=i+1
endloop
if (slots==0) then
call DisplayTimedTextToPlayer(GetOwningPlayer(hero),0.,0.,2.00,udg_MCI_Text[2])
else
set temp = CreateItem(GetItemTypeId(itm),0.,0.)
call UnitAddItem(inv,temp)
call RemoveItem( UnitItemInSlot(hero,itmLevel-2) )
set temp = CreateItem(udg_MCI_ItemType[itmLevel],0.,0.)
call UnitAddItem(hero,temp)
endif
set i=i+1
endif
set idummy = null
set hero = null
set inv = null
set itm = null
endfunction
function Trig_MCIUse_Conditions takes nothing returns boolean
return GetItemType(GetOrderTargetItem()) != ITEM_TYPE_POWERUP
endfunction
// ================== MCI Using END ==================
// ================== MCI PortInvMoving ==================
function Trig_MCIPortInvMoving_Actions takes nothing returns nothing
local real X
local real Y
local real a
local integer i = 0
loop
exitwhen i >= udg_MCI_UnitNum
if udg_MCI_Unit[i] != null then
if udg_MCI_Inventory[i] == null then
set udg_MCI_Inventory[i] = CreateUnit(GetOwningPlayer(udg_MCI_Unit[i]), udg_MCI_InvUnit,0,0, bj_UNIT_FACING )
call MCI_PrepareUnit(udg_MCI_Unit[i])
else
set a = GetUnitFacing(udg_MCI_Unit[i])
set a = a+180
set X = GetUnitX(udg_MCI_Unit[i])
set Y = GetUnitY(udg_MCI_Unit[i])
set X = X+50*Cos(a*bj_DEGTORAD)
set Y = Y+50*Sin(a*bj_DEGTORAD)
call SetUnitX(udg_MCI_Inventory[i], X)
call SetUnitY(udg_MCI_Inventory[i], Y)
endif
elseif udg_MCI_Inventory[i] != null then
call RemoveUnit(udg_MCI_Inventory[i])
set udg_MCI_Inventory[i] = null
endif
set i=i+1
endloop
endfunction
// ================== MCI PortInvMoving END ==================
// ================== MCI Workshop ==================
function Trig_MCIWorkshop_Actions takes nothing returns nothing
local integer index
local unit c = GetSpellAbilityUnit()
local unit u = GetSpellTargetUnit()
loop
exitwhen (udg_MCI_Unit[index] == u) or index >= udg_MCI_UnitNum
set index=index+1
endloop
if index < udg_MCI_UnitNum then
call TriggerSleepAction(0.1)
call IssueTargetOrder(c,"smart",udg_MCI_Inventory[index])
endif
set c = null
set u = null
endfunction
function Trig_MCIWorkshop_Conditions takes nothing returns boolean
return GetSpellAbilityId() == 'Aneu'
endfunction
// ================== MCI Workshop END ==================
// ================== MCI Selection ==================
function MCI_Selection_Actions takes nothing returns nothing
local unit obj = GetTriggerUnit()
local integer thisPlayer = GetPlayerId(GetTriggerPlayer())
if MCI_UnitWithInventory(obj) then
set udg_MCI_LastSelectedUnit[thisPlayer] = obj
elseif (udg_MCI_LastSelectedUnit[thisPlayer] != null) and MCI_IsUnitInventory(obj) then
if GetLocalPlayer() == Player(thisPlayer) then
call SetCameraTargetController(obj,0,0,false)
call ClearSelection()
set obj = MCI_UnitToInv(udg_MCI_LastSelectedUnit[thisPlayer])
call SelectUnit(obj,true)
if udg_MCI_SettingBool[1] then
call PanCameraToTimed(GetUnitX(obj),GetUnitY(obj),0)
endif
endif
set udg_MCI_LastSelectedUnit[thisPlayer] = null
endif
set obj = null
endfunction
function MCI_Selection_Cond takes nothing returns boolean
return udg_MCI_SettingBool[0]
endfunction
// ================== MCI Selection END ==================
//===========================================================================
//===========================================================================
//===========================================================================
function MCI_PreInit takes nothing returns nothing
local integer i = 0
local integer j
local item itm = null
// =============== StartInit
set udg_MCI_Unit[udg_MCI_UnitNum] = null
set i = 0
loop
exitwhen i > 11
set udg_MCI_LastSelectedUnit[i] = null
set i=i+1
endloop
set i = 0
loop
exitwhen i >= udg_MCI_UnitNum
set udg_MCI_Inventory[i] = CreateUnit(GetOwningPlayer(udg_MCI_Unit[i]), udg_MCI_InvUnit,0,0, bj_UNIT_FACING )
set i=i+1
endloop
call MCI_PrepareUnits()
endfunction
function PortableMiniInvEngine_INITIALIZATOR takes nothing returns nothing
local trigger MCIPickUp = CreateTrigger()
local trigger MCIUse = CreateTrigger()
local trigger MCIPortInvMoving = CreateTrigger()
local trigger MCIWorkshop = CreateTrigger()
local trigger MCI_Selection = CreateTrigger()
local trigger MCI_Prelauncher = CreateTrigger()
local integer i = 0
// MCI PickUp
call TriggerRegisterAnyUnitEventAntiBJ( MCIPickUp, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER )
call TriggerAddCondition( MCIPickUp, Condition( function Trig_MCIPickUp_new_Conditions ) )
call TriggerAddAction( MCIPickUp, function Trig_MCIPickUp_new_Actions )
// MCI Using
call TriggerRegisterAnyUnitEventAntiBJ( MCIUse, EVENT_PLAYER_UNIT_USE_ITEM )
call TriggerAddCondition( MCIUse, Condition( function Trig_MCIUse_Conditions ) )
call TriggerAddAction( MCIUse, function Trig_MCIUse_Actions )
// MCI PortInvMoving
call TriggerRegisterTimerEvent( MCIPortInvMoving, 0.2, true )
call TriggerAddAction( MCIPortInvMoving, function Trig_MCIPortInvMoving_Actions )
// MCI Workshop
call TriggerRegisterAnyUnitEventAntiBJ( MCIWorkshop, EVENT_PLAYER_UNIT_SPELL_EFFECT )
call TriggerAddCondition( MCIWorkshop, Condition( function Trig_MCIWorkshop_Conditions ) )
call TriggerAddAction( MCIWorkshop, function Trig_MCIWorkshop_Actions )
// MCI Selection
loop
exitwhen i>11
call TriggerRegisterPlayerUnitEvent(MCI_Selection, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
set i=i+1
endloop
call TriggerAddCondition( MCI_Selection, Condition( function MCI_Selection_Cond ) )
call TriggerAddAction( MCI_Selection, function MCI_Selection_Actions )
// MCI PreLauncher
call TriggerRegisterTimerEvent( MCI_Prelauncher, 0.0, false )
call TriggerAddAction( MCI_Prelauncher, function MCI_PreInit )
set MCIPickUp = null
set MCIUse = null
set MCIPortInvMoving = null
set MCIWorkshop = null
set MCI_Selection = null
set MCI_Prelauncher = null
endfunction