Thanks, yaflhdztioxo. Only three of those being hooks are documented on the wiki.
Does being:wear(item) work on weapons, and does it work for items that aren't in the inventory? I'm trying to implement a grenade weapon that is stored in stacks in the inventory but is equipped one at a time. I've got this:
register_item "hl_grenade" { --delayed explosion requires more hooks
name = "Hand Grenade",
desc = "Good thing you can throw accurately.",
ascii = "*" ,
color = BROWN,
sprite = SPRITE_ROCKET,
glow = {1,0,0,0.5},
level = 6,
weight = 200,
flags = {IF_NONMODABLE, IF_NOAMMO},
firstmsg = "These could come in handy.",
color_id = "generic",
--type specific
type = ITEMTYPE_RANGED,
damage = "5d5",
damagetype = DAMAGE_FIRE,
group = "weapon-rocket",
fire = 10,
acc = 0,
radius = 4,
shots = 0, --setting to 1 leads to x1 being appended to name, which is seriously confusing here
ammo_id = "shell", --not actually used
ammomax = 0,
reload = 10,
shotcost = 0,
altfire = ALT_NONE,
--altfirename = "double shot",
altreload = RELOAD_FULL,
--altreloadname = "dualreload",
--sound_id = "shotgun",
missile = "hl_grenade_missile",
psprite = SPRITE_PLAYER, --the sprite used to represent the player when equipped
OnCreate = function(self)
self:add_property("quantity", 2)
self:add_property("base_name", self.name) --used by test.SetNameFromQuantity
test.SetNameFromQuantity(self)
end,
OnEquipCheck = function(self, equipper)
if self:get_property("quantity") == 1 then return true end
self:set_property("quantity", self:get_property("quantity") - 1)
test.SetNameFromQuantity(self)
local spawned = item.new(items[self.id].nid) --spawn a new grenade item with 1 quantity
spawned:set_property("quantity", 1) --set quantity
test.SetNameFromQuantity(spawned)
if player:wear(spawned) == true then ui.msg("success") else ui.msg("fail") end --equip the new item
return false --don't equip this item
end,
}
When I attempt to equip a stack of more than 1 grenade, I get the message "success", the size of the stack decreases by 1 but the grenade isn't equipped. Equipping a single grenade works.
Also, it turns out that being.inv:add() does work on monsters. Thanks SPTX for suggesting that - I thought I'd tried it before but evidently not.
EDIT: What sound IDs exist that are appropriate for explosions?