Author Topic: [Solved]Get all map entities?  (Read 394 times)

zutokaza

  • Full Member
  • ***
  • Posts: 146
  • Active - Making stories can take the most time.
    • View Profile
[Solved]Get all map entities?
« on: June 01, 2017, 09:44:18 pm »
Is it possible make a NPC target entities with a prefix?

Code: Lua
  1. target_movement:set_target(map:get_entities("bird_"))
« Last Edit: June 06, 2017, 04:52:31 am by zutokaza »

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1043
    • View Profile
Re: Get all map entities?
« Reply #1 on: June 01, 2017, 11:24:04 pm »
Well a movement can only have one direction at a time, so you have to choose a target.
You can always make a loop to detect the closest entity from a list of entities, and repeat this in a timer.

zutokaza

  • Full Member
  • ***
  • Posts: 146
  • Active - Making stories can take the most time.
    • View Profile
Re: Get all map entities?
« Reply #2 on: June 02, 2017, 05:08:13 pm »
Quote
make a loop to detect the closest entity from a list of entities

How is that done? My script looks like this so far.

Code: Lua
  1. -- Call a function every second.
  2. sol.timer.start(5000, function()
  3.     local birds = map:get_entities("bird_")
  4.     local npc_near_birds = npc_1:get_distance(birds)
  5.     if npc_near_birds < 10 then
  6.        movement = sol.movement.create("target")
  7.        movement:set_target(birds)
  8.        movement:set_speed(48)
  9.        movement:start(npc_1)
  10.     end
  11.   return true  -- To call the timer again (with the same delay).
  12. end)

zutokaza

  • Full Member
  • ***
  • Posts: 146
  • Active - Making stories can take the most time.
    • View Profile
Re: Get all map entities?
« Reply #3 on: June 04, 2017, 04:47:02 am »
Can anyone give me an example? Please...  :D

ffomega

  • Full Member
  • ***
  • Posts: 212
    • View Profile
    • Solarus Resource & Tutorial Site
Re: Get all map entities?
« Reply #4 on: June 05, 2017, 01:50:45 pm »
I think the best example would be the "Evil Tile".  these are the tiles in dungeons that lift up and fly at the hero, one at a time, with a timed delay between each tile's movements.
My tilesets page can be found here:
http://absolute-hyrule-tutorials.solarus-games.org/

zutokaza

  • Full Member
  • ***
  • Posts: 146
  • Active - Making stories can take the most time.
    • View Profile
Re: Get all map entities?
« Reply #5 on: June 05, 2017, 08:36:50 pm »
I think the best example would be the "Evil Tile".  these are the tiles in dungeons that lift up and fly at the hero, one at a time, with a timed delay between each tile's movements.

Do you know what map and game the "Evil Tile" exists in?

Edit:
Found it.
https://github.com/solarus-games/zsdx/blob/dev/data/maps/evil_tiles.lua
« Last Edit: June 05, 2017, 09:04:17 pm by zutokaza »