• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

item Gold and Lumber cost and lvl check

Level 29
Joined
Oct 24, 2012
Messages
6,543
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.

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:
Level 29
Joined
Oct 24, 2012
Messages
6,543
stupid question but what do u mean api ? lol. if api is the list of functions tht ppl can use i added tht forgot to repost it on here

and ya tht is really similar never noticed there was one out there thts close to the one i made. not really sure which is better. tht one uses table mine just uses normal hashtable. i have the option to make units tht arent a valid lvl to drop the item or to remove the item but tht is just a small feature
 
Level 31
Joined
Jul 10, 2007
Messages
6,306
Level 29
Joined
Oct 24, 2012
Messages
6,543
The IsInHash condition does never get applied to the trigger, so the store function runs every time an item is picked up.

Also, it should use a constant dummy instead of creating and destroying dummys every time it's used.
The player the dummy is created for should be configurable and also the place where the dummys are created.

ItemLvLCheck should not be part of the system, as it has no relation to the getGold/lumber functionality. You can make it a public getter, but it should not cause the unit to actually drop the item.

Also, was Nes said: There have been better submissions on that.
 
Top