• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Using GetLocalPlayer to form localized items

Status
Not open for further replies.
Level 19
Joined
Aug 8, 2007
Messages
2,765
I'm only recently trying to fiddle with GetLocalPlayer

JASS:
function GetUnitWingData takes nothing returns nothing
    local integer i
    local integer array i2
    loop
        exitwhen i == 12
        if GetLocalPlayer() == Player(i) then
            if GetRandomInt(0, 100) < 50 then
                set i2[GetPlayerId(GetLocalPlayer())] = 'A019'
                endif
            endif
        set i = i+ 1
    endloop
    call CreateItem(i2[GetPlayerId(GetLocalPlayer())], 0, 0)
endfunction

i dont really have friends to test it

Would this work to create items that show for only a specific player?
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
I read that there was a workaround, assigning the id of the handle u want to create locally and than creating it globally but using the localized handle.

In this case, i assigned the item type locally and the iteem itself globally. Cant do that?
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
Same if you enum items (as it should opens a new thread in each enum).

But this is just pure guess.
Maybe it doesn't desync as long you don't interact with it.

I have for example already gave a different position for an unit through SetUnitX/Y for the differents players, it only desynced when the game interact with the unit (like when the unit is targeted).

What do you want to do exactly (maybe there are workarounds) ?
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
I want to make a localized drop system, so players only see their drops not others
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
I'm no modeling expert, but can animations change the bounding sphere? (or whatever is used for determining mouse selection)
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
I don't know that much neither, but for units i know you can make animations which make the unit not targetable with the mouse (without 'Aloc', and the "AI" will still target it, it just avoid the mouse target).
So i suppose it's just the same with items.

