Skip to content

OnPlayerUseItem

The player’s game consumed an item - the server is about to apply its effect; return false to cancel.

A potion drunk, food eaten, an ointment applied. The server looked the class up in the game’s tables (Consumables) and is about to add health to its own vitals (a potion’s heal-over-time runs at [combat] potion_speed times the game’s pace) and give the buff buff (GivePlayerBuff). Return false to cancel both

  • the item is gone from the player’s inventory either way, their game consumed it. Item classes the tables do not know never get here; a use of an item the player never held is refused by the inventory audit first. A drink raises the alcohol level on the side (OnPlayerDrunk).
function OnPlayerUseItem(pid, class, health, buff)
-- ...
end
Parameter Type
pid number the player
class string the item’s class GUID (GetItemName turns it into a name)
health number the health the server is about to add (a negative number hurts)
buff string the buff GUID the server is about to give; "" = none

false cancels the health and the buff; anything else lets them through

-- nothing heals in the arena; bandages (an Ointment) still stop the bleeding
function OnPlayerUseItem(pid, class, health, buff)
local info = GetItemInfo(class)
if inArena[pid] and info and info.category ~= "Ointment" and health > 0 then
SendClientMessage(pid, COLOUR_RED, "That does nothing in the arena.")
return false
end
end

GivePlayerBuff · OnPlayerDrunk · GetItemInfo · OnPlayerAuditViolation · the Buffs and the drink group of the index