Hey, we have forums!

Author Topic: Big Energy-Form Battle  (Read 67916 times)

0 Members and 1 Guest are viewing this topic.

Offline Hiro

  • Hero Bit
  • *********
  • Posts: 674
  • Kriel's Legionary
    • View Profile
    • The Rat Hole
Re: Big Energy-Form Battle
« Reply #60 on: November 07, 2009, 10:36:52 am »
Ever the dutiful helpful developer.  ;)

Yeah, sorry calebj but I don't actually know scripting either (only some really basic understanding of how the system works) so I'm not the guy to ask. Good thing Alec is on the scene eh?  ^-^
My site is: http://www.therathole.co.nr/
Where I put pictures and blog posts and stuff..

Offline calebj

  • Bit
  • ***
  • Posts: 28
    • View Profile
Re: Big Energy-Form Battle
« Reply #61 on: November 08, 2009, 04:52:06 pm »
Thanks Alec,

It took me a little while to figure out but I got it eventually. 

Offline Alec

  • Administrator
  • Dream Bit
  • **********
  • Posts: 2211
    • View Profile
Re: Big Energy-Form Battle
« Reply #62 on: November 09, 2009, 08:59:41 pm »
Thanks Alec,

It took me a little while to figure out but I got it eventually. 

Glad to hear it! :)

Offline calebj

  • Bit
  • ***
  • Posts: 28
    • View Profile
Re: Big Energy-Form Battle
« Reply #63 on: November 09, 2009, 11:17:13 pm »
Ok, so I figured got how to get it to work if i type in the name of a specific entity but now I want the script to test if there are any enemies left at all.  I tried taking the part of edwards script for big energy-form battle but it still didn't work.  Any help would be appreciated.

Thanks, Caleb

Offline TheBear

  • Extra Bit
  • *****
  • Posts: 199
    • View Profile
    • http://doconnell.wordpress.com
Re: Big Energy-Form Battle
« Reply #64 on: November 10, 2009, 01:18:16 am »
Quote
dofile("scripts/entities/entityinclude.lua")

done = false
door = 0
numEnemies = 0

function init(me)   
   door = node_getNearestEntity(me, "energydoor")
end

function update(me, dt)
   if done == false then
      ent = getFirstEntity()
      while ent ~= 0 do
         if entity_getEntityType(ent) == ET_ENEMY then
            numEnemies = numEnemies + 1
         end   
         ent = getNextEntity()
      end   

      --all enemies killed -> open door
      if numEnemies == 0 then
         entity_setState(door, STATE_OPEN)
         done = true
      --reset for next test
      else
         numEnemies = 0
      end
   end
end
I suppose it'd be prettier to break out of the while loop as soon as you find an enemy but the script works (tested it out). The while loop finds exactly how many enemies are in the map each update and will open the door once there are none left.

Offline calebj

  • Bit
  • ***
  • Posts: 28
    • View Profile
Re: Big Energy-Form Battle
« Reply #65 on: November 11, 2009, 01:07:10 am »
Thank you so much!  I couldn't get it working at first then I realized how stupid I was and that it wasn't saved as a .lua. 

-Caleb

Offline calebj

  • Bit
  • ***
  • Posts: 28
    • View Profile
Re: Big Energy-Form Battle
« Reply #66 on: November 11, 2009, 02:40:52 am »
OK...sorry about all the questions and amendments  - you guys have been great.  One more thing (for now), so using Edwards' script you need to kill all of the enemies on the whole map to continue, but what if I only want to kill the enemies in a certain part of the map for the door to open?  I'd imagine you would have to specify what area the getFirstEntity should look in but I can't figure it out.  I think that's all the questions about this I have.

Offline Yogoda

  • Extra Bit
  • *****
  • Posts: 144
    • View Profile
Re: Big Energy-Form Battle
« Reply #67 on: November 11, 2009, 09:06:05 am »
getFirst/NextEntity return entities on the whole map, you have no way to change this.

But all you have to do is create a node covering the whole room where the enemies are. It can be the same node that is opening the door. Just make this small modification :

Quote
...
         if entity_getEntityType(ent) == ET_ENEMY and node_isEntityIn(me, ent) then
            numEnemies = numEnemies + 1
         end
...
« Last Edit: November 11, 2009, 02:18:59 pm by Yogoda »

Offline TheBear

  • Extra Bit
  • *****
  • Posts: 199
    • View Profile
    • http://doconnell.wordpress.com
Re: Big Energy-Form Battle
« Reply #68 on: November 13, 2009, 03:52:47 am »
Tag-team programming!

Offline calebj

  • Bit
  • ***
  • Posts: 28
    • View Profile
Re: Big Energy-Form Battle
« Reply #69 on: November 16, 2009, 01:35:53 am »
YES!! And they win!  Thanks!