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

Non Shearable Items

Status
Not open for further replies.
Level 4
Joined
Aug 1, 2013
Messages
54
How do i make a trigger where items owned by heroes cannot be gave to the ally heroes (with exception if the item is a reagent with no stats) or the enemy heroes (even if the item is a reagent can't be taken), or taken by someone after they drop it down except the owner?

Help would be greatly appreciated :thumbs_up:
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
A simple approach is to use two natives which set an integer flag for an item. You set the flag whenever a hero picks up the item to their player id. e.g. Player 1 acquires a Sobi Mask, set the item user data to 0(=GetPlayerId(Player(0))).

Then, whenever a hero picks up an item, you check to its item user data value. If the value doesn't match the player's id number, order the hero to immediately drop it.

It will look something like this (note this library won't work out of the box, it's just an example):

JASS:
library ItemProtect initializer init requires Colors, PlayerFilters

globals
    constant integer LOOTABLE = 0 //if an item can be taken
    constant string MSG = RED + "Error:|r" + SILVER + " This item does not belong to you!"
    constant string MSG2 = RED + "Error:|r" + SILVER + " Monster Masters cannot use Monster items!"
    constant string MSG3 = RED + "Error:|r" + SILVER + " Monsters cannot use Monster Master items!"
endglobals

function isLoot takes item i, integer pid returns boolean
    return(GetItemUserData(i) == LOOTABLE or GetItemUserData(i) == pid + 1)
endfunction



private function main takes nothing returns boolean
	local player p = GetTriggerPlayer()
    local integer pid = GetPlayerId(p)
    local item i = GetManipulatedItem()
    local unit u = GetManipulatingUnit()
    local integer ownerId = GetItemUserData(i)
	local integer itemType = GetItemLevel(i)
	
    if isLoot(i, pid) then //check if the item is loot: belongs to the player or is unclaimed
		if u == playerDatum[pid].pc.u then //is it a player/quest item?
			if itemType == PLAYER_ITEM or itemType == QUEST_ITEM then
				call SetItemUserData(i, pid + 1)
			else
				call UnitRemoveItem(u, i)
				call DisplayTimedTextToPlayer(p, 0, 0, 10, MSG2)
				if GetLocalPlayer() == p then
					call StartSound(gg_snd_Error)
				endif
			endif
		else //is it a monster item?
			if itemType == MONSTER_ITEM then
				call SetItemUserData(i, pid + 1)
			else
				call UnitRemoveItem(u, i)
				call DisplayTimedTextToPlayer(p, 0, 0, 10, MSG3)
				if GetLocalPlayer() == p then
					call StartSound(gg_snd_Error)
				endif
			endif
		endif
    else
        set u = GetManipulatingUnit()
        call UnitRemoveItem(u, i)
        call DisplayTimedTextToPlayer(p, 0, 0, 10, MSG)
        if GetLocalPlayer() == p then
            call StartSound(gg_snd_Error)
        endif
    endif
    return false
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t, Condition(function main))
endfunction
endlibrary
 
Level 4
Joined
Aug 1, 2013
Messages
54
A simple approach is to use two natives which set an integer flag for an item. You set the flag whenever a hero picks up the item to their player id. e.g. Player 1 acquires a Sobi Mask, set the item user data to 0(=GetPlayerId(Player(0))).

Then, whenever a hero picks up an item, you check to its item user data value. If the value doesn't match the player's id number, order the hero to immediately drop it.

It will look something like this (note this library won't work out of the box, it's just an example):

JASS:
library ItemProtect initializer init requires Colors, PlayerFilters

globals
    constant integer LOOTABLE = 0 //if an item can be taken
    constant string MSG = RED + "Error:|r" + SILVER + " This item does not belong to you!"
    constant string MSG2 = RED + "Error:|r" + SILVER + " Monster Masters cannot use Monster items!"
    constant string MSG3 = RED + "Error:|r" + SILVER + " Monsters cannot use Monster Master items!"
endglobals

function isLoot takes item i, integer pid returns boolean
    return(GetItemUserData(i) == LOOTABLE or GetItemUserData(i) == pid + 1)
endfunction



private function main takes nothing returns boolean
	local player p = GetTriggerPlayer()
    local integer pid = GetPlayerId(p)
    local item i = GetManipulatedItem()
    local unit u = GetManipulatingUnit()
    local integer ownerId = GetItemUserData(i)
	local integer itemType = GetItemLevel(i)
	
    if isLoot(i, pid) then //check if the item is loot: belongs to the player or is unclaimed
		if u == playerDatum[pid].pc.u then //is it a player/quest item?
			if itemType == PLAYER_ITEM or itemType == QUEST_ITEM then
				call SetItemUserData(i, pid + 1)
			else
				call UnitRemoveItem(u, i)
				call DisplayTimedTextToPlayer(p, 0, 0, 10, MSG2)
				if GetLocalPlayer() == p then
					call StartSound(gg_snd_Error)
				endif
			endif
		else //is it a monster item?
			if itemType == MONSTER_ITEM then
				call SetItemUserData(i, pid + 1)
			else
				call UnitRemoveItem(u, i)
				call DisplayTimedTextToPlayer(p, 0, 0, 10, MSG3)
				if GetLocalPlayer() == p then
					call StartSound(gg_snd_Error)
				endif
			endif
		endif
    else
        set u = GetManipulatingUnit()
        call UnitRemoveItem(u, i)
        call DisplayTimedTextToPlayer(p, 0, 0, 10, MSG)
        if GetLocalPlayer() == p then
            call StartSound(gg_snd_Error)
        endif
    endif
    return false
endfunction

private function init takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t, Condition(function main))
endfunction
endlibrary

Is it possible to make it not to be in jazz because i don't really get it in jazz :(
 

Chaosy

Tutorial Reviewer
Level 40
Joined
Jun 9, 2011
Messages
13,219
  • Untitled Trigger 001
    • Events
      • Unit - A unit Acquires an item
    • Conditions
    • Actions
      • Set integer_variable = (Custom value of (Item being manipulated))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • integer_variable Equal to (Player number of (Owner of (Triggering unit)))
        • Then - Actions
          • -------- the unit can pick up the item --------
        • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • integer_variable Equal to 0
            • Then - Actions
              • -------- no one owns the item --------
              • Item - Set the custom value of (Item being manipulated) to (Player number of (Owner of (Triggering unit)))
            • Else - Actions
              • -------- player doesn't own the item --------
              • Hero - Drop (Item being manipulated) from (Triggering unit)
nice and simple.
 
Status
Not open for further replies.
Top