- Joined
- Oct 24, 2012
- Messages
- 6,545
hello i have an item system it gets item lumber and gold cost and also has a drop item for when the item lvl is higher than your hero or units lvl. it adds all items picked up by any player to a hashtable. this system is simple to use there r three main functions GetItemGoldCost, GetItemLumberCost, and ItemLvlCheck. The lvl check has a drop or remove item option just a boolean true or false.
it is a simple system. i thought it would be nice for ppl to have if they need something like this.
its easy to install just copy and paste it into your map.
note: you have to make 1 unit in object editor and change the constant value i called MERCHANT. they also need to change the value for the Buyer unit. the merchant has to have 2 abilities to allow this to work properly.
here is the system. i hope to expand on it in the future put a couple more features into it if i can.
it is a simple system. i thought it would be nice for ppl to have if they need something like this.
its easy to install just copy and paste it into your map.
note: you have to make 1 unit in object editor and change the constant value i called MERCHANT. they also need to change the value for the Buyer unit. the merchant has to have 2 abilities to allow this to work properly.
here is the system. i hope to expand on it in the future put a couple more features into it if i can.
JASS:
library ItemGL
/* uses Alloc *
================================ 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.
================================ 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.
======================================== API ==========================================
static method getItemGoldCost takes item itm returns integer
returns gold cost of item
static method getItemLumberCost takes item itm returns integer
returns lumber cost of 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.
*/
globals
private Table itemTable
endglobals
struct ItemCosts extends array
implement Alloc
private static constant integer MERCHANT = 'n01M'
private static constant integer BUYER = 'Hblm' // change this
private static rect unitRect
private static method storeRectValue takes nothing returns nothing
//set unitRect = gg_rct_unitRect // set this to ur rect
endmethod
private static constant playerstate PSRG = PLAYER_STATE_RESOURCE_GOLD
private static constant playerstate PSRL = PLAYER_STATE_RESOURCE_LUMBER
private static constant integer MAX = 1000000
private static real unitX
private static real unitY
private static unit merchant
private static unit buyer
private integer gold
private integer lumber
static method getItemGoldCost takes item itm returns integer
local thistype this = itemTable[ GetHandleId( itm)]
return this.gold
endmethod
static method getItemLumberCost takes item itm returns integer
local thistype this = itemTable[ GetHandleId( itm)]
return this.lumber
endmethod
static method create takes item itm returns thistype
local thistype this = thistype.allocate()
return this
endmethod
method destroy takes nothing returns nothing
call this.deallocate()
endmethod
private static method storeItem takes nothing returns nothing
local integer id = GetItemTypeId( GetManipulatedItem())
local thistype this = thistype.create( GetManipulatedItem())
local integer playerG = GetPlayerState( Player(11), PSRG)
local integer playerL = GetPlayerState( Player(11), PSRL)
call MapItemCleanup.pause()
call SetPlayerState( Player(11), PSRG, MAX)
call SetPlayerState( Player(11), PSRL, MAX)
call AddItemToStock( merchant, id, 1, 1)
call IssueNeutralImmediateOrderById( Player(11), merchant, id)
set this.gold = MAX - GetPlayerState( Player(11), PSRG)
set this.lumber = MAX - GetPlayerState( Player(11), PSRL)
call SetPlayerState( Player(11), PSRG, playerG)
call SetPlayerState( Player(11), PSRL, playerL)
call MapItemCleanup.resume()
endmethod
private static method isItemInTable takes nothing returns boolean
if itemTable.has( GetItemTypeId( GetManipulatedItem())) then
call storeItem()
endif
return false
endmethod
private static method onInit takes nothing returns nothing
local trigger t = CreateTrigger()
call storeRectValue()
set merchant = CreateUnit( Player(11), MERCHANT, unitX, unitY, 270)
set buyer = CreateUnit( Player(11), BUYER, unitX, unitY, 0)
call TriggerRegisterAnyUnitEventBJ( t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition( t, function thistype.isItemInTable)
set t = null
endmethod
endstruct
endlibrary
Last edited: