Brains

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Eleven Warrior
Posts: 736
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Brains

Post by Eleven Warrior »

JKos wrote:Well you can do it by scripting for example like this:


herder_ai_test script entity

Code: Select all

state = "begin"

function onThink(self)
	if state == "begin" and self.partyLastSeen ~= 0 then
		if self:goTo("lever_1") then
			state = "operate"
		end
	end
	if state == "operate" then
		lever_1.lever:toggle()
		state = "end"
	end
end
just call herder_ai_test.script.onThink(self) from the onThink hook. But floor trigger works too of course.
Sorry Jkos I don't know what you mean with this script sorry.
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: Brains

Post by Doridion »

Eleven Warrior wrote:Sorry Jkos I don't know what you mean with this script sorry.
JKos's script is step by step script ^^

Local data gives the state of the script like that :
1 - Begin = herder didn't see the party yet
2 - Operate = herder seen the party and go to the lever
3 - End = herder gone to the lever, the lever self activated

The only problem, is that the lever self activate in same time that the herder begin to move. If I all understood :p
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Brains

Post by JKos »

You have to think a bit diffrently when using onThink-hook, because it gets called every time after the monster has made his previous move/action. Just try that script and add print(state) to the first line of onThink-method, put the herder_test a few squares away from lever_1, and you will see that every time the monster moves to the next square the state will be printed.

self:goTo(entity) returs true when the monster has reached it's destination. So the state is changed to "operate" after that, and the lever:toggle() get's called on next onThink-cycle.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Eleven Warrior
Posts: 736
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Brains

Post by Eleven Warrior »

Hi Jkos I seem to lost as usual I tried this thinking it was correct but I failed, Sorry about this. I know something's wrong with this cause it give me a error.

Code: Select all

defineObject{
   name = "herder_test_3",
   baseObject = "herder",
   components = {
   {
      class = 'Brain',
	  state = "begin"

function onThink(self)
   if state == "begin" and self.partyLastSeen ~= 0 then
      if self:goTo("lever_1") then
         state = "operate"
      end
   end
   if state == "operate" then
      lever_1.lever:toggle()
      state = "end"
   end
end

   }
}
}
User avatar
JKos
Posts: 464
Joined: Wed Sep 12, 2012 10:03 pm
Location: Finland
Contact:

Re: Brains

Post by JKos »

You shoud do it like this:

Code: Select all

defineObject{
   name = "herder_test_3",
   baseObject = "herder",
   components = {
   {
      class = 'Brain',
      onThink = function(self)
            herder_ai_test.script.onThink(self)
      end
   }
}
}
End then add a scpit-entity to your dungeon and name it as herder_ai_test. Then copy paste this in it:

Code: Select all

state = "begin"

function onThink(self)
   print(state)
   if state == "begin" and self.partyLastSeen ~= 0 then
      if self:goTo("lever_1") then
         state = "operate"
      end
   end
   if state == "operate" then
      lever_1.lever:toggle()
      state = "end"
   end
end
Edit: fixed the code
Last edited by JKos on Wed Oct 29, 2014 8:12 pm, edited 1 time in total.
- LoG Framework 2http://sites.google.com/site/jkoslog2 Define hooks in runtime by entity.name or entity.id + multiple hooks support.
- cloneObject viewtopic.php?f=22&t=8450
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: Brains

Post by Doridion »

JKos, you didn't specified "where" putting the first part of code ( I think that's what said Eleven Warrior ).

So Eleven, first part of the JKos code is going to the "Monster.lua" file in your dungeon folder ( My docs/Almost Humans/.../mod_assets/scripts ). The "defineObject" is always used to declare a new/clone object/monster in LoG ( 1 & 2 ). After, you launch LoG2 Editor and search for "herder_test_3" entity, placing it, creating script and copying script code into it.

Yes, I know i'm boring, but some new modders don't even know difference between script codes and objects definitions, and where to place them, so i try to help as I can ;)
Post Reply