Difference between revisions of "LUA:RemoveItem"

(Created page with "Removes 1 of an item from a target, and returns a true or false if successful or not. ==== Syntax ==== RemoveItem(target, item_id) ==== Usage ==== <pre> function Deleted(Quest...")
 
 
Line 1: Line 1:
Removes 1 of an item from a target, and returns a true or false if successful or not.
+
{{PageHeaderChild|LUA|RemoveItem}}
 +
 
 +
= LUA Functions: RemoveItem() =
 +
Removes a single item from the player
 +
 
  
 
==== Syntax ====
 
==== Syntax ====
RemoveItem(target, item_id)
+
RemoveItem(param1, param2)
 +
 
 +
 
 +
==== Parameters ====
 +
; Required - ''param1'' (Spawn), ''param2'' (int32)
 +
: ''param1'' is the player we want to check
 +
: ''param2'' is the item id to remove
 +
 
 +
 
 +
==== Returns ====
 +
True if an item was removed
 +
 
  
 
==== Usage ====
 
==== Usage ====
<pre>
+
<pre>
 
function Deleted(Quest, QuestGiver, Player)
 
function Deleted(Quest, QuestGiver, Player)
    if HasItem(Player, 46842) then
+
    while HasItem(Player, 5642, 1) do
        if RemoveItem(46842) == true then
+
          RemoveItem(Player, 5642)
            Say(Player, "item removed")
+
    end
        end
 
    end
 
 
end
 
end
 
</pre>
 
</pre>
This will delete an item with the id of 46842 from a player if they have that item, when a quest with this function is deleted, and have the player say "item removed" if the item was removed correctly.
+
 
 +
This will delete all quests items when the quest is deleted
  
  
 +
==== Notes ====
 +
This only removes one instance of an item, so if you have a stack of 5 and call this function it will now be a stack of 4
  
[[LUA:MiscFunctions|Back to LUA General Functions Index]]
+
Can only be used on a player

Latest revision as of 00:08, 14 January 2016

LUA - RemoveItem

Return to: LUA | Tutorials | Portal | Forum | Project Manager | Bug Tracker


LUA Functions: RemoveItem()

Removes a single item from the player


Syntax

RemoveItem(param1, param2)


Parameters

Required - param1 (Spawn), param2 (int32)
param1 is the player we want to check
param2 is the item id to remove


Returns

True if an item was removed


Usage

function Deleted(Quest, QuestGiver, Player)
     while HasItem(Player, 5642, 1) do
          RemoveItem(Player, 5642)
     end
end

This will delete all quests items when the quest is deleted


Notes

This only removes one instance of an item, so if you have a stack of 5 and call this function it will now be a stack of 4

Can only be used on a player