• 🏆 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!

[Trigger] Item Query!

Status
Not open for further replies.
Level 12
Joined
Jan 13, 2008
Messages
559
Hi,

is there a chance to find out if an item got looted from the ground or bought in a shop?

I am working with level restrictions.

Example 1:
hero level 1 wants to acquire a level 5 item via shop -> hero level ain't high enough -> remove item from hero and return gold

Example 2:
hero level 1 wants to acquire a dropped level 5 item -> hero level ain't high enough -> item gets dropped and removed due the trigger in example 1. (Instead of just dropping)

How am I solving this problem? It seems like I can't check if the item got dropped or bought in a shop. I know there is a solution because i played RPGs which got level restrictions on items too.

thanks
 
Level 29
Joined
Oct 24, 2012
Messages
6,543
ooo ok mybe ill make a gui friendly version. just keep looking on here if i make one ill post it here for u.

here u go just copy paste and follow instructions on how to install and use in gui.

JASS:
/*
================================ 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
 
Last edited:
Status
Not open for further replies.
Top