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

[Solved] strange hashtable problem

Status
Not open for further replies.
Level 9
Joined
Jul 10, 2011
Messages
562
okay Spartipilo...first thanks for your work :D it really helped me ^.^

now what i did with your help....it now works perfectly for my purpose even if the item picked up occupies the slot it should be in. You can take a look and tell me whether i should change something because it could cause bugs or whatever.

JASS:
function Trig_Hero_and_Item_List_Actions takes nothing returns nothing

set udg_ItemRestrictionTable = InitHashtable()

//                             | Table |      ItemID | 000 | ItemClass |
    call SaveInteger(udg_ItemRestrictionTable, 'ofro',   0,       1) // Item 1
    call TriggerSleepAction(0.25) // Add one of these every 10 actions.
    // and so on...

//                  | Table |                  Hero ID | item Class | If forbidden = true |
// Hero 1
    call SaveBoolean(udg_ItemRestrictionTable, 'H02Q',   1,             true)
    call SaveBoolean(udg_ItemRestrictionTable, 'H00F',   1,             false)
    
    // and so on...

endfunction

//===========================================================================
function InitTrig_Hero_and_Item_List takes nothing returns nothing
    set gg_trg_Hero_and_Item_List = CreateTrigger(  )
    call TriggerRegisterTimerEvent( gg_trg_Hero_and_Item_List, 1.00, false )
    call TriggerAddAction( gg_trg_Hero_and_Item_List, function Trig_Hero_and_Item_List_Actions )
endfunction

and im really proud of this trigger ^-^ especially because my jass knowledge is really small ^^

JASS:
function Item_Acquire_Actions takes nothing returns nothing

    local unit u = GetTriggerUnit()
    local item i = (GetManipulatedItem())
    local integer lvl = GetItemLevel(i)
    local integer ItemClass = LoadInteger(udg_ItemRestrictionTable, GetItemTypeId(i), 0)
    local item i2 = UnitItemInSlot(u, lvl-1)
    local item i3 = UnitItemInSlot(u, lvl)
    local boolean b = false

    if GetUnitTypeId(u) == 'H02B' or GetUnitTypeId (u) == 'H015' or GetUnitTypeId (u) == 'H029' or GetUnitTypeId (u) == 'H00R' then
        set b = true
    endif
    
    if LoadBoolean(udg_ItemRestrictionTable, GetUnitTypeId(u),ItemClass ) == true then // Checks if the Acquired Item is Useable by the Unit
    // Drops the item and Displays Message
        call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 10, "You can't carry this item.")
        call UnitRemoveItem(u, i)
        call SetItemUserData(i, 0 )
        if GetItemLevel(UnitItemInSlot(u, 0)) == null then
            call UnitRemoveItem(u , GetItemOfTypeFromUnitBJ (u , 'I001'))
        endif   
        
    elseif b == true and lvl == 1 then
            if i2 == null or i2 == i then // Checks if the Item Slot is Empty or the Item in the slot is the desired item.
            call  IssueTargetOrderById(u, 852001+lvl, i) // Moves the Item to the correct Slot
            elseif i3 == null or i3 == i then
                call IssueTargetOrderById(u, 852001+lvl+1, i)
                else
                    call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 10, "Needed slot is already occupied.")
                    call UnitRemoveItem(u, i)
                    call SetItemUserData(i, 0 )
                    if GetItemLevel(UnitItemInSlot(u, 0)) == null then
                        call UnitRemoveItem(u , GetItemOfTypeFromUnitBJ (u , 'I001'))
                    endif 
                endif
        elseif b == false then
    // Drops the item and Displays Message
                if i2 == null or i2 == i then
                    call  IssueTargetOrderById(u, 852001+lvl, i)
                    if ItemClass <= 8 and GetItemTypeId(i) != 'I001' then
                        call UnitAddItemToSlotById(u,'I001',1)
                    endif
                else
                    call DisplayTimedTextToPlayer(GetTriggerPlayer(), 0, 0, 10, "Needed slot is already occupied.")
                    call UnitRemoveItem(u, i)
                    call SetItemUserData(i, 0 )
                    if GetItemLevel(UnitItemInSlot(u, 0)) == null then
                        call UnitRemoveItem(u , GetItemOfTypeFromUnitBJ (u , 'I001'))
                    endif
                endif
    endif

    set u = null
    set i = null
    set i2 = null
    set i3 = null
    set b = false
    
