Author Topic: LUA-question  (Read 11977 times)

Stephen

  • Administrator
  • Hero Member
  • *****
  • Posts: 259
Re: LUA-question
« Reply #45 on: November 06, 2016, 10:36:11 PM »
Hi,

Sorry for taking so long to reply... I somehow missed your post

I'm a little confused, what are you trying to do exactly?

ImpassIve_rus

  • Sr. Member
  • ****
  • Posts: 84
  • 0_o
Re: LUA-question
« Reply #46 on: November 07, 2016, 09:42:25 AM »
Hello, Stephen.

We have already changed the concept of the mod, so described questions are not so important anymore...

Anyway, we were planning to make a vampire, who could turn into a special bat (in a similar way, as it was implemented in Rat Riders mod: just replacing old monster with another one) to avoid lethal damage. This bat was supposed to run away from all knights and if it is still alive after XX seconds - it can turn back into a vampire form (fully regenerated, of course).

  1) Since we don't have much control over AI behaviour, we had an idea to fill "ai_fear" field with all possible knight weapons, but... yeah, now I see in the wiki - "ai_fear" is listed in "Walking monsters only" category.

  2) Then we had another idea: FlyingMonsterAI class from the source code has a "run_away_flag" variable, which forces flying creature to run away from the target. It is even possible to set it into "true" state via Lua script, by calling "kts.Damage" with zero amount of damage at each tile (or just frequently enough).

But there were a problem: it cannot be done from inside the "on_move" hook of the monster (see previous post), while other hooks are... not so reliable. Looks like Lua doesn't provide a way to run a function with specific time intervals?

Also, later we realised that a monster with constant "run_away_flag == 1" wouldn't run from the knight - it will run in the direction, pointed by knight's facing, so we had to abandon this concept.

  3) There were a backup plan: in some legends, vampires are turning into fog instead of bats, so we could use (1) case with walking type of monster. But a walking monster can easily be cornered, so this wouldn't add a lot to his survivability.

Anyway, as I mentioned in the beginning of the post, the concept of the mod has been changed and it doesn't require any manipulations over monster's behavious anymore.

EDIT:
Looks like Lua doesn't provide a way to run a function with specific time intervals?

Ah, my bad!
I haven't noticed the "kts.AddTask()" function...
« Last Edit: November 07, 2016, 03:29:55 PM by ImpassIve_rus »


Stephen

  • Administrator
  • Hero Member
  • *****
  • Posts: 259
Re: LUA-question
« Reply #47 on: November 07, 2016, 07:30:48 PM »
OK, that mod does sound interesting.

I did once have an idea to make AI controllable from Lua, so that you could write little Lua scripts to control what a monster does. That would be quite a lot of work though.

There's no good reason why ai_fear should be walking monsters only... it just needs to be implemented in the FlyingMonsterAI as well. (The only reason it wasn't implemented, is because it was only needed for zombies at the time.) I guess I could do that sometime.

If I ever make another indie game, I will put the scripting in from the beginning, instead of tacking it on at the end like I did with Knights... that is the cause of most of these problems I think :)

ImpassIve_rus

  • Sr. Member
  • ****
  • Posts: 84
  • 0_o
Re: LUA-question
« Reply #48 on: November 07, 2016, 07:55:09 PM »
An offtop note:
hey, looks like I've got a personal remote-controlled monster!


Stephen

  • Administrator
  • Hero Member
  • *****
  • Posts: 259
Re: LUA-question
« Reply #49 on: November 08, 2016, 06:22:01 PM »
Nice, I like it ;)