Hi,
I'm sure it's not difficult but i don't find what i want ...
How can i check if the player have a X item ?
For example, a NPC block the path if the player have not the lamp.
Thanks
With game:get_item():get_variant() you can check the possession value of the item :)
http://www.solarus-games.org/doc/latest/lua_api_item.html#lua_api_item_get_variant
Don't forget the item name parameter in game:get_item(). So it would be:
game:get_item("bow"):get_variant() == 0
or a shorter equivalent:
game:get_item("bow"):has_variant()
I didn't find where is "get_item()" in the documentation.
so i try like you said :
local map = ...
function map:on_started()
if map:get_item("lamp"):get_variant() == 1 then
_13_NPC00:set_enabled(false)
end
end
but it does not work :
ror: In on_started: [string "maps/Map13/13.lua"]:4: attempt to call method 'get_variant' (a nil value)
get_item() is a function of game, not map.
See http://www.solarus-games.org/doc/latest/lua_api_game.html#lua_api_game_get_item
And now that I see the doc, there is an even shorter solution:
game:has_item("lamp")
Sorry for the name of the item, I posted the answer yesterday just before going to work aaaaaaaand.... I did not double check my post :) I wanted to indicate also where the get_item was on the doc, but good point for the "has_item" : I knew there was a shortcut, but didn't remember the location (and I didn't search a lot yesterday :p).
I try this :
local map = ...
function map:on_started()
if map:get_game():has_item("lamp") == true then
_13_NPC00:set_enabled(false)
end
end
But i never see my NPC like if i always have the lamp :(
EDIT : I'm just a retard who put a fail line in the code ....