endfunction

//===========================================================================
function InitTrig_Item_Acquire takes nothing returns nothing
    set gg_trg_Item_Acquire = CreateTrigger(  )
    call TriggerRegisterAnyUnitEventBJ( gg_trg_Item_Acquire, EVENT_PLAYER_UNIT_PICKUP_ITEM )
    call TriggerAddAction( gg_trg_Item_Acquire, function Item_Acquire_Actions )
endfunction


thread can me set to solved
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
There's no need to save "False" on heroes. Just save "true" in the item classes that the hero can't use.

This is crazy. Don't do it.
JASS:
    if GetUnitTypeId(u) == 'H02B' or GetUnitTypeId (u) == 'H015' or GetUnitTypeId (u) == 'H029' or GetUnitTypeId (u) == 'H00R' then
        set b = true
    endif

Actually, you deleted most of my last improvements and made the code worse :p My past code was fine.

The problem lies on acquiring the item, and checking if the slot for that item is empty. If it isn't empty, check if the item that occupies the slot is the acquired item, and that the slot that's being occupied matches with the acquired item level.

There's a function to know which item is in which slot, but there's no function to retrieve the slot an item occupies.

I'll probably work around this later.

This is not solved at all. You'r script has many flaws that aren't noticeable right now, but will showup later.
 
Level 9
Joined
Jul 10, 2011
Messages
562
There's no need to save "False" on heroes. Just save "true" in the item classes that the hero can't use.

i just set that to test whether it changes^^ that was just for testing purpose :D i know that i dont have to do that xD

This is crazy. Don't do it.
JASS:
if GetUnitTypeId(u) == 'H02B' or GetUnitTypeId (u) == 'H015' or GetUnitTypeId (u) == 'H029' or GetUnitTypeId (u) == 'H00R' then
    set b = true
endif

how i should change it ? Oo that was the only way (for me at least ^^) to check it because these 4 classes are able to wear 2 onehanded weapons and i need to check whether the triggering unit is one of these classes.

Actually, you deleted most of my last improvements and made the code worse :p My past code was fine.

actually, i made this changes all the time from the version that didnt work at all^^ so i deleted nothing xD

The problem lies on acquiring the item, and checking if the slot for that item is empty. If it isn't empty, check if the item that occupies the slot is the acquired item, and that the slot that's being occupied matches with the acquired item level.

the version i made recognizes whether the slot is empty and whether the picked up item occupies the slot so that part is working.

This is not solved at all. You'r script has many flaws that aren't noticeable right now, but will showup later.

i know that its not perfect at all....especially because my jass knowledge is really small...but its working (at least so far) and thats what i want and need...it doesnt have to be perfect it just has to work the way i need it.
if i could/should change some lines because its more efficient or my lines/the way i do it could cause bugs/desync/whatever tell me what to change in which way and ill do it.

the thing is that my way (even if its "bad jass") works the way i need it and thats (in my eyes) better than having a good written system that just does the half or less of what i need it to do.

i hope you get what i mean.
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
I definitely know what you mean, but because if what you say (small knowledge about jass) you're making several mistakes which you can't see right now, but that will make you bash your head against your desktop later.

Finally, after a while... Hehehe... I got it ;) My trigger does most of what you want. I found several mistakes, since I never tested. I was "asuming" it was good :p

1. Checks if the ItemClass is useable by the Unit. If it can, goes to 2, else, drops it.
2. Checks If the Item doesn't belong to other player. If it can, goes to 3 and 4, else, drops it.
3. Checks the slot the item is at
4. Checks if the correct ItemSlot for that item is empty. If it is, goes to 5, else, drops it.
5. Checks if the Item is already at the correct slot. If it is, goes to 6, else, drops it.
6. Checks if the Item is occupied by another item. If it is, drops it.