Hide locally items on drop except for the owner worths a try.
But i'm not sure it won't descyn when the owner will pick it again. (if it doesn't desync on hide)
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
I don't know that much neither, but for units i know you can make animations which make the unit not targetable with the mouse (without 'Aloc', and the "AI" will still target it, it just avoid the mouse target).
So i suppose it's just the same with items.

Hide locally items on drop except for the owner worths a try.
But i'm not sure it won't descyn when the owner will pick it again. (if it doesn't desync on hide)

  • beta
    • Events
      • Player - Player 1 (Red) types a chat message containing beta as An exact match
      • Player - Player 2 (Blue) types a chat message containing beta as An exact match
      • Player - Player 3 (Teal) types a chat message containing beta as An exact match
      • Player - Player 4 (Purple) types a chat message containing beta as An exact match
    • Conditions
    • Actions
      • Item - Create Kelen's Dagger of Escape at (Center of Hero SpawnRespawn <gen>)
      • Set TempItem = (Last created item)
      • Custom script: if GetLocalPlayer() != GetTriggerPlayer() then
      • Item - Hide TempItem
      • Custom script: endif
Worked, but desync'd when i moused over the iteem

e/ ERM. it works. it just so turns out that my friend has horrible internet connection and dropped EXACTLY when i picked up the item. Ty guys
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
He said he couldnt see the daggger, i picked it up, he saw it in my inventory, i used it,i dropped it, he could see it on the ground, he picked it up and used it. No desyncs.
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Based off of experiences question, not really needed but

do hidden items take collision space?
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
if you put 500 items in one spot, they will appear to form a grid. Im wondering if hidden items will take place in that grid
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Hmm.. because i dont want to create another thread...

How do i reference a struct inside of a TriggerRegisterAction? i tried thistype.MethodName but it didnt work

(the two methods are in the same struct)
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
Stil cant figure it out.. :S

JASS:
    globals
        hashtable ItemDropHash = InitHashtable()
        hashtable ItemChanceHash = InitHashtable()
        integer MaxItemsInt = 2938439
    endglobals
struct ItemDrops
    private static method onInit takes nothing returns nothing
        call TriggerRegisterAnyUnitEventBJ(function thistype.onKill, EVENT_PLAYER_UNIT_DEATH)
    endmethod
    private static method onKill takes nothing returns nothing
        local unit u = GetDyingUnit()
        local integer i = 0
        local integer i2 = 0
        loop
            exitwhen i == 12
            if GetLocalPlayer() == Player(i) then
                loop
                    exitwhen i2 == LoadInteger(ItemDropHash, GetUnitTypeId(u), MaxItemsInt)
                    if GetRandomReal(0, 100) < LoadReal(ItemChanceHash, GetUnitTypeId(u), i2) then
                        call CreateItemLoc(LoadInteger(ItemDropHash, GetUnitTypeId(u), i2), GetUnitLoc(u))
                    endif
                    set i2 = i2 + 1
                endloop
            endif
        endloop
    endmethod
    private static method addUnitType takes integer unitType, integer itemType, real chance returns nothing
        local boolean b = false
        local integer i = 0
        loop
            exitwhen b == true
            if LoadInteger(ItemDropHash, unitType, i) < 50 then
            call SaveInteger(ItemDropHash, unitType, i, itemType)
            call SaveReal(ItemChanceHash, unitType, i, chance)
            call SaveInteger(ItemDropHash, unitType, MaxItemsInt, i)
            set b = true
            endif
            set i = i + 1
        endloop
    endmethod
endstruct
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
putting it under still give the same error

e/ fixed.

2e/ on a sidenote, will that code even work? xD gotta test
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
JASS:
function TriggerRegisterAnyUnitEventBJ takes trigger trig, playerunitevent whichEvent returns nothing

call TriggerRegisterAnyUnitEventBJ(function thistype.onKill, EVENT_PLAYER_UNIT_DEATH)

thistype.onKill is a static method (simple function) not a trigger :p
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
ok heres what i have atm, untested ofc :)

JASS:
    globals
        hashtable ItemDropHash = InitHashtable()
        hashtable ItemChanceHash = InitHashtable()
        integer MaxItemsInt = 2938439
    endglobals
struct ItemDrops
    private static method onKill takes nothing returns nothing
        local unit u = GetDyingUnit()
        local integer i = 0
        local integer i2 = 0
        local integer i3 = 0
        local boolean array b
        local integer array itemTypes
        local integer max = 0
        loop
            call print("Started Loop 1")
            exitwhen i == 12
            if GetLocalPlayer() == Player(i) then
                loop
                    call print("Started Loop 2")
                    exitwhen i2 == LoadInteger(ItemDropHash, GetUnitTypeId(u), MaxItemsInt)
                    if GetRandomReal(0, 100) < LoadReal(ItemChanceHash, GetUnitTypeId(u), i2) then
                       set b[i2] = true
                    endif
                    set i2 = i2 + 1
                endloop
            endif
        endloop
        loop
            exitwhen i3 == LoadInteger(ItemDropHash, GetUnitTypeId(u), MaxItemsInt)
            set bj_lastCreatedItem = CreateItemLoc(LoadInteger(ItemDropHash, GetUnitTypeId(u), i3), GetUnitLoc(u))
            if b[13] == false then
                call SetItemVisible(GetLastCreatedItem(), false)
            endif
            set i3 = i3 + 1
        endloop
    endmethod
    private static method addUnitType takes integer unitType, integer itemType, real chance returns nothing
        local boolean b = false
        local integer i = 0
        loop
            exitwhen b == true
            if LoadInteger(ItemDropHash, unitType, i) < 50 then
            call SaveInteger(ItemDropHash, unitType, i, itemType)
            call SaveReal(ItemChanceHash, unitType, i, chance)
            call SaveInteger(ItemDropHash, unitType, MaxItemsInt, i)
            call print("Successful")
            set b = true
            endif
            set i = i + 1
        endloop
    endmethod
    private static method onInit takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddAction(t, function thistype.onKill)
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
        call addUnitType('N001', 'I01E', 100)
        call print("Good")
    endmethod
endstructt

the problem is that. if it works, it will create every single item that the unit can drop and if no players were given the drop than it will just sit there forever hidden

e/ woops double
 
Level 19
Joined
Aug 8, 2007
Messages
2,765
looked at table and it confuses me. the reason addUnitType loops is so it will add to the next available slot, allowing unit types to have moar than 1 item
 
Level 17
Joined
Apr 27, 2008
Messages
2,455
You could simply use the itempool api.
Check for GUI examples or even on a preplaced unit and then check the generated code in the map script if you don't know how to use an itempool.
It should have some tutorials about it somewhere, or about unitpools which work just the same, except they are for random units instead of random items.
 
Status
Not open for further replies.
Top