How can I restrict items of type of being carried ?

marvey323

Member
Reaction score
1
I want to make it so heroes can only pick up only 1 of a type of item. If they try to pick up another it just drops it on the ground.
 

Exide

I am amazingly focused right now!
Reaction score
448
I made one of those triggers in JASS, once.
Works like this:
A Hero can only have 1 item of each type 'armor', 'weapon', and 'shield' (you can rename them if you like.) If a hero acquires another weapon, armor or shield, it's dropped to the ground and a message is displayed.

JASS:

function Trig_Special_Items_Actions takes nothing returns nothing
    local force playzor = CreateForce()
    local item newitem = GetManipulatedItem()
    local integer loopnr = 0
    
    
    call ForceAddPlayer(playzor, GetOwningPlayer(GetTriggerUnit()))
    
    if ( GetItemType(newitem) == ITEM_TYPE_ARTIFACT ) then
        
        loop
            exitwhen loopnr >= 6
            if ( GetItemType(UnitItemInSlot(GetTriggerUnit(), loopnr)) == ITEM_TYPE_ARTIFACT ) and (UnitItemInSlot(GetTriggerUnit(), loopnr) != GetManipulatedItem()) then
                
                call QuestMessageBJ( playzor, bj_QUESTMESSAGE_UPDATED, "You are already wielding a Weapon!" )
                call UnitRemoveItem( GetTriggerUnit(), newitem )
                
            endif
            set loopnr = (loopnr + 1)
        endloop
        
    endif


    if ( GetItemType(newitem) == ITEM_TYPE_PERMANENT ) then
        
        loop
            exitwhen loopnr >= 6
            if ( GetItemType(UnitItemInSlot(GetTriggerUnit(), loopnr)) == ITEM_TYPE_PERMANENT ) and (UnitItemInSlot(GetTriggerUnit(), loopnr) != GetManipulatedItem()) then
                
                call QuestMessageBJ( playzor, bj_QUESTMESSAGE_UPDATED, "You are already carrying a Shield!" )
                call UnitRemoveItem( GetTriggerUnit(), newitem )
                
            endif
            set loopnr = (loopnr + 1)
        endloop
        
    endif
    
    
    if ( GetItemType(newitem) == ITEM_TYPE_CAMPAIGN ) then
        
        loop
            exitwhen loopnr >= 6
            if ( GetItemType(UnitItemInSlot(GetTriggerUnit(), loopnr)) == ITEM_TYPE_CAMPAIGN ) and (UnitItemInSlot(GetTriggerUnit(), loopnr) != GetManipulatedItem()) then
                
                call QuestMessageBJ( playzor, bj_QUESTMESSAGE_UPDATED, "You are already wearing an Armor!" )
                call UnitRemoveItem( GetTriggerUnit(), newitem )
                
            endif
            set loopnr = (loopnr + 1)
        endloop
        
    endif

    
    call DestroyForce(playzor)
    set playzor = null
    set newitem = null
endfunction

//===========================================================================
function InitTrig_Special_Items takes nothing returns nothing
    local trigger gg_trg_Special_Items = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Special_Items, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Special_Items, function Trig_Special_Items_Actions )
endfunction


Artifact = Weapon
Permanent = Shield
Campaign = Armor
 

marvey323

Member
Reaction score
1
Thanks man !

Would it be possible to allow certain classes to wear two of a kind and so on? (like 2 swords, etc).
 

lindenkron

You can change this now in User CP
Reaction score
102
Trigger:
  • AmmunitionAcquire
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to Hollow-point Bullets
          • (Item-type of (Item being manipulated)) Equal to Steel Bullets
          • (Item-type of (Item being manipulated)) Equal to Split Bullets
    • Actions
      • Set Ammunition[(Player number of (Owner of (Hero manipulating item)))] = (Ammunition[(Player number of (Owner of (Hero manipulating item)))] + 1)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Ammunition[(Player number of (Owner of (Hero manipulating item)))] Greater than 1
        • Then - Actions
          • Hero - Drop (Item being manipulated) from (Hero manipulating item)
        • Else - Actions
          • Unit - Order (Triggering unit) to move (Item being manipulated) to inventory slot 1


