• 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.

[JASS] Item owner

Status
Not open for further replies.
Level 2
Joined
Dec 14, 2012
Messages
20
JASS:
function item_is_in_pool takes nothing returns boolean
if(GetItemTypeId(GetManipulatedItem())=='I06B')then
return true
endif
endfunction

function set_item_player takes  returns nothing
local unit u=GetTriggerUnit()
local item i=GetManipulatedItem()
call SetItemPlayer(I,GetPlayerId(GetOwningPlayer(U))
set u=null
set i=null
endfunction
 
function trigger_item_pickup takes nothing returns nothing
set t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition(t,Condition(function item_is_in_pool))
call TriggerAddAction(t,function set_item_player)
set t=null
endfunction

This is my first trigger and I have no clue why its not working
 
Last edited:
Level 2
Joined
Dec 14, 2012
Messages
20
I've been thinking about that Blizzard Function too but it seems did not work for me, therefore I created a system Item Bound (Signature) - however it's in GUI.

Wait, what you're trying to do exactly ?
And what's the "not working" part ?
Specify.

I got a unit that drops a item but this item being drop belongs to that player .. now if this unit picks up that item and that item is say 'I909' it should change the itemowner to the guy who picked it up
 
Level 6
Joined
Nov 24, 2012
Messages
218
I'm very new to jass too but here would be my take on it:
JASS:
function item_is_in_pool takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == 'I06B' 
endfunction

function set_item_player takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local item i=GetManipulatedItem()
    call SetItemPlayer(i, GetOwningPlayer(u), true)
    // true changes item color, but I don't get why item color would change
    // fixed the trigger, but this here is likely not work like defskull said
    set u=null
    set i=null
endfunction
 
function InitTrig_item_pickup takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t,Condition(function item_is_in_pool))
    call TriggerAddAction(t,function set_item_player)
    set t=null
endfunction
Assuming the trigger name is "item pickup"
Edit: woops, here it is.
Edit2: nvm, u have some wrong functions, 1 min, gotta fix mines too
Edit3: tested, trigger works, Item ownership doesn't. I have an item ownership code in gui in one of my maps, 1 min.
 
Last edited:
Level 2
Joined
Dec 14, 2012
Messages
20
I'm very new to jass too but here would be my take on it:
JASS:
function item_is_in_pool takes nothing returns boolean
return GetItemTypeId(GetManipulatedItem()) == 'I06B' 
endfunction

function set_item_player takes nothing returns nothing
local unit u=GetTriggerUnit()
local item i=GetManipulatedItem()
call SetItemPlayer(I,GetPlayerId(GetOwningPlayer(U))
set u=null
set i=null
endfunction
 
function InitTrig_item_pickup takes nothing returns nothing
local trigger t=CreateTrigger()
call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
call TriggerAddCondition(t,Condition(function item_is_in_pool))
call TriggerAddAction(t,function set_item_player)
set t=null
endfunction
Assuming the trigger name is "item pickup"
Edit: woops, here it is.
Edit2: nvm, u have some wrong functions, 1 min, gotta fix mines too

can i ask some thing is the InitTrig_ infront of the itempickup for a reason? or is it just a name.. i am really noob at this
 
Level 2
Joined
Dec 14, 2012
Messages
20
I don't know? I just started Jass like yesterday.
It's like that by standard conversion.
Only that init function needs it if it is necessary.
If you want items bound by ownership, one minute, working something.

thanks hey would help me so much
 
Level 6
Joined
Nov 24, 2012
Messages
218
Well, this is my second jass script I ever wrote. Sort of. Not really, since ¾ of it is yours.
Fun stuff. Liking it more than GUI already, damn why did I stick with GUI for 6 years
(and refused to learn hashtables + timers, all I know is arrays lmao).
JASS:
function item_is_in_pool takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == 'I06B'
    /*************************************************************************************
    replace the above line with 
    return GetItemType(GetManipulatedItem()) != ITEM_TYPE_PURCHASABLE 
    if you want all items bounded except for items of purchasable class 
    or something like
    return GetItemTypeId(GetManipulatedItem()) == 'xxxx' or GetItemTypeId(GetManipulatedItem()) == 'xxxx'
    if you want to bound only 2 item types, etc
    *************************************************************************************/
endfunction

function set_item_player takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local item i=GetManipulatedItem()
    local force f=GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit()))
    if (GetItemUserData(i) == 0) then 
        call SetItemUserData(i, GetConvertedPlayerId(GetOwningPlayer(u)))
    endif
    if (GetItemUserData(i) != GetConvertedPlayerId(GetOwningPlayer(u))) then
        call UnitRemoveItemSwapped( GetManipulatedItem(), GetTriggerUnit())
        call DisplayTextToForce(f, "This item belongs to " + GetPlayerName(ConvertedPlayer(GetItemUserData(i))))
    endif
    set u=null
    set i=null
    set f=null