DOESN'T CHECK IF THE ITEM IS 2HANDED (yet)

I tested with 2 items and 2 heroes, and works great

Test it, and let me know how do you want your 2Handed thing to work. I'm sure that will be another headache but i'm learning :D
 

Attachments

  • Test.w3m
    17.6 KB · Views: 52
Level 9
Joined
Jul 10, 2011
Messages
562
okay at first i have to say thanks for all the help and that youll be credited in my map for sure ^^

then here are the things that have to be added to the system (please dont kill me ^^):

1. the unittypes with the rawcodes 'H02B' , 'H015' , 'H029' , 'H00R' are able to carry 2 one handed weapons (ItemClasses 9-13) one is slot 1 & one in slot 2 but the item level (the slot it should be in) is 1 on every of these items because usually they are put in slot 1. so you have to write a check whether the triggering unit type is equal to one of these and then check whether slot 1 or slot 2 is empty and then add the weapon to the slot if its empty.

2. whenever a 2handed weapon (ItemClasses 1-8) is successfully picked up a dummy item has to fill slot 2 (dummy item rawcode 'I001') so slot 1 & slot 2 have to be empty to succesfully pick up a 2handed weapon.

3. just because its nicer....could you change "You don't own this item. It belongs to Player " + I2S(GetItemUserData(i))) to display the name of that player instead of the player number?

4. i dont know whether its a problem but i got the following system for restricting players from moving items inside the inventory and i dont know whether it also restricts your change slot order inside the system...ill test it but just to make you know :
JASS:
scope SlotChangeRestriction

struct SlotChangeRestriction extends array
    implement Alloc
    private integer tempIndex
    private unit tempUnit
    private item tempItem
    
    private static trigger moveTrigger
    
    private static method moveCallback takes nothing returns nothing
        local thistype this=ReleaseTimer(GetExpiredTimer())
        call DisableTrigger(thistype.moveTrigger)
        call IssueTargetOrderById(this.tempUnit,this.tempIndex,this.tempItem)
        call EnableTrigger(thistype.moveTrigger)
        call this.deallocate()
    endmethod
    static method create takes unit triggerUnit,item triggerItem returns thistype
        local thistype this=thistype.allocate()
        local integer i=0
        set this.tempUnit=triggerUnit
        set this.tempItem=triggerItem
        loop
            if UnitItemInSlot(this.tempUnit,i)==this.tempItem then
                set this.tempIndex=i+852002
            endif
            set i=i+1
            exitwhen i==6
        endloop
        call TimerStart(NewTimerEx(this),.01,false,function thistype.moveCallback)
        return this
    endmethod
    private static method onMove takes nothing returns boolean
        if GetIssuedOrderId()>852001 and GetIssuedOrderId()<852008  then
            call thistype.create(GetTriggerUnit(),GetOrderTargetItem())
        endif
        return false
    endmethod
    private static method onInit takes nothing returns nothing
        set thistype.moveTrigger=CreateTrigger()
        call TriggerRegisterPlayerUnitEvent(thistype.moveTrigger,Player(0),EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER,null)
        call TriggerAddCondition(thistype.moveTrigger,Condition(function thistype.onMove))
    endmethod

endstruct

endscope

5. when the dummy item is added you have to prevent the system from running otherwise it would get dropped and that were s***.

6. if its possible and easy to add to the system and just then could you add if a charged item is picked up and the unit already has this item to stack them on top up to the max HP of the item? if you have 5 for example, max stack is 8 and you pick up 5 the 2 charges that are left should be dropped without a message. (i want you to add this because the only good item stack n split system i found uses the item levels as max stack value....i dont need a split trigger i just want them to stack) (ItemClass of charged items is 20)

7. beside heroes there are 2 inventory boxes for each player. could you prevent the system from restricting the items and the slots there? (rawcode of the boxes is 'h004') but the owner check should still run but if someone tries to put an item in an inventory box and the inventory box owner != owner of the item the error message should be displayed to the owner of the item ("You just can give potions to other players.").

8. like already recognizalbe through the error message in 7. if the item picked up is charged their should be no owner (so no change of the custom value).

