Difference between revisions of "LUA:HasItem"

(Created page with "This function will return a true or false if a target has an item. ==== Syntax ==== HasItem(target, item_id) ==== Usage ==== <pre> Example(Player) if HasItem(Player, 1157) then...")
 
 
Line 1: Line 1:
This function will return a true or false if a target has an item.
+
{{PageHeaderChild|LUA|HasItem}}
 +
 
 +
= LUA Functions: HasItem() =
 +
Checks to see if the given player has an item
  
 
==== Syntax ====
 
==== Syntax ====
HasItem(target, item_id)
+
HasItem(param1, param2, [param3])
 +
 
 +
 
 +
==== Parameters ====
 +
; Required - ''param1'' (Spawn), ''param2'' (int32)
 +
: ''param1'' is the player we want to check
 +
: ''param2'' is the item id to check for
 +
; Optional - ''param3'' (int8)
 +
: ''param3'' is set to 1 to include the players bank
 +
 
 +
 
 +
==== Returns ====
 +
True if the player has the item
  
 
==== Usage ====
 
==== Usage ====
 
<pre>
 
<pre>
Example(Player)
+
function Deleted(Quest, QuestGiver, Player)
if HasItem(Player, 1157) then
+
    while HasItem(Player, 5642, 1) do
    Say(Player, "This thing smells.")
+
          RemoveItem(Player, 5642)
 +
    end
 
end
 
end
 
</pre>
 
</pre>
  
When Example() is called the if statement checks if the player has the item with an id of "1157" and if it passes the player says the string "This thing smells.".
+
This will delete all quests items when the quest is deleted
 
 
 
 
[[LUA:MiscFunctions|Back to LUA General Functions Index]]
 

Latest revision as of 00:04, 14 January 2016

LUA - HasItem

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


LUA Functions: HasItem()

Checks to see if the given player has an item

Syntax

HasItem(param1, param2, [param3])


Parameters

Required - param1 (Spawn), param2 (int32)
param1 is the player we want to check
param2 is the item id to check for
Optional - param3 (int8)
param3 is set to 1 to include the players bank


Returns

True if the player has the item

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