Sorry Jkos I don't know what you mean with this script sorry.JKos wrote:Well you can do it by scripting for example like this:
herder_ai_test script entityjust call herder_ai_test.script.onThink(self) from the onThink hook. But floor trigger works too of course.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
Brains
- Eleven Warrior
- Posts: 752
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: Brains
Re: Brains
JKos's script is step by step script ^^Eleven Warrior wrote:Sorry Jkos I don't know what you mean with this script sorry.
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
Re: Brains
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.
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
- cloneObject viewtopic.php?f=22&t=8450
- Eleven Warrior
- Posts: 752
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: Brains
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
}
}
}
Re: Brains
You shoud do it like this:
End then add a scpit-entity to your dungeon and name it as herder_ai_test. Then copy paste this in it:
Edit: fixed the code
Code: Select all
defineObject{
name = "herder_test_3",
baseObject = "herder",
components = {
{
class = 'Brain',
onThink = function(self)
herder_ai_test.script.onThink(self)
end
}
}
}
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
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
- cloneObject viewtopic.php?f=22&t=8450
Re: Brains
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
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
