• 🏆 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 class JASS trigger

Status
Not open for further replies.
Level 7
Joined
Mar 5, 2009
Messages
254
I need trigger in jass for this function = Every unit can pick only 1 item class ( etc. permanent ) if he already have 1 permanent class item and picks another 1.The second one will be dropped. Do u understand now ?
 
Level 6
Joined
Oct 10, 2009
Messages
1,425
well, i tried other ways, but this seemed the only solution and it worked :) so here you go.

JASS:
function Trig_Untitled_Trigger_002_Conditions takes nothing returns boolean
    if ( not ( GetItemType(GetManipulatedItem()) == ITEM_TYPE_PERMANENT)) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_002_Func001C takes nothing returns boolean
    if ( not ( GetUnitUserData(GetManipulatingUnit()) == 1)) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    if ( Trig_Untitled_Trigger_002_Func001C() ) then
        call UnitRemoveItem(GetManipulatingUnit(),GetManipulatedItem())
    else
    endif
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_002 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_002, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_002, Condition( function Trig_Untitled_Trigger_002_Conditions ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_002, function Trig_Untitled_Trigger_002_Actions )
endfunction
JASS:
function Trig_Untitled_Trigger_003_Conditions takes nothing returns boolean
    if ( not ( GetItemType(GetManipulatedItem()) == ITEM_TYPE_PERMANENT)) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_003_Func001C takes nothing returns boolean
    if ( not ( GetUnitUserData(GetManipulatingUnit()) == 0)) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_003_Actions takes nothing returns nothing
    if ( Trig_Untitled_Trigger_003_Func001C()) then
        call SetUnitUserData( GetManipulatingUnit(), 1)
    else
    endif
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_003 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_003 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_003, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_003, Condition( function Trig_Untitled_Trigger_003_Conditions ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_003, function Trig_Untitled_Trigger_003_Actions )
endfunction
JASS:
function Trig_Untitled_Trigger_004_Conditions takes nothing returns boolean
    if ( not ( GetItemType(GetManipulatedItem()) == ITEM_TYPE_PERMANENT)) then
        return false
    endif
    return true
endfunction

function Trig_Untitled_Trigger_004_Actions takes nothing returns nothing
    call SetUnitUserData( GetManipulatingUnit(),0)
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_004 takes nothing returns nothing
    set gg_trg_Untitled_Trigger_004 = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Untitled_Trigger_004, EVENT_PLAYER_UNIT_DROP_ITEM )
    call TriggerAddCondition( gg_trg_Untitled_Trigger_004, Condition( function Trig_Untitled_Trigger_004_Conditions ) )
    call TriggerAddAction( gg_trg_Untitled_Trigger_004, function Trig_Untitled_Trigger_004_Actions )
endfunction

if you need explanations just ask :) Demo Map Below :)
View attachment aaa.w3m
 
Level 6
Joined
Oct 10, 2009
Messages
1,425
Can you make for other 5 item classes too please ? +rep for this

ahh well if you have basic jassing knowledge you could do it as well:p i need sleep now and those triggers would take awhile, I'll probably be back on at noon tomorrow if you're willing to wait :)

EDIT which item classes are the others:?
EDIT2 thanks for the rep :grin:
 
Level 14
Joined
Nov 18, 2007
Messages
1,084
JASS:
function Trig_ItemClassLimit_Actions takes nothing returns boolean
    local unit u = GetTriggerUnit() //GetTriggerUnit() is same as GetManipulatingUnit()
    local item i = GetManipulatedItem()
    local item check
    local itemtype itype = GetItemType(i)
    local integer index = 0
    local boolean b = false
    if itype == ITEM_TYPE_PERMANENT or itype == ITEM_TYPE_CHARGED or itype == ITEM_TYPE_ARTIFACT or itype == ITEM_TYPE_POWERUP or itype == ITEM_TYPE_CAMPAIGN or itype == ITEM_TYPE_PURCHASABLE  then //We'll check if the item meets a certain type. Done this way since it seemed to bug if you checked if the item wasn't ITEM_TYPE_MISCELLANEOUS.
        loop
            set check = UnitItemInSlot(u,index)
            if GetItemType(check) == itype and i != check  then
                call UnitDropItemPoint(u,i,GetUnitX(u),GetUnitY(u))
                call DisplayTextToPlayer(GetOwningPlayer(u),0,0,"Can't have more than one item of the same class!")
                set b = true
            endif
            set index = index + 1
            exitwhen index == 6 or b
        endloop
    endif
    set u = null
    set i = null
    set check = null
    return false
