HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Replacing a dropped item?

03-19-2005, 07:18 AM#1
Raptor--
Ok, so I've been working on my own little inventory system -- its a hack-job (ie thrown together as i went along), so its really messy, but it serves its purpose up until attempting to drop an item and have that slot replaced with itself or something else

anyways, what happens is

Code:
EQUIP Drop Equipment
    Events
        Unit - A unit Loses an item
    Conditions
        ((Hero manipulating item) is in GAME_ugroupPlayerUnits) Equal to True
        INVENTORY_bDisableDropCheck[(Player number of (Owner of (Hero manipulating item)))] Equal to False
    Actions
        Set OTHER_nPlayerIndex = (Player number of (Owner of (Hero manipulating item)))
        Set INVENTORY_bDisableDropCheck[OTHER_nPlayerIndex] = True
        Trigger - Run EQUIP Determine Slots <gen> (checking conditions)
        Custom script:   set udg_XTEMP_n01 = GetHandleInt( GetManipulatedItem(), "var_nOwner")
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                XTEMP_n01 Equal to OTHER_nPlayerIndex
            Then - Actions
                Set EQUIPMENT_itemTemp = (Item being manipulated)
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        PLAYER_bSelectWeap1_A[OTHER_nPlayerIndex] Equal to True
                    Then - Actions
                        Game - Display to (All players) the text: equip mode true
                        -------- In equipping mode --------
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                PLAYER_itemPrimary_A[OTHER_nPlayerIndex] Equal to No item
                                (Item-type of EQUIPMENT_itemTemp) Equal to Unarmed
                            Then - Actions
                                //Game - Display to (All players) the text: Dropped unarmed
                                Set XTEMP_point01 = (Center of Temp Area <gen>)
                                Item - Remove EQUIPMENT_itemTemp
                                Set XTEMP_item03 = EQUIPMENT_itemTemp
                                Item - Create Unarmed at XTEMP_point01
                                Set EQUIPMENT_itemTemp = (Last created item)
                                Set ICREATE_bMakeItem = False
                                Trigger - Run ICREATE Unarmed <gen> (checking conditions)
                                Set EQUIPMENT_itemTemp = XTEMP_item03
                                Custom script:   call SetHandleInt( GetLastCreatedItem(), "var_nOwner", udg_OTHER_nPlayerIndex )
                                Item - Make (Last created item) Unpawnable
                                Custom script:   call RemoveLocation( udg_XTEMP_point01 )
                                Custom script:   call giveItemInSlot( udg_PLAYER_unitHero_A[udg_OTHER_nPlayerIndex], GetLastCreatedItem(), 5 )
                            Else - Actions
                                Do nothing
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                PLAYER_itemPrimary_A[OTHER_nPlayerIndex] Equal to EQUIPMENT_itemTemp
                            Then - Actions
                                Game - Display to (All players) the text: Dropped primary
                                Trigger - Run EQUIP Drag Item Off 5 <gen> (checking conditions)
                                Set PLAYER_itemPrimary_A[OTHER_nPlayerIndex] = No item
                                Set XTEMP_point01 = (Center of Temp Area <gen>)
                                Set XTEMP_item03 = EQUIPMENT_itemTemp
                                Item - Create Unarmed at XTEMP_point01
                                Set EQUIPMENT_itemTemp = (Last created item)
                                Set ICREATE_bMakeItem = False
                                Trigger - Run ICREATE Unarmed <gen> (checking conditions)
                                Set EQUIPMENT_itemTemp = XTEMP_item03
                                Custom script:   call SetHandleInt( GetLastCreatedItem(), "var_nOwner", udg_OTHER_nPlayerIndex )
                                Item - Make (Last created item) Unpawnable
                                Custom script:   call RemoveLocation( udg_XTEMP_point01 )
                                Set XTEMP_point01 = (Position of PLAYER_unitHero_A[OTHER_nPlayerIndex])
                                Set XTEMP_point02 = (XTEMP_point01 offset by (Random real number between 0.00 and 64.00) towards (Random angle) degrees)
                                Item - Move EQUIPMENT_itemTemp to XTEMP_point02
                                Custom script:   call RemoveLocation( udg_XTEMP_point01 )
                                Custom script:   call RemoveLocation( udg_XTEMP_point02 )
                                Custom script:   call giveItemInSlot( udg_PLAYER_unitHero_A[udg_OTHER_nPlayerIndex], GetLastCreatedItem(), 5 )
                            Else - Actions
                                Do nothing
                    Else - Actions
                        Do nothing
                Custom script:   set udg_XTEMP_s01 = GetHandleString( GetManipulatedItem(), "var_sType" )
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        XTEMP_s01 Equal to weapon
                    Then - Actions
                        Set XTEMP_b01 = False
                        Trigger - Run EQUIP Deposite Weapon <gen> (checking conditions)
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                XTEMP_b01 Equal to True
                            Then - Actions
                                //Game - Display to (All players) the text: inv was full
                                -------- INV WAS FULL --------
                            Else - Actions
                                -------- WEAPON --------
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        PLAYER_itemPrimary_A[OTHER_nPlayerIndex] Equal to No item
                                    Then - Actions
                                        Set PLAYER_itemPrimary_A[OTHER_nPlayerIndex] = (Item being manipulated)
                                        Set EQUIPMENT_itemTemp = (Item being manipulated)
                                        Trigger - Run EQUIP Raise Stats <gen> (checking conditions)
                                    Else - Actions
                                        Do nothing
                    Else - Actions
                        Do nothing
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        XTEMP_s01 Equal to other
                    Then - Actions
                        Game - Display to (All players) the text: other
                        Set XTEMP_b01 = False
                        Trigger - Run EQUIP Deposite Item <gen> (checking conditions)
                        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                            If - Conditions
                                XTEMP_b01 Equal to True
                            Then - Actions
                                Game - Display to (All players) the text: inv was full
                                -------- INV WAS FULL --------
                            Else - Actions
                                -------- ITEM --------
                    Else - Actions
                        Do nothing
            Else - Actions
        Set INVENTORY_bDisableDropCheck[OTHER_nPlayerIndex] = False