9. if an item is given from a player (1-10) to neutral hostile, player 11 (dark green) or player 12 (brown) the item should be dropped immediately without a message.



that should be everything....i really have the feeling that i have to say sorry for all these adds...so sorry for that ^^ i hope its not too much work for you and you still wanna help me ^^

could happen that i get something small that has to be added in my mind later so it could happen that the list gets a little longer.

i really have to thank you for your great help :D



thanks in advance

greetz clapto

p.s. if you have any questions just ask^^ ill answer them as fast and as accurate as im able to ^^ ;D

p.p.s.
I definitely know what you mean, but because if what you say (small knowledge about jass) you're making several mistakes which you can't see right now, but that will make you bash your head against your desktop later.
i just have to believe this ^^ but i trust you so...;D
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
1. the unittypes with the rawcodes 'H02B' , 'H015' , 'H029' , 'H00R' are able to carry 2 one handed weapons (ItemClasses 9-13) one is slot 1 & one in slot 2 but the item level (the slot it should be in) is 1 on every of these items because usually they are put in slot 1. so you have to write a check whether the triggering unit type is equal to one of these and then check whether slot 1 or slot 2 is empty and then add the weapon to the slot if its empty.

They'll be able to use them by default, as long as you don't save "true" on these classes for those units. I would suggest creating the MainHand and OffHand weapon. I mean, classify the offhand weapon as a Shield (Or classify shields as offhand)

2. whenever a 2handed weapon (ItemClasses 1-8) is successfully picked up a dummy item has to fill slot 2 (dummy item rawcode 'I001') so slot 1 & slot 2 have to be empty to succesfully pick up a 2handed weapon.
Ok, that's doable. I'll work on it.

3. just because its nicer....could you change "You don't own this item. It belongs to Player " + I2S(GetItemUserData(i))) to display the name of that player instead of the player number?

Yeah, that's easy.

4. i dont know whether its a problem but i got the following system for restricting players from moving items inside the inventory and i dont know whether it also restricts your change slot order inside the system...ill test it but just to make you know :
I don't know. You would have to test it. I don't think it presents any problem.

5. when the dummy item is added you have to prevent the system from running otherwise it would get dropped and that were s***.
No problem. I Turn off/on the trigger before creating that dummy item, so the trigger doesn't run.

6. if its possible and easy to add to the system and just then could you add if a charged item is picked up and the unit already has this item to stack them on top up to the max HP of the item? if you have 5 for example, max stack is 8 and you pick up 5 the 2 charges that are left should be dropped without a message. (i want you to add this because the only good item stack n split system i found uses the item levels as max stack value....i dont need a split trigger i just want them to stack) (ItemClass of charged items is 20)
Item stack systems are a pain in the ass. I don't know. I've never worked with them. I used to use the same you're using with item level :p. I'll give a look at it

7. beside heroes there are 2 inventory boxes for each player. could you prevent the system from restricting the items and the slots there? (rawcode of the boxes is 'h004') but the owner check should still run but if someone tries to put an item in an inventory box and the inventory box owner != owner of the item the error message should be displayed to the owner of the item ("You just can give potions to other players.").

This triggers ONLY for heroes. I would have to create a separate system (a lot easier) for those boxes, which, obviously, aren't heroes.

8. like already recognizalbe through the error message in 7. if the item picked up is charged their should be no owner (so no change of the custom value).
That's ok

9. if an item is given from a player (1-10) to neutral hostile, player 11 (dark green) or player 12 (brown) the item should be dropped immediately without a message.
That's ok.


Eh.. there are a lot of things to do, so, It may take up some time. Be aware that you can do most of the stuff you requested if you put a bit of yourself on it. I've never done most of these stuff and i'm burning my brain off (as you should) to make them and, look, i'm slowly achieving it.
 
Level 9
Joined
Jul 10, 2011
Messages
562
They'll be able to use them by default, as long as you don't save "true" on these classes for those units. I would suggest creating the MainHand and OffHand weapon. I mean, classify the offhand weapon as a Shield (Or classify shields as offhand)

