Announcement

Collapse

Forum Rules

  • No flaming or derogatory remarks, directly or through insinuation.
  • No discussion, sharing or referencing illegal software such as hacks, keygen, cracks and pirated software.
  • No offensive contents, including but not limited to, racism, gore or pornography.
  • No excessive spam/meme, i.e. copious one liners in a short period of time, typing with all caps or posting meme responses (text/image).
  • No trolling, including but not limited to, flame incitation, user provocation or false information distribution.
  • No link spamming or signature advertisements for content not specific to Dota 2.
  • No Dota 2 key requests, sell, trade etc.
  • You may not create multiple accounts for any purpose, including ban evasion, unless expressly permitted by a moderator.

  • Please search before posting. One thread per issue. Do not create another thread if there is an existing one already.
  • Before posting anything, make sure you check out all sticky threads (e.g., this). Do not create new threads about closed ones.
  • It is extremely important that you post in correct forum section.

  • Balance discussion only in Misc.
  • All art related (such as hero model) feedbacks go to Art Feedback Forum.
  • All matchmaking feedback should go here: Matchmaking Feedback
  • All report/low priority issues should go here: Commend/Report/Ban Feedback
  • No specific workshop item feedback. These should go to workshop page of that item.
  • When posting in non-bugs section (such as this), use [Bugs], [Discussion] or [Suggestion] prefix in your thread name.



In case you object some action by a moderator, please contact him directly through PM and explain your concerns politely. If you are still unable to resolve the issue, contact an administrator. Do not drag these issues in public.



All rules are meant to augment common sense, please use them when not conflicted with aforementioned policies.
See more
See less

CDOTA_BaseNPC:RemoveItem deletes the item instead of removing from inventory

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • CDOTA_BaseNPC:RemoveItem deletes the item instead of removing from inventory

    I have an item that I want one player to give to another, but they are not always close enough to walk. So I use AddItem() to give the player the item, then RemoveItem() to take it away from the other player. But when I do this, the item just disappears. I checked and it looks like RemoveItem deletes the item instead of removing it from the inventory. This seems like a strange behavior, because there is no other function that lets me remove an item from the inventory. However there are many other functions for deleting things, so it makes no sense why RemoveItem should delete the item too. Also, the wiki says that RemoveItem should remove the passed item from the unit inventory, but it does not say it deletes it.

  • #2
    It's definitely a bit silly to not have that behavior. Here is a wacky workaround that does allow you to remove an item from the inventory without deleting it.

    Code:
        unit:DropItemAtPositionImmediate(item, unit:GetAbsOrigin())
        for i=GameRules:NumDroppedItems()-1,0,-1 do
          local drop = GameRules:GetDroppedItem(i)
          if drop:GetContainedItem() == item then
            drop:RemoveSelf()
            break
          end
        end
    This will force drop the item in this server frame (creating a physical item with your item in it), then find the dropped item and delete the physical container, leaving the original item in "limbo" (not in a physical item or inventory). At this point it can be AddItem'd to another unit. Don't let the loop scare you, it should always be GameRules:GetDroppedItem(GameRules:NumDroppedItems ()-1), and as such the loop should exit on the first run, but i wanted to use the loop with a break just in case.

    Comment

    Working...
    X