• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Items like on dota

Status
Not open for further replies.
Level 7
Joined
Jul 12, 2008
Messages
295
How can i make this: When a hero buys an item and then puts it on the ground.. And when other player picks it up to be unsoldable and to give nothing(I mean to be used by his rightful owner)
 
Level 5
Joined
Dec 18, 2007
Messages
205
Hmm, that's quite difficult.
I think you need 2 arrays, 1 item array variable and 1 player array variable.
If an item is sold, then you check which array nmber is free, set this item to that item array and then set the exact player array number to the owning player.
If an item is sold (or mixed?, dunno what you want to make) you must empty both array numbers.
If an other owner aquires that item you must replace the item with a fake item of that type and change the item array.
Whoa, while i'm writing this here, it seems to be very difficult. i think over it once again, but i don't think i can easily find a trigger.
 
Level 5
Joined
Dec 18, 2007
Messages
205
okay, i've written some triggers and codes, but i didn't get to a solution because the Unit-Aquires trigger and the Unit-Sells-an-item trigger activate both when a unit buys an item from a shop, and i don'Ät know how to fix.

If a good JASSer is looking at this code, he could help me and the author of the topic by the solution.

He're my 3 triggers for now:

1. Getting Owner Trigger gets the owner of the item just being sold
JASS:
function Trig_Setting_Owner_Actions takes nothing returns nothing
    local integer i=0
    loop
        exitwhen GetBooleanOr(udg_Item[i]==null,i>udg_Item_Max)
        set i=i+1
    endloop
    if i>udg_Item_Max then
        call BJDebugMsg("|cffff0000Error:|rItem limit reached. Item-Owner-Detection failed.")
        call BJDebugMsg("|cffff0000Error:|rThe author of the map should increase this value.")
        return
    endif
    set udg_Item[i]=GetSoldItem()
    set udg_Item_Owner[i]=GetOwningPlayer(GetBuyingUnit())
endfunction

//===========================================================================
function InitTrig_Setting_Owner takes nothing returns nothing
    set gg_trg_Setting_Owner = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Setting_Owner, EVENT_PLAYER_UNIT_SELL_ITEM )
    call TriggerAddAction( gg_trg_Setting_Owner, function Trig_Setting_Owner_Actions )
endfunction

2. Removing Owner Trigger removes the item/player when the item is sold (later maybe when the item is destroyed etc.)
JASS:
function Trig_Removing_Owner_Actions takes nothing returns nothing
    local integer i=0
    loop
        exitwhen GetBooleanOr(udg_Item[i]==GetSoldItem(),i>udg_Item_Max)
        set i=i+1
    endloop
    if i>udg_Item_Max then
        return
    endif
    set udg_Item[i]=null
    set udg_Item_Owner[i]=null
endfunction

//===========================================================================
function InitTrig_Removing_Owner takes nothing returns nothing
    set gg_trg_Removing_Owner = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Removing_Owner, EVENT_PLAYER_UNIT_PAWN_ITEM )
    call TriggerAddAction( gg_trg_Removing_Owner, function Trig_Removing_Owner_Actions )
endfunction

3. and the difficult part: Getting Owner trigger should only activate, when a unit aquires an item NOT from the shop. It checks the owner and replaces the item
JASS:
function GetFakeItem takes item i returns integer
    if GetBooleanOr(GetItemTypeId(i) == 'I000',GetItemTypeId(i) == 'I001') then
        return 'I000'
    
    endif
    call BJDebugMsg("|cffff0000Error:|r Item Database doesn't fit with target item.")
    return 'texp'   
endfunction

function GetRealItem takes item i returns integer
    if GetBooleanOr(GetItemTypeId(i) == 'I000',GetItemTypeId(i) == 'I001') then
        return 'I001'
    
    endif
    call BJDebugMsg("|cffff0000Error:|r Item Database doesn't fit with target item.")
    return 'texp'   
endfunction
//===========================================================================
function Trig_Getting_Owner_Actions takes nothing returns nothing
    local integer i
    local unit u=GetTriggerUnit()
    local integer itemid
    loop
        exitwhen GetBooleanOr(udg_Item[i]==GetManipulatedItem(),i>udg_Item_Max)
        set i=i+1
    endloop
    if i>udg_Item_Max then
        return
    endif
    if udg_Item_Owner[i]!=GetOwningPlayer(u) then
        set itemid=GetFakeItem(GetManipulatedItem())
    else
        set itemid=GetRealItem(GetManipulatedItem())
    endif
    call RemoveItem(GetManipulatedItem())
    call UnitAddItemById(u,itemid)    
    set udg_Item[i]=GetLastCreatedItem()
    set u=null
endfunction

//===========================================================================
function InitTrig_Getting_Owner takes nothing returns nothing
    set gg_trg_Getting_Owner = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Getting_Owner, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Getting_Owner, function Trig_Getting_Owner_Actions )
endfunction

I don't know, if the triggers work, if there's a soultion for the aquires-item-thing, but i cannot work on until that problem is fixed, i think

greetz
 
Level 11
Joined
Oct 13, 2005
Messages
233
First off, the simplest way to stop anyone except for the "owner" of an item from using an item would be to drop the item from any hero that picks it up that is not the owner. Now, I don't have access to the World Editor at the moment, but the trigger (in GUI) would look somewhat like this:
Code:
Event - A Unit Acquires an Item
Actions:
    if custom value of (item) == 0 then
        set custom value of (item) to player number of (owner of hero manipulating item)

    if custom value of (item) != player number of (owner of hero manipulating item) then
        drop (item being manipulated) from (hero manipulating item)
Key:
== means equal to
!= means not equal to

Whenever a hero acquires an item that isn't owned by another player (custom value = 0) then the custom value of the item is set to the player number of the player that owns the hero. Then, if the custom value of the item doesn't equal the player number that owns the hero, the item will be dropped.

Now for some JASS suggestions for bReathl3sS:
  • You don't want to use GetBooleanOr the way you're using it. (Actually, you should probably never need to use that function ever). Instead, you want to have each boolean expression separate and with "or" between them like so:
    JASS:
    exitwhen udg_Item[i] == null or i > udg_Item_Max
  • Values in arrays do not have a default value. Your trigger assumes that default values in an item array are null when there are none.
  • You could have implemented this method much more cleanly using a stack instead of checking through each index of the arrays, but I won't go into that now since I don't have much time. If you're interested in how a stack works, let me know and I'll give you some example code.
 
Level 5
Joined
Dec 18, 2007
Messages
205
Well, ok wyrmlord, I take ur suggestion for the 'or' thing (didn't know that there's something that easy).
But what are the arrays then? they are not null, so what are they then? not specified or is there a value? and would 'if xxx==null' return false or true in that case? or is there happening sth. else?

You said sth. about an easier method: stacks. So I'm quite new to JASS, so could you tell me: what are stacks exactly as a code?

And Igor_Z: The method of wyrmlord is the easiest, yes. Just set the custom value of an item to the player nubmer of the first owner and when s.o. else trys to pick it up (other player number) then drop it.
Then you could add a command, that makes an item shareable (e.g. setting custom value to 13 and make that item custom value to be able to be picked by everyone). Dunno what you want.

greetz
 
Status
Not open for further replies.
Top