Page 8 of 8

Re: How to check which item is in alcove?

Posted: Mon Feb 17, 2014 8:58 pm
by LordofKral
germanny wrote:

Code: Select all

for i in entitiesAt(place.level,place.x,place.y) do
        if i.name == "that_item" then
		hudPrint("Your item is found: "..i.name)
	else return false
        end
end
Forgot to paste the 'end' parts^^

No problem XD

Re: How to check which item is in alcove?

Posted: Mon Mar 10, 2014 7:18 pm
by THOM
Funny thing with this script:

Code: Select all

  function checkPoison()
         for i in mouth_socket_poison_1:containedItems() do
             if i.name == "potion_poison"
            then
                playSound("consume_potion")
           	timer_poison_door:activate()
                setMouseItem(spawn("flask"))
 --               containedItems:destroy()
              return
             end
          end
           
        end
The sound is played, the timer is activated - but no flask appears in the mousepointer.. ????

And apart from that: I also try to destroy the poison potion in the mouth-socket (in the script above still disabled with -- ) but I can't figure out how to do that... :-(

Re: How to check which item is in alcove?

Posted: Mon Mar 10, 2014 7:50 pm
by DesperateGames
I think setting the mouse item might not work because the engine will execute the script first which will set the item under the mouse cursor to the flask and then deletes the item from your mouse cursor. (Wild guessing here...) I just tried a similar thing with a pressure plate and it did not work for me as well: When I walked on the plate, it was possible to add something under the mouse cursor, if I put an item on the plate it did not work. It works however if you start a timer with a 0.001 second interval which then creates the flask under the cursor ;-)

Regarding destroying the potion: if you use i:destroy() instead of containedItems:destroy() it should work.

Re: How to check which item is in alcove?

Posted: Mon Mar 10, 2014 8:14 pm
by THOM
Perfect - works!!! :idea:

Hey DesperateGames - are you the scripting-expert or what?? :D

Re: How to check which item is in alcove?

Posted: Mon Mar 10, 2014 8:42 pm
by DesperateGames
Ah nah, there are people here on the forum which can do far more impressive things than I could, but I'm keeping an eye on the forum as it is the perfect excuse for taking a break from work and typing a response ;)

Re: How to check which item is in alcove?

Posted: Tue May 27, 2014 1:04 am
by Darsithis
I'm trying something posted earlier in the thread:

Code: Select all

function CheckPlantAlcove()

	for alcoveItem in plantAlcove:containedItems() do
		print (alcoveItem.name)
	end
	
	if containsItems(plantAlcove, "cave_nettle") 
		and containsItems(plantAlcove, "tar_bead")
		and containsItems(plantAlcove, "slime_bell")		
		and containsItems(plantAlcove, "blooddrop_blossom")		
		and containsItems(plantAlcove, "grim_cap")	
		and containsItems(plantAlcove, "milkreed")
	then
		plantDoor:open()
		plantSecret:activate()
	else
		plantDoor:close()	
	end
end

function containsItems(entity, item)
   for i in entity:containedItems() do
      if i.name == item then
         return true
      end
   end
   -- if we get here the item was not found
   return false
end
The idea is that after you put 1 of each of the 6 potion ingredients in the alcove, the door and secret will execute. The print(alcoveItem.name) however shows that it only executes once, ever, for the first item placed. Subsequent items placed in the alcove do not execute the script. Any ideas why?