and the function in question (or thats suppose to do the replacing) is

Code:
//***************************************************************************
//Gives the unit an item in a specified inventory slot
//***************************************************************************
function giveItemInSlot takes unit u, item i, integer slot returns nothing
    local integer x

    set x = 1
    loop
        exitwhen x > (slot - 1)
        if ( UnitItemInSlotBJ(u, x) == null ) then
            call UnitAddItemByIdSwapped( 'ches', u )
           set udg_EQUIPMENT_itemDummy_A[x] = GetLastCreatedItem()
        else
            call DoNothing(  )
        endif
        set x = x + 1
    endloop
    call UnitRemoveItemFromSlotSwapped( x, u )
    call SetItemPositionLoc( UnitItemInSlotBJ(u, x), GetRectCenter(GetPlayableMapRect()) )
    call UnitAddItemSwapped( i, u )

    set x = 1
    loop
        exitwhen x > (slot - 1)
        call RemoveItem( udg_EQUIPMENT_itemDummy_A[x] )
        set x = x + 1
    endloop
endfunction

the only thing is, its unable to put an item into the slot that had an item just dropped from it, any ideas?
03-19-2005, 08:48 PM#2
johnfn
Code:
Part1
    Events
        Unit - A unit Acquires an item
    Conditions
    Actions
        For each (Integer A) from 1 to 6, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Item carried by (Triggering unit) in slot (Integer A)) Equal to (Item being manipulated)
                    Then - Actions
                        Set ItemsInSlots[(Integer A)] = (Item being manipulated)
                        Skip remaining actions
                    Else - Actions





Part2
    Events
        Unit - A unit Loses an item
    Conditions
    Actions
        Wait 0.10 seconds
        For each (Integer A) from 1 to 6, do (Actions)
            Loop - Actions
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    If - Conditions
                        (Item being manipulated) Equal to ItemsInSlots[(Integer A)]
                    Then - Actions
                        For each (Integer B) from 1 to (Integer A), do (Actions)
                            Loop - Actions
                                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                                    If - Conditions
                                        (Item carried by (Triggering unit) in slot (Integer B)) Equal to No item
                                    Then - Actions
                                        Hero - Create Heart of Aszune and give it to (Triggering unit)
                                    Else - Actions
                        Hero - Create Scroll of Animate Dead and give it to (Triggering unit)
                    Else - Actions
        For each (Integer A) from 1 to 5, do (Actions)
            Loop - Actions
                Item - Remove (Item carried by (Triggering unit) of type Heart of Aszune)

