I'm trying to make an AI that runs the player. I want it to be able to cause the player to take consecutive actions. The problem is that if I just try to write a loop, the game never updates the turn and so I just block execution.
What do I need to overwrite/hook/check to make sure that a move I have entered is executed fully, or alternately what do I check to make sure the game is waiting for player input? Ideally there is a function called when the game waits for player input that I can hook/superload to call my AI functions.
Looping around extended player actions
Moderator: Moderator
Looping around extended player actions
Currently developing the Player AI addon. You can get it from the T-Engine Addon Hub or Steam
You can also view the source code.
You can also view the source code.
Re: Looping around extended player actions
Here goes stupid idea coming from someone who never coded anything in this game:
have you tried to make it skip a turn and then, if condition still isn't met, repeat, and if it is, stop?
have you tried to make it skip a turn and then, if condition still isn't met, repeat, and if it is, stop?
Re: Looping around extended player actions
No idea on this one.
My feedback meter decays into coding. Give me feedback and I make mods.
-
- Uruivellas
- Posts: 708
- Joined: Wed Apr 30, 2008 5:55 pm
Re: Looping around extended player actions
You probably need to take a look at Player's :act function, as that's what waits for user input, I believe. So, like, you put a wrapper around it that, if a flag is set, calls the npc act function with a given ai (somehow) instead of the player one.
Addons: Arcane Blade Tweaks, Fallen Race, Monk Class, Weapons Pack
Currently working on Elementals. It's a big project, so any help would be appreciated.
Currently working on Elementals. It's a big project, so any help would be appreciated.

Re: Looping around extended player actions
Thanks guys. My current setup is to superload Player:act() and then check the game.pause flag (and my ai flag) like so:
And it's mostly working. For some reason now, every time I try to rest from the AI it gives me an error that a dialog is up so it can't rest. This is partially true, because the "You are resting..." dialog is open, except that shouldn't stop resting. If I can clean that up so the AI can rest again, I'll have a fully-functional (basic) AI that rests, auto explores, and walks into enemies it can see.
EDIT UPDATE: I added "and not game.player.resting" to the condition, and it still SAYS resting stopped because of dialog, but it seems to rest properly anyways. However, I have now learned that hotkeys don't work while the AI is active because of how I interact with the act() function, so I can't stop the AI once it's on, and it starts autoexploring back and forth between the level entrance and exit. Progress!
Code: Select all
local old_act = _M.act
function _M:act()
old_act(game.player)
if (not game.pause) and _M.ai_active then
player_ai_act()
end
end
EDIT UPDATE: I added "and not game.player.resting" to the condition, and it still SAYS resting stopped because of dialog, but it seems to rest properly anyways. However, I have now learned that hotkeys don't work while the AI is active because of how I interact with the act() function, so I can't stop the AI once it's on, and it starts autoexploring back and forth between the level entrance and exit. Progress!
Currently developing the Player AI addon. You can get it from the T-Engine Addon Hub or Steam
You can also view the source code.
You can also view the source code.