endfunction

//===========================================================================
function InitTrig_ItemClassLimit takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
    call TriggerAddCondition(t,Condition(function Trig_ItemClassLimit_Actions))
endfunction
If you don't understand something don't hesitate to ask.

Edit: Attached a test map. Did not add power up items to test since they're gone once you acquire them. Amulet of Recall is there to show that items of type Miscellaneous aren't affected by the trigger.
 

Attachments

  • ItemClassLimitTestMap.w3x
    17.1 KB · Views: 96

Bribe

Code Moderator
Level 50
Joined
Sep 26, 2009
Messages
9,467
Need: a variable (hashtable) entitled "hash"
This is all done in one trigger.

JASS:
//
// Check Class of Item
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
   function ItemClassCheck takes nothing returns boolean
       local integer id = GetItemType(GetManipulatedItem())
       local integer data = LoadInteger(udg_hash,GetPlayerId(GetTriggerPlayer()),1)
       
       if id == ITEM_TYPE_PERMANENT and data != 1 then
           call UnitRemoveItem(GetTriggerUnit(),GetManipulatedItem())
           
       elseif id = ITEM_TYPE_ARTIFACT and data != 2 then
           call UnitRemoveItem(GetTriggerUnit(),GetManipulatedItem())
           
       elseif id = ITEM_TYPE_PURCHASABLE and data != 3 then
           call UnitRemoveItem(GetTriggerUnit(),GetManipulatedItem())
           
       elseif id = ITEM_TYPE_CAMPAIGN and data != 4 then
           call UnitRemoveItem(GetTriggerUnit(),GetManipulatedItem())
           
       elseif id = ITEM_TYPE_CHARGED and data != 5 then
           call UnitRemoveItem(GetTriggerUnit(),GetManipulatedItem())
           
       //elseif id = ITEM_TYPE_POWERUP then     <<- How do you plan to stop him collecting powerups?
       endif
       return false
   endfunction
//
// Player Types: "item class (Something)"
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
   function ChooseItemClass takes nothing returns boolean
       local integer id = GetPlayerId(GetTriggerPlayer())
       local string s
       if not LoadBoolean(udg_hash,id,0) then
           set s = GetEventPlayerChatString()
           
           if s == "item class permanent" then
               call SaveInteger(udg_hash,id,1,1)
               call SaveBoolean(udg_hash,id,0,true)
               
           elseif s == "item class artifact" then
               call SaveInteger(udg_hash,id,1,2)
               call SaveBoolean(udg_hash,id,0,true)
               
           elseif s == "item class purchasable" then
               call SaveInteger(udg_hash,id,1,3)
               call SaveBoolean(udg_hash,id,0,true)
               
           elseif s == "item class campaign" then
               call SaveInteger(udg_hash,id,1,4)
               call SaveBoolean(udg_hash,id,0,true)
               
           elseif s == "item class charged" then
               call SaveInteger(udg_hash,id,1,5)
               call SaveBoolean(udg_hash,id,0,true)
           endif
       endif
       
       return false
   endfunction
//
// Initializer
// ¯¯¯¯¯¯¯¯¯¯¯
   function InitTrig_ItemChecker takes nothing returns nothing
       local integer i = 0
       local trigger t = CreateTrigger()
       local player p
       call TriggerAddCondition(t,Condition(function ChooseItemClass))
       
       loop
           set p = Player(i)
           if GetPlayerSlotState(p) == PLAYER_SLOT_STATE_PLAYING then
               call SaveBoolean(udg_hash,i,0,false)
               
               call TriggerRegisterPlayerChatEvent(t,p,"item class permanent",true)
               call TriggerRegisterPlayerChatEvent(t,p,"item class artifact",true)
               call TriggerRegisterPlayerChatEvent(t,p,"item class purchasable",true)
               call TriggerRegisterPlayerChatEvent(t,p,"item class campaign",true)
               call TriggerRegisterPlayerChatEvent(t,p,"item class charged",true)
               
           endif
           exitwhen i == 11
           set i = i +1
       endloop
       
       set t = CreateTrigger()
       call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_PICKUP_ITEM)
       call TriggerAddCondition(t,Condition(function ItemClassCheck))
   endfunction
 
Status
Not open for further replies.
Top