endfunction
 
function InitTrig_item_pickup takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t,Condition(function item_is_in_pool))
    call TriggerAddAction(t,function set_item_player)
    set t=null
endfunction
Trigger name: item pickup
What it does: items bound by player, gives message of who owner is if other player tries to pick.

EDIT: I did this by setting Item Custom Value to Player # of manipulator. Just thought you'd need to know in case you ever want to edit it.
 
Last edited:
Level 2
Joined
Dec 14, 2012
Messages
20
Well, this is my second jass script I ever wrote. Sort of. Not really, since ¾ of it is yours.
Fun stuff. Liking it more than GUI already, damn why did I stick with GUI for 6 years
(and refused to learn hashtables + timers, all I know is arrays lmao).
JASS:
function item_is_in_pool takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == 'I06B'
    /*************************************************************************************
    replace the above line with 
    return GetItemType(GetManipulatedItem()) != ITEM_TYPE_PURCHASABLE 
    if you want all items bounded except for items of purchasable class 
    or something like
    return GetItemTypeId(GetManipulatedItem()) == 'xxxx' or GetItemTypeId(GetManipulatedItem()) == 'xxxx'
    if you want to bound only 2 item types, etc
    *************************************************************************************/
endfunction

function set_item_player takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local item i=GetManipulatedItem()
    local force f=GetForceOfPlayer(GetOwningPlayer(GetTriggerUnit()))
    if (GetItemUserData(i) == 0) then 
        call SetItemUserData(i, GetConvertedPlayerId(GetOwningPlayer(u)))
    endif
    if (GetItemUserData(i) != GetConvertedPlayerId(GetOwningPlayer(u))) then
        call UnitRemoveItemSwapped( GetManipulatedItem(), GetTriggerUnit())
        call DisplayTextToForce(f, "This item belongs to " + GetPlayerName(ConvertedPlayer(GetItemUserData(i))))
    endif
    set u=null
    set i=null
    set f=null
endfunction
 
function InitTrig_item_pickup takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t,Condition(function item_is_in_pool))
    call TriggerAddAction(t,function set_item_player)
    set t=null
endfunction
Trigger name: item pickup
What it does: items bound by player, gives message of who owner is if other player tries to pick.

EDIT: I did this by setting Item Custom Value to Player # of manipulator. Just thought you'd need to know in case you ever want to edit it.

thanks man so much hey!! i am gonna pm u to ask u a fav
 
Level 37
Joined
Mar 6, 2006
Messages
9,243
JASS:
function item_is_in_pool takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == 'I06B'
    /*************************************************************************************
    replace the above line with 
    return GetItemType(GetManipulatedItem()) != ITEM_TYPE_PURCHASABLE 
    if you want all items bounded except for items of purchasable class 
    or something like
    return GetItemTypeId(GetManipulatedItem()) == 'xxxx' or GetItemTypeId(GetManipulatedItem()) == 'xxxx'
    if you want to bound only 2 item types, etc
    *************************************************************************************/
endfunction

function set_item_player takes nothing returns nothing
    local unit u=GetTriggerUnit()
    local item i=GetManipulatedItem()
    if GetItemUserData(i) == 0 then 
        call SetItemUserData(i, GetPlayerId(GetOwningPlayer(u))+1)
    endif
    if GetItemUserData(i) != GetPlayerId(GetOwningPlayer(u))+1 then
        call UnitRemoveItem(u, GetManipulatedItem())
        call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 5, "This item belongs to " + GetPlayerName(Player(GetItemUserData(i))))
    endif
    set u=null
    set i=null
endfunction
 
function InitTrig_item_pickup takes nothing returns nothing
    local trigger t=CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t,Condition(function item_is_in_pool))
    call TriggerAddAction(t,function set_item_player)
    set t=null
endfunction

Some edits to HesitationSnow's code.
 
Status
Not open for further replies.
Top