would not be possible...sadly.
1. i dont have special offhand weapons they are all just one handed weapons (main & offhand).
2. even if had offhand weapons classifying them as shield would result in that these unit can wear shields and they shouldnt be able to wear shields.

so there has to be a specific check in the system for these unittypes.


Item stack systems are a pain in the ass. I don't know. I've never worked with them. I used to use the same you're using with item level :p. I'll give a look at it

like i said if its too hard or anything let it out.


This triggers ONLY for heroes. I would have to create a separate system (a lot easier) for those boxes, which, obviously, aren't heroes.

okay if it doesnt work on the boxes its perfect as it is^^


Eh.. there are a lot of things to do, so, It may take up some time.

no problem...take the time it needs...hopefully youre able to finish it this month because i planned to release an open beta next month (and i need some time for testing before releasing^^) but if you need more time then it is as it is^^ no problem ;D

Be aware that you can do most of the stuff you requested if you put a bit of yourself on it. I've never done most of these stuff and i'm burning my brain off (as you should) to make them and, look, i'm slowly achieving it.

im sorry for that but i already tried it myself (2 times...1 time GUI , the reason of this thread, and one time JASS , the reason why you do it^^).
beside ive never done all this stuff before (item restriction system...beside just one of each class) so i burned my brain too^^
so take the time you need and dont try to force yourself getting a solution^^ as long as you make it as fast and as good as you can im glad ^^

thanks again :D clapto

p.s. i'll go sleepin now so we'll write tomorrow again...;D gn8 man
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
would not be possible...sadly.
1. i dont have special offhand weapons they are all just one handed weapons (main & offhand).
2. even if had offhand weapons classifying them as shield would result in that these unit can wear shields and they shouldnt be able to wear shields.

so there has to be a specific check in the system for these unittypes.
It's possible. Just create an aditional ItemClass for Offhands

I've been feeling for a while thay you may have many restrictions for all the Heroes. I was just wondering, how many Class Restrictions do you have per Hero?

I mean.. If you have 23 Item Classes, are more of 12 restricted for most units? Or you forbid less than 12?
 
Level 9
Joined
Jul 10, 2011
Messages
562
It's possible. Just create an aditional ItemClass for Offhands

i said its impossible because its impossible. sure i could create an additional class with offhand 1handed weapons but i want the normal 1handed weapons to be wearable for these classes in main and offhand and with an additional offhand class that wouldnt be possible. also i dont wanna make XX more items just for offhand^^

I've been feeling for a while thay you may have many restrictions for all the Heroes. I was just wondering, how many Class Restrictions do you have per Hero?

I mean.. If you have 23 Item Classes, are more of 12 restricted for most units? Or you forbid less than 12?

the thing is that each class just is able to wear some weapon classes so nearly every itemclass from 1-13 is restricted (1-2 are wearable for each class). for example if the model of the hero wears a 1handed sword and a shield the restriction would restrict every weapon beside 1handed swords and shields. if it wears a 2handed hammer all classes beside 2handed hammers is restricted. i hope you get what i wanna achieve ;D

so to answer your question i will restrict up to max 11 classes for each hero (1 weapon class is wearable for every herotype).

p.s. i just have 20 itemclasses not 23 ^^
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
Damn, it's so much. 83 heroes with 11 restrictions each means hundreds of callings...

If items can't be destroyed, you could use ItemLevel as ItemSlot and ItemLife as ItemClass.
 
Level 9
Joined
Jul 10, 2011
Messages
562
Damn, it's so much. 83 heroes with 11 restrictions each means hundreds of callings...

If items can't be destroyed, you could use ItemLevel as ItemSlot and ItemLife as ItemClass.

i cant change it^^ its the way it should work^^


I will post my test map later guys for you to test.

It will require JNGP tho.

okay ill wait and hope youre able to add everything i need/mentioned.


No matter who will be the one finishing the system you both will be credited in my map for all this help :D i think it was really time consuming so thanks for all thw work you 2 did up to now :D
 
Level 20
Joined
Jul 14, 2011
Messages
3,213
clapto... The thing is, you don't see right now the problems we're seeing. We're talking about 1500+ callings

