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

Localized Items - Last Desync

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
ok, so ive been working for a while on working with getlocalplayer and SetItemVisible to create a localized item system. im 99% done. my last desync (theres been tons so far >.<)

JASS:
library CustomDrop initializer init
    globals
        private hashtable Hash_t = InitHashtable()
        private location SendToItem = Location(0,0)
    endglobals
    
    private function OnDeath takes nothing returns nothing
        local unit u = GetDyingUnit()
        local integer unitId = GetUnitTypeId(u)
        local integer count = LoadInteger(Hash_t,unitId,0) // if the unit type was not registred for drop it will be equal to 0, else it will be > 0
        local real random
        local integer i
        local item drop
        
        loop // loop on all dropable item for unitID
        exitwhen count == 0 
            
            set i = 0
            loop // player loop
            exitwhen i == 11
                if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER then
                    set random = GetRandomReal(0,100)
                    if random < LoadReal(Hash_t,unitId,count) then
                        set drop = CreateItem(LoadInteger(Hash_t,unitId,count),GetUnitX(u),GetUnitY(u))
                        call SetItemVisible(drop,GetLocalPlayer()==Player(i))// the item will be visible only for Player(i)
                    endif
                endif
            set i = i+1
            endloop
     
        set count = count-1
        endloop
        set u = null
        set drop = null
    endfunction
    
    private function RegisterDrop takes integer unitId , integer itemId, real chanceToDrop returns nothing // chanceToDrop in percent
        local integer n = LoadInteger(Hash_t,unitId,0)
        /* integer : unitId ; 0 -> number of possible item drop for the unit type unitId
           integer : unitId ; x -> rawcode of the item to drop ; x > 0
           real : unitId ; x -> chance of the item x to drop
        */
        set n = n+1
        call SaveInteger(Hash_t,unitId,0,n)
        call SaveInteger(Hash_t,unitId,n,itemId)
        call SaveReal(Hash_t,unitId,n,chanceToDrop)
    endfunction
    private function onItemPickup takes nothing returns nothing
        local item it = GetOrderTargetItem()
        local unit u = GetTriggerUnit()
        local boolean b
        local integer i = 0
 //       call SetItemPosition(i, GetItemX(i), GetItemY(i))
////        call TriggerSleepAction(0.01)
 ///       call UnitAddItem(u , i)
        if it != null then
            call IssueImmediateOrder(u, "stop")
            call SetUnitPositionLoc(u, GetUnitLoc(u))
            call SetItemVisible(it, true)
            call UnitAddItem(u, it)
        endif
            
    endfunction

    private function init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        local trigger trig2 = CreateTrigger()
        
        call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_DEATH)
        call TriggerRegisterAnyUnitEventBJ(trig2, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER  )
        call TriggerAddAction(trig,function OnDeath)
        call TriggerAddAction(trig2, function onItemPickup)
        call RegisterDrop('n000','rat6',25)
        
    endfunction
    
endlibrary

ill clean leaks later no worry. My problem is that, if you have a full inventory and try to grab an item, desync ahoy. Anyone got a solution, trigger-wise? My current solution is to make all items tomes, but thats alot of work. -.-
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
its now desyncing even more before full inv + the full inventory ui message still appears even tho it prints "Full Inventory

JASS:
library CustomDrop initializer init
    globals
        private hashtable Hash_t = InitHashtable()
        private location SendToItem = Location(0,0)
    endglobals
    
    private function OnDeath takes nothing returns nothing
        local unit u = GetDyingUnit()
        local integer unitId = GetUnitTypeId(u)
        local integer count = LoadInteger(Hash_t,unitId,0) // if the unit type was not registred for drop it will be equal to 0, else it will be > 0
        local real random
        local integer i
        local item drop
        
        loop // loop on all dropable item for unitID
        exitwhen count == 0 
            
            set i = 0
            loop // player loop
            exitwhen i == 11
                if GetPlayerSlotState(Player(i)) == PLAYER_SLOT_STATE_PLAYING and GetPlayerController(Player(i)) == MAP_CONTROL_USER then
                    set random = GetRandomReal(0,100)
                    if random < LoadReal(Hash_t,unitId,count) then
                        set drop = CreateItem(LoadInteger(Hash_t,unitId,count),GetUnitX(u),GetUnitY(u))
                        call SetItemVisible(drop,GetLocalPlayer()==Player(i))// the item will be visible only for Player(i)
                    endif
                endif
            set i = i+1
            endloop
     
        set count = count-1
        endloop
        set u = null
        set drop = null
    endfunction
    
    private function RegisterDrop takes integer unitId , integer itemId, real chanceToDrop returns nothing // chanceToDrop in percent
        local integer n = LoadInteger(Hash_t,unitId,0)
        /* integer : unitId ; 0 -> number of possible item drop for the unit type unitId
           integer : unitId ; x -> rawcode of the item to drop ; x > 0
           real : unitId ; x -> chance of the item x to drop
        */
        set n = n+1
        call SaveInteger(Hash_t,unitId,0,n)
        call SaveInteger(Hash_t,unitId,n,itemId)
        call SaveReal(Hash_t,unitId,n,chanceToDrop)
    endfunction
    private function onItemPickup takes nothing returns nothing
        local item it = GetOrderTargetItem()
        local unit u = GetTriggerUnit()
        local boolean b
        local integer i = 0
 //       call SetItemPosition(i, GetItemX(i), GetItemY(i))
////        call TriggerSleepAction(0.01)
 ///       call UnitAddItem(u , i)
        loop
            set b = UnitItemInSlot(u, i) == null
            exitwhen b == true
            set i = i + 1
            exitwhen i == 5
        endloop
        if b == false then
//            call TriggerSleepAction(0)
            call IssueImmediateOrder(u, "stop")
            call IssueInstantPointOrder(u, "move", GetUnitX(u), GetUnitY(u), null)
            call print("Full Inventory")
        elseif it != null then
            call TriggerSleepAction(0)
            call IssueImmediateOrder(u, "stop")
            call SetUnitPositionLoc(u, GetUnitLoc(u))
            call SetItemVisible(it, true)
            call UnitAddItem(u, it)
        endif
            
    endfunction

    private function init takes nothing returns nothing
        local trigger trig = CreateTrigger()
        local trigger trig2 = CreateTrigger()
        
        call TriggerRegisterAnyUnitEventBJ(trig, EVENT_PLAYER_UNIT_DEATH)
        call TriggerRegisterAnyUnitEventBJ(trig2, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER  )
        call TriggerAddAction(trig,function OnDeath)
        call TriggerAddAction(trig2, function onItemPickup)
        call RegisterDrop('n000','rat6',25)
        
    endfunction
    
endlibrary
 
When does it desync? (at what part of the code?) Also, why are you changing the visibility?

If you want to remove the chances of desync, I recommend that you globally set the item visible before handling it. If you get the desync in the onItemPickup function, just put at the top after the local variables call SetItemVisible(it, true). (or wherever it should be so that your triggers still work)
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
it doesnt desync at a part of the code persay, but it desyncs when units pickup the hidden items (ON OCCASION, not 100%) (but this was fixed but i startedm aking changes to the script and it came back)

ill try setting it visible, i tried to already but that was with an acquire item event so it might be better

e/rase

spoke too soon, OP bug is still in place (full inventory desync)
 
Last edited:
Status
Not open for further replies.
Top