Its rare for triggers to be fun for me to write, but that one was, mainly because I didnt make any errors at all :)


It may be due to the fact that I have a wait and you dont. Maybe the game doesnt properly recognize the item is dropped until after the trigger fires? /shrug
03-19-2005, 10:48 PM#3
Raptor--
the thing is i don't want to use waits since that gives the slight possibility of -ROYALLY- screwing everything up since it allows other triggers to be processed in the meantime, and some flags are globally set on other triggers that need to be in certain states only while the trigger is running, which basically i can't account for all that the way i've programmed it so far

nice try, but i guess i should have specified i can't use waits or i would have fixed it aeons ago
03-19-2005, 11:30 PM#4
Anitarf
Quote:
Originally Posted by Raptor--
the thing is i don't want to use waits since that gives the slight possibility of -ROYALLY- screwing everything up since it allows other triggers to be processed in the meantime, and some flags are globally set on other triggers that need to be in certain states only while the trigger is running, which basically i can't account for all that the way i've programmed it so far

nice try, but i guess i should have specified i can't use waits or i would have fixed it aeons ago
You don't need waits to -ROYALLY- screw everything up, I learned that when playing with various item-systems myself. The action "drop item from unit" will instantly cause any triggers with the event "unit looses an item" to run and interfere, just like if you used an action "run trigger". Similar goes for "give item to unit" and "unit acquires an item", and probably other action-event pairs as well. I don't know if you knew about this and took it into account, so I just thought I'd bring it up.
03-19-2005, 11:54 PM#5
Raptor--
Quote:
Originally Posted by Anitarf
You don't need waits to -ROYALLY- screw everything up, I learned that when playing with various item-systems myself. The action "drop item from unit" will instantly cause any triggers with the event "unit looses an item" to run and interfere, just like if you used an action "run trigger". Similar goes for "give item to unit" and "unit acquires an item", and probably other action-event pairs as well. I don't know if you knew about this and took it into account, so I just thought I'd bring it up.

course i know that, thats the exact reason waits -will- screw everything up -- i disable certain events for the duration of the trigger (0 seconds without any waits), but with waits there is a possibility that 2 triggers will run in tandem and therefore disable and renable the other event triggers while an instance of the initial trigger is still running

essentially yeah waits don't necessarily have to mess things up, but only when triggers run completely contained in themselves so you can have 100 instances of the trigger running all independent -- but the moment triggers start affecting global things waits will mess up set dependences

i mean, you can even think about a small example -- what if ur inventory was full, u dropped an item, and then picked up another item in that 0.10 seconds of delay, then all of a sudden ur inventory is full and when it tries to force an item back into ur inventory it can't
03-20-2005, 12:11 AM#6
johnfn
It can be 0.01 seconds for all it matters.



And cant you do a turn this trigger off at the beginning and turn it on at the end?
03-20-2005, 03:12 AM#7
Raptor--
even with 0.01 it gives a small chance of picking up while the trigger is waiting, and even a small chance of breaking the whole thing is a chance of breaking :S...

but regardless, i'm just looking for a way to do it without 'waiting'
03-20-2005, 04:04 AM#8
AnarkiNet
yeah i wouldnt use waits if it could screw it up.
for example, the host of a game lags and some guy clicks repeatedly on an item or something, well all those clicks are going to arrive at once (not .01 seconds apart like if he had been actually clicking) so that might screw something up if theres a wait.

disclaimer - i didnt read the whole trigger :)
03-20-2005, 08:37 AM#9
Raptor--
yeah nope, i even tried putting the 0.01 wait there, it messes -everything- up instantly because my (slightly crappy) code relies on everything being instant without waits

that and u start getting a lot of delays between things even with 0.01

so yup... don't tell me i have to rewrite all my item stuff from the ground up in a more planned and efficient manner...
03-21-2005, 03:40 AM#10
Raptor--
hmm, well i was able to put items in slots on a 'dragdrop' event but i haven't been able to fix the whole dropping thing

has anyone been able to stop a unit from dropping an item by putting it back exactly where it came from? if this map exists maybe i can look at it to see how its done