Trigger:
  • AmmunitionDrop
    • Events
      • Unit - A unit Loses an item
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Item-type of (Item being manipulated)) Equal to Hollow-point Bullets
          • (Item-type of (Item being manipulated)) Equal to Steel Bullets
          • (Item-type of (Item being manipulated)) Equal to Split Bullets
    • Actions
      • Set Ammunition[(Player number of (Owner of (Hero manipulating item)))] = (Ammunition[(Player number of (Owner of (Hero manipulating item)))] - 1)


This is what I used in one of my maps. Need 2 triggers for each "type" of item you would like. Like: 2 for shield. 2 for sword. 2 for armor. Etc Etc.

-Lindenkron

Edit:
Damn you beat me to it Exide :p
 

marvey323

Member
Reaction score
1
So, in my ORPG where there will be about 1000 different items per class, i need to make 1000 different variables with 2000 different triggers to hold everything ?
 

marvey323

Member
Reaction score
1
Thank Exide it works just fine. I didn't realize I had to name my trigger "Special Items' or change it in your trigger. I'm horrid at JASS.
 

marvey323

Member
Reaction score
1
Exide, your trigger doeosn't work.

I've placed an item named 'Sword' in ARTIFACT category but I'm able to have more than one in-game.

Uh I just realized that I need to create variables?

If so can you tell me which ones (I'm poor at JASS).
 

Firezy

New Member
Reaction score
14
Trigger:
  • Main hand
    • Events
      • Unit - A unit Acquires an item
    • Conditions
      • (Item-class of (Item being manipulated)) Equal to Campaign
    • Actions
      • Unit - Order (Hero manipulating item) to move (Item being manipulated) to inventory slot 1
      • Wait 0.01 seconds
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Or - Any (Conditions) are true
            • Conditions
              • (Item-class of (Item carried by (Hero manipulating item) in slot 2)) Equal to Campaign
              • (Item-class of (Item carried by (Hero manipulating item) in slot 3)) Equal to Campaign
              • (Item-class of (Item carried by (Hero manipulating item) in slot 4)) Equal to Campaign
              • (Item-class of (Item carried by (Hero manipulating item) in slot 5)) Equal to Campaign
              • (Item-class of (Item carried by (Hero manipulating item) in slot 6)) Equal to Campaign
        • Then - Actions
          • Hero - Drop (Item being manipulated) from (Hero manipulating item)
          • Game - Display to (Player group((Owner of (Hero manipulating item)))) the text: (colorGold + You may only wield one weapon!)
        • Else - Actions


Since theres only 7 categories I suggest making this for your class Ie weapon, armor etc.
and then another system if you wanna make sub class IE. weapon sword weapon blunt etc.
 

Exide

I am amazingly focused right now!
Reaction score
448
I made a map with only the trigger in it. -All you need to do is to open both maps, copy my trigger into your map, and then save your map.

Also make sure that your items has the right classification.
Artifact = Weapon
Permanent = Shield
Campaign = Armor

Map attached.
 

Attachments

  • Special Items.w3x
    17.7 KB · Views: 159

lindenkron

You can change this now in User CP
Reaction score
102
So, in my ORPG where there will be about 1000 different items per class, i need to make 1000 different variables with 2000 different triggers to hold everything ?

No, read what I wrote.

You don't have 1000 different -ITEM TYPES- ;).

Like:
Sword,
Armor,
Shield,
Necklace.

I don't mean 2 triggers for EACH sword. Read the trigger, you add all swords to them 2 triggers.
Code:
    Or - Any (Conditions) are true
          Conditions
                (Item-type of (Item being manipulated)) Equal to Sword of pwnage
                (Item-type of (Item being manipulated)) Equal to Sword of a thousand thruths
                (Item-type of (Item being manipulated)) Equal to Sword of another sword



So all in all you might need 10 triggers for all your items (Lets say you got chest, sword, shield, necklace, helmet).

Anyway. It's the best GUI solution if you ask me, but do as you please ;)

-Lindenkron
 

TAIL

New Member
Reaction score
0
Exide, if i want to add a new class like power up or charged what should i add to your jass script ?
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top