Name | Type | is_array | initial_value |
//TESH.scrollpos=0
//TESH.alwaysfold=0
struct loot
//****************************************************
// customizable fiels
//****************************************************
// You can change some messages directly. Don't modify
// the field looters. Just put in the array the looter
// for each player.
// Modify the method IsLootable if you want soem items
// availables only to some heros for instance.
//****************************************************
static method IsLootable takes item dummy, player looter returns boolean
if GetItemType(dummy) == ITEM_TYPE_TOME then
return true
elseif UnitInventoryCount(loot.looters[GetPlayerId(GetTriggerPlayer())]) < UnitInventorySize(loot.looters[GetPlayerId(GetTriggerPlayer())]) then
return true
endif
return false
endmethod
static unit array looters[11] // the units where goes the loot
static constant string cancel = "|cffff0000cancel"
static constant string looterror1 = "|cffff0000You can't loot anything: your inventory is full !"
static constant string looterror2 = "|cffff0000You can't loot this item: your inventory is full !"
//****************************************************
// available methods
//****************************************************
// LootDialog( item chest, player looter )
// create( item chest, string title, integer count )
// destroy()
//****************************************************
// In most case, you'll only use create. It takes the
// item to be used as a chest, the title of the poping
// dialog, and the count of items in (max 10)
// Give you items TypeIds in the array
// loot.CreateItemsTypes[10] before calling create
//****************************************************
// you shouldn't modify the following !
private static constant integer maxItems = 10
private static trigger handler = CreateTrigger()
private item chest // to check the chest
private location chestloc
private dialog list // what we gonna use to show our items
private string title // maybe we can show a different title for our dialog on special loots
private button array Items[loot.maxItems] // our items
private integer array ItemsTypes[loot.maxItems] // our items types
private integer remaining // the number of remaining items
method LootDialog takes item chest, player looter returns boolean
local integer temp = GetItemTypeId(this.chest)
local item dummy = null
local integer id = 0
local string color
local boolean lootable = false
if chest != this.chest then
return false
endif
call DialogClear(this.list)
loop
exitwhen id >= loot.maxItems
if this.ItemsTypes[id] != 0 then
set dummy = CreateItem(this.ItemsTypes[id], 0, 0)
if loot.IsLootable(dummy, looter) then
set lootable = true
endif
if loot.IsLootable(dummy, GetLocalPlayer()) then
set color = "|cff00ff00"
else
set color = "|cffff0000"
endif
set this.Items[id] = DialogAddButton(this.list, color + GetItemName(dummy), 0)
call RemoveItem(dummy)
endif
set id = id + 1
endloop
set dummy = null
call DialogAddButton(this.list, loot.cancel, 0)
if not lootable then
//notify the player he can't loot anything
call DisplayTextToPlayer(looter, 0, 0, loot.looterror1)
// recreate the chest because it has been used
call RemoveItem(this.chest)
set this.chest = CreateItemLoc(temp, this.chestloc)
call SetItemUserData(this.chest, this)
return false
endif
call DialogSetMessage(this.list, this.title)
call DialogDisplay(looter, this.list, true)
call RemoveItem(this.chest)
set this.chest = CreateItemLoc(temp, this.chestloc)
call SetItemUserData(this.chest, this)
return true
endmethod
private static method loot takes nothing returns nothing
local loot this = 0
local integer id = 0
local integer pindex = 0
local string color
local item dummy = null
local boolean lootable = false
loop
set this = this + 1
if this == 8193 then // maybe another dialog that is not a loot
return
endif
exitwhen this.list == GetClickedDialog()
endloop
// now, if it's correct, we do have our dialog.
// check the button
loop
exitwhen this.Items[id] == GetClickedButton()
set id = id + 1
if id > loot.maxItems then // maybe we hitted the cancel button
return
endif
endloop
// we do have the item that the player want !
if loot.looters[GetPlayerId(GetTriggerPlayer())] == null then // see error line...
call BJDebugMsg("error: looting unit not defined for player " + I2S(GetPlayerId(GetTriggerPlayer()))) // we don't care about his name
return
endif
//check the player can take the item he selected
set dummy = CreateItem(this.ItemsTypes[id], 0, 0)
if loot.IsLootable(dummy, GetTriggerPlayer()) then
// finnaly, this is done !
call UnitAddItemByIdSwapped( this.ItemsTypes[id], loot.looters[GetPlayerId(GetTriggerPlayer())] )
// check wether any item is remaining or not
set this.remaining = this.remaining - 1
if this.remaining == 0 then
call this.destroy()
return
endif
// remove the button
set this.ItemsTypes[id] = 0
else
call DisplayTextToPlayer(GetTriggerPlayer(), 0, 0, loot.looterror2)
endif
call RemoveItem(dummy)
// rebuild the list
call DialogClear(this.list)
set id = 0
loop
exitwhen id >= loot.maxItems
if this.ItemsTypes[id] != 0 then
set dummy = CreateItem(this.ItemsTypes[id], 0, 0)
//if you can gather more stuff...
if loot.IsLootable(dummy, GetTriggerPlayer()) then
set lootable = true
endif
if loot.IsLootable(dummy, GetLocalPlayer()) then
set color = "|cff00ff00"
else
set color = "|cffff0000"
endif
set this.Items[id] = DialogAddButton(this.list, color + GetItemName(dummy), 0)
call RemoveItem(dummy)
endif
set id = id + 1
endloop
call DialogAddButton(this.list, loot.cancel, 0)
set dummy = null
// if the looter has any remaining slot, then show him again
if lootable or UnitInventoryCount(loot.looters[GetPlayerId(GetTriggerPlayer())]) < UnitInventorySize(loot.looters[GetPlayerId(GetTriggerPlayer())]) then
call this.LootDialog(this.chest, GetTriggerPlayer())
endif
endmethod
static integer array CreateItemsTypes[loot.maxItems] // use this to give your items to the create method
static method create takes item chest, string title, integer count returns loot
local loot this = loot.allocate()
local integer index = 0
set this.chestloc = GetItemLoc(chest)
set this.list = DialogCreate()
set this.chest = chest
call SetItemUserData(chest, this)
if count > loot.maxItems then
call BJDebugMsg("error: item count in loot can't be supérior to " + I2S(loot.maxItems))
call this.destroy()
return 0
endif
set this.remaining = count
loop
exitwhen index >= this.remaining
set this.ItemsTypes[index] = loot.CreateItemsTypes[index]
set index = index + 1
endloop
loop
exitwhen index >= loot.maxItems
set this.ItemsTypes[index] = 0
set index = index + 1
endloop
call TriggerRegisterDialogEvent( loot.handler, this.list )
set this.title = title
return this
endmethod
method onDestroy takes nothing returns nothing
call RemoveLocation(this.chestloc)
call RemoveItem(this.chest)
call DialogDestroy(this.list)
endmethod
private static method onInit takes nothing returns nothing
call TriggerAddAction(loot.handler, function loot.loot)
endmethod
endstruct
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_Loot_handler_Actions takes nothing returns nothing
local loot this = GetItemUserData(GetManipulatedItem())
call this.LootDialog(GetManipulatedItem(), GetOwningPlayer(GetManipulatingUnit()))
endfunction
//===========================================================================
function InitTrig_Loot_handler takes nothing returns nothing
set gg_trg_Loot_handler = CreateTrigger( )
call TriggerRegisterAnyUnitEventBJ( gg_trg_Loot_handler, EVENT_PLAYER_UNIT_PICKUP_ITEM )
call TriggerAddAction( gg_trg_Loot_handler, function Trig_Loot_handler_Actions )
endfunction
//TESH.scrollpos=0
//TESH.alwaysfold=0
function Trig_test_Actions takes nothing returns nothing
//set the paladin to be the red player's looter
set loot.looters[0] = gg_unit_Hpal_0001
//create our loot chest
//first we create the array with the items to be looted
set loot.CreateItemsTypes[0] = 'ratc'
set loot.CreateItemsTypes[1] = 'rat6'
set loot.CreateItemsTypes[2] = 'rat9'
set loot.CreateItemsTypes[3] = 'ratc'
set loot.CreateItemsTypes[4] = 'rat6'
set loot.CreateItemsTypes[5] = 'rat9'
set loot.CreateItemsTypes[6] = 'ratc'
set loot.CreateItemsTypes[7] = 'rat6'
set loot.CreateItemsTypes[8] = 'rat9'
set loot.CreateItemsTypes[9] = 'texp'
//then we create a chest giving the item to be used, the title to display and the count of items
//for special loot, you may want change the chest's skin and the title, so that's why I let you do this
call loot.create( gg_item_I000_0002, "you looted claws !", 10 )
//create a second loot chest
set loot.CreateItemsTypes[0] = 'tstr'
set loot.CreateItemsTypes[1] = 'tdex'
set loot.CreateItemsTypes[2] = 'tint'
set loot.CreateItemsTypes[3] = 'tpow'
call loot.create( gg_item_I001_0003, "you found some books", 4 )
endfunction
//===========================================================================
function InitTrig_test takes nothing returns nothing
set gg_trg_test = CreateTrigger( )
call TriggerAddAction( gg_trg_test, function Trig_test_Actions )
endfunction