/*
================================ Requirements =================================
This System does not need any other systems for it to work.
================================ Installing =================================
Just copy and paste this library to your map and change the values i listed below and you are good to go.
Create variables in your variable editor. Make a trigger go to edit and convert to custom text.
then delete everything there and paste this in its place. name the trigger ItemDatabase
================================ variables to create =================================
variable type | name
Integer | MERCHANT
Integer | BUYER
Hashtable | itemHash
================================ how to use functions / custom scripts =================================
here is the custom scripts u can copy from here paste and change values u need to
call GetItemGoldCost( GetItemTypeId( GetManipulatedItem())) - this is for getting gold cost
call GetItemLumberCost( GetItemTypeId( GetManipulatedItem())) - this is for getting lumber cost
call ItemLvlCheck( boolean) true for drop item, false for remove item - this is to see if unit is able to use item
================================ Explanation =================================
This system allows you to get the item cost and lumber cost of any item you have picked up.
It also has an option that allows you to order a unit to drop item if the item lvl is higher than the hero lvl.
You have 2 options when it comes to this you can either have the unit drop the item or you can remove the item.
================================ Things You need to change =================================
You do need to change 2 values and create a unit
The unit must have the abilities Sell Items and Shop Purchase Item. I used the marketplace.
You have to change MERCHANT to your marketplace and change BUYER to a unit w a backpack.
*/
function ItemDataStartup takes nothing returns nothing
set udg_MERCHANT = 'n01M' // change this
set udg_BUYER = 'Hblm' // change this
endfunction
function GetItemGoldCost takes integer I returns integer
return LoadInteger( udg_itemHash, I, 1)
endfunction
function GetItemLumberCost takes integer I returns integer
return LoadInteger( udg_itemHash, I, 2)
endfunction
function GetItemUnitLvl takes item I, unit u returns boolean
return GetItemLevel( I) <= GetHeroLevel( u)
endfunction
function ItemLvlCheck takes boolean d returns nothing
local unit u = GetTriggerUnit()
local item I = GetManipulatedItem()
local boolean b = GetItemUnitLvl( I, u)
if b == false then
if d == true then
call UnitDropItemPoint( u, I, GetUnitX( u), GetUnitY( u))
else
call RemoveItem( I)
endif
endif
set u = null
set I = null
endfunction
function StoreItemGL takes nothing returns nothing
local integer id = GetItemTypeId( GetManipulatedItem())
local integer gold = GetPlayerState( Player(11), PLAYER_STATE_RESOURCE_GOLD)
local integer lumber = GetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER)
local unit u = CreateUnit( Player(11), udg_MERCHANT, 0, 0, 270)
local integer resource = 1000000
local integer costG
local integer costL
call SetPlayerState( Player(11), PLAYER_STATE_RESOURCE_GOLD, resource)
call SetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER, resource)
call AddItemToStock( u, id, 1, 1)
call CreateUnit( Player(11), udg_BUYER, 0, 0, 0)
call IssueNeutralImmediateOrderById( Player(11), u, id)
set costG = resource - GetPlayerState( Player(11), PLAYER_STATE_RESOURCE_GOLD)
set costL = resource - GetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER)
call SetPlayerState( Player(11), PLAYER_STATE_RESOURCE_GOLD, gold)
call SetPlayerState( Player(11), PLAYER_STATE_RESOURCE_LUMBER, lumber)
call SaveInteger( udg_itemHash, id, 1, costG)
call SaveInteger( udg_itemHash, id, 2, costL)
set u = null
endfunction
function IsInHashCheck takes nothing returns boolean
return not HaveSavedInteger( udg_itemHash, GetItemTypeId( GetManipulatedItem()), 0)
endfunction
function InitTrig_ItemDatabase takes nothing returns nothing
local trigger t = CreateTrigger()
local integer L = 0
call ItemDataStartup()
set udg_itemHash = InitHashtable()
loop
exitwhen L > 11
call TriggerRegisterPlayerUnitEvent( t, Player(L), EVENT_PLAYER_UNIT_PICKUP_ITEM, function IsInHashCheck)
set L = L + 1
endloop
call TriggerAddAction( t, function StoreItemGL)
set t = null
endfunction