Check Item

Started by Yruama, December 03, 2014, 12:00:45 AM

Previous topic - Next topic

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.


With game:get_item():get_variant() you can check the possession value of the item :)

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:

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

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.

And now that I see the doc, there is an even shorter solution:

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).

December 04, 2014, 06:51:40 PM #6 Last Edit: December 09, 2014, 09:05:18 PM by Yruama
I try this :

local map = ...

function map:on_started()
if map:get_game():has_item("lamp") == true then

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 ....