• 🏆 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!

[General] Inventory Item-types Lock

Status
Not open for further replies.
Level 4
Joined
Dec 31, 2014
Messages
68
Hello All,

Right I have made an RPG map that has custom Weapons, Armor and Shields. What I am wanting to do is to somehow lock the inventory so that the player can only have 1 of these in their inventory at the same time.
(i.e Not allow the player to equip 2 swords, 2 shields etc)

I would like the first 3 slots in lockdown for them 3 item types but then have the remaining 3 slots free that the player can fill with healing or other items.

I'm unsure if this is trigger work or Item work but could you guys help me here, or provide a link to a tutorial?

Thanks
 
Level 5
Joined
Jan 18, 2012
Messages
92
Just came to the forums to ask a similiar thing. I made a little JASS script that should drop an item from the inventory if there is already one of the same class in it. It is supposed to do that with Artifact and Campaign classes.

JASS:
function manageItems takes nothing returns nothing
    local integer i = 0
    local unit triggerer = GetTriggerUnit()
    
    if GetItemType(GetManipulatedItem()) == ITEM_TYPE_ARTIFACT then
        loop
            if GetItemType(UnitItemInSlot(triggerer, i)) == ITEM_TYPE_ARTIFACT then
                call UnitRemoveItem(triggerer, GetManipulatedItem())
                call DisplayTextToPlayer(GetOwningPlayer(triggerer), 0.0, 0.0, GetUnitName(triggerer) + " can only carry one weapon.")
            endif
            
            set i = i + 1
            exitwhen i >= bj_MAX_INVENTORY
        endloop
    elseif GetItemType(GetManipulatedItem()) == ITEM_TYPE_CAMPAIGN then
        loop
            if GetItemType(UnitItemInSlot(triggerer, i)) == ITEM_TYPE_CAMPAIGN then
                call UnitRemoveItem(triggerer, GetManipulatedItem())
                call DisplayTextToPlayer(GetOwningPlayer(triggerer), 0.0, 0.0, GetUnitName(triggerer) + " can only carry one shield.")
            endif
            
            set i = i + 1
            exitwhen i >= bj_MAX_INVENTORY
        endloop
    endif
    
    set triggerer = null
endfunction

//===========================================================================
function InitTrig_Item_Managment takes nothing returns nothing
    local trigger itemManagment = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( itemManagment, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( itemManagment, function manageItems )
endfunction

But, sadly, lines 8 and 9(if I comment out line number 8) give a syntax error which I can't figure out.

I would like the first 3 slots in lockdown for them 3 item types but then have the remaining 3 slots free that the player can fill with healing or other items.

There is this function in JASS -
JASS:
UnitAddItemToSlotById
. You can then use it when a unit gets an item remove it and add it to the slot you want. You can also make a loop to go through the last three slots.
You would also need a trigger that runs every 0.03 seconds or whatever to check if there is an weapon or armor in the first three slots and then either remove them and inform the player that they can't put a weapon or armor in the first three slots or if one of the last three slots is free remove the item and add it again in one of the three slots.
 
Level 4
Joined
Dec 31, 2014
Messages
68
Errr, I don't actually understand anything about JASS - would that be the only way or is there something with the GUI I could do?
 
Level 4
Joined
Dec 31, 2014
Messages
68
I've been trying that tutorial out but I'm not having much luck.
I am using custom items which from experimentation don't seem to work with this system, does anyone know how I could work around this?
(Iv sent a private message to the creator also but I thought id ask here as well)

I am viewing my custom items as raw data which display like 'l020:ratc' which I have tried to type into the RegisterRestrictedItem sections. When saving/testing the map throws me a script error 'Expected a valid argument list'.
I have tried 'l020' by itself which stops the script error appearing but doesn't do it as It looks like its referencing the original item. 'ratc' also doesn't work.
 
Level 4
Joined
Dec 31, 2014
Messages
68
Oh right ok,
Yeah the custom script I was trying was ;
  • Custom script: call IRS_RegisterRestrictedItem ('ratc', "Weapon", null, 0, 0, 0, 0, 0)
(also I'v noticed that if I only use the suffix part of the raw code, I have 2 items which have the same 'ratc' in them, so how could this work? :/)

It seems to get past that script error but it simply doesn't work in-game.
 
Level 4
Joined
Dec 31, 2014
Messages
68
note: As I only need it so that a unit cannot carry 2 of the same type of weapon and all my Heroes are melee characters I made it 0,0,0,0,0 on the custom script, I assume this is correct?
 
Status
Not open for further replies.
Top