I REALLY thing that this system may work for something smaller... like 12 heroes and 10 item classes... Increasing it to 83 and 20 item classes is just mad...
 
Level 25
Joined
Jun 5, 2008
Messages
2,572
This is just to show how easy it is to set up.

Demon hunter and Paladin are set up with custom pickup, archmage isn't.

You can see inside the trigger how it is done.
The debug messages are there only for show atm.

Enjoy, might refine it if you like it.
 

Attachments

  • itemPickup.w3x
    22.5 KB · Views: 30
Level 20
Joined
Jul 14, 2011
Messages
3,213
Well, it still requires reading the custom value of the item to know the item owner. Also restrict item movement inside inventory, and add each item to a fixed slot.
 
Level 9
Joined
Jul 10, 2011
Messages
562
the basic idea is really great :D its easy to set the items and the heroes.

so and correct me if im wrong but as far i understand the system it work like this (so far):

you add the item to abstract groups (weapons, body armor, boots, and so on) and then add them in a specific group (axe, sword, helmet, and so on).

then you set the heroes restrictions (for example hero X can wear hammers, sword & helmets but nothing else).

then whenever a item is acquired the trigger checks the abstract group until it fits, then the specific group and then it cheks whether the hero is able to wear it.

so far it is correct i hope. ;D


so now i have some "problems". I need the system ill use in my map to do the following additionally :

-moving the items to specific slots and drops them if the needed slots are filled
-the system need to be able to differ between 2-handed and dual wield
-i need the system to check whenever a 2-handed weapon is picked up successfully the dummy item 'I001' is added to slot 2
-item ownage check through custom value


also it would be nice if it could do this :
-stacks charged items on top of each other up to a certain value (saved somewhere in the editor values of the item if possible) if the hero already carrys this itemtype
-if possible i would like to avoid a offhand itemclass and let the normal 1-handed weapons to be dual wielded if a certain value is set for the hero (for example instead of the value 2 for the item class set it to 3 if it could be dual wielded)


would be really nice if you could change the system to do what i mentioned.

p.s. the abstract classes and the specific classes are customizable?


*EDIT: oh....i started writing this post after you posted the testmap so i havent read the post after that one...
 
Level 25
Joined
Jun 5, 2008
Messages
2,572
Yes you are correct.

Using abstract groupd and subgroups (or in the trigger named classes) you can have complete control.

And you are dead on on how the system works, glad you like it.

p.s. the abstract classes and the specific classes are customizable?

They are what you tell them to be, i can make them constant like:
JASS:
globals
        private constant integer WEAPON_GROUP = 1
        private constant integer HELM_GROUP = 2
        // etc etc...
        private constant integer SWORD_CLASS = 1
        private constant integer AXE_CLASS  = 2
       // and so on..
endglobals

Or you could just memorize stuff and use the comments like i did. Remember these are abstract classes they are non-existent and it comes down to integer comparison.

The 1st aproach is easier to debug but the 2nd aproach is faster if you for example write the groups/classes on paper or notepad and just use them while setting up items.

Edit:

I am glad you like my idea and aproach, it will save you function calls and improve efficency a lot.
 
Level 9
Joined
Jul 10, 2011
Messages
562
ahhh glad to hear that im at least able to understand how such a system works...even though i cant write it myself ^^


okay as long as you dont change them the classes and groups are what i need them to be.

so...back to the thing i mentioned...would you do me the favor and implement the checks/functions/etc i mentioned into the system?

(i think now you have to make the classes and groups constants because of the slot check or you make any value which can be changed in the editor to set the required slot ; both would be okay^^)


would be glad if you would finish the system the way i need it to be ;D

greetz clapto

p.s. gn8 ^^ we'll write tomorrow again... goin to sleep now ^^
 
Level 25
Joined
Jun 5, 2008
Messages
2,572
I will try to make the modifications during the next 3 days but i can't promise much.

I got limited spare time due to exams and helping out other people also so... sorry for not being able to put a fix date but i guess you will have to wait or find someone else.

Hope you understand.
 
Status
Not open for further replies.
Top