What's a good A.I control module or plug-in?

Started by Icey, Sun 17/03/2013 23:33:01

Previous topic - Next topic

Icey

So I'm looking for a module or plug-in that would let me have certain character preform a task. Like let's say that in a game: The main character had to go through a locked door and the only way to open it was from another location, like on a platform above the door. The A.I character would go to that area and begin rotating a lever which opened the door. The door would stay open as long as the A.I. held the Lever so the main character needed to find a blockage that would hold the door open for good.

In a sense that's a bad example cause I just thought about another way to do this without a Module but instead having the player control the A.I character. I'm sure there's other better examples but I'm hoping that anyone would get the gist of what I'm asking for.

zabnat

Are you sure you need AI? Everything you describe in your use case can be accomplished in AGS script with relative ease. Also no module will probably provide these exact actions for the character to perform, so you would still have to do some scripting for it.

Khris

Yeah, how is a module supposed to help with that?
It's not like you can write a module that allows you to do cNpc.Command("Go to room 4, up the platform and hold the lever");

Everything you want it to do had to be added into the module separately, and in a way highly specific to your game, defeating the entire purpose or using a module in the first place.

A module is a collection of generally useful functionality, supposed to be able to be added to lots of different games.

Icey

Well that's why I said that was a bad example. Cause I could just make what I said into a cutscene showing the A.I go and preform that task. Or have the player manually take control of the A.I and go that task. I've done it that way before, it's just I couldn't think of a better example. What I'm really looking for or to do is making a "active" command that won't pause the game just to control the A.I.


Snarky

You can script other characters to do stuff in the background while the player is doing something else (i.e. non-blocking), and you don't need AI for that.

For example in Monkey Island, when you ask the store keeper to go see the swordmaster for you. He'll go off, and you can follow him (or not). Because his behavior is completely deterministic, you can just write it as a script, with triggers and a couple of global variables to keep track of his state (to determine whether he'll be in a certain screen when you enter it).

In adventure games, almost any behavior by other characters can most easily be implemented by regular scripting, where the actions they do are pre-defined responses to particular triggers. You'll rarely need any sort of AI. (Some games have some very simple AI routines just to have the other characters move around and do random stuff, because that's supposed to seem more realistic. I think the general feeling is that it's actually just annoying.)

Crimson Wizard

#5
Icey, what you need, is to learn how to make "state machine" running in the "repeatedly_execute" function (either in Room, or Global script, depending on situation).
But before that, try to write down the behavior logic "on paper".

In your case that may be simply as:
0. Initially the NPC is in "Follow the player" state.
1. If player walks near the door, set NPC's state to "Walking to the lever".
2. If NPC is at the lever, set the state to "Pulling the lever".
3. While in "Pulling" state, wait for player to return back.
4. As soon as player finished his business beyond the door, set the state to "Follow the player" (again).

The room script would be (primitive example):
Code: ags

enum NPCState
{
  eFollowPlayer,
  eWalkToLever,
  ePullLever
};

NPCState npc_state;

function Room_BeforeFadeIn()
{
   npc_state = eFollowPlayer;
   cNPC.FollowCharacter(player);
}

function repeatedly_execute()
{
   if (npc_state == eFollowPlayer)
   {
     if ( player is in region near door &&
          player_needs_to_go_beyond_door)
     {
       npc_state = eWalkToLever;
       cNPC.Walk(lever_pos_x, lever_pos_y, eNoBlock);
     }
   }
   else
   {
      if (player is somewhere too far from door)
      {
        npc_state = eFollowPlayer;
        cNPC.FollowCharacter(player);
      }
      else if (npc_state == eWalkToLever)
      {
        if (cNPC.x == lever_pos_x && cNPC.y == lever_pos_y)
        {
          npc_state = ePullLever;
          < Play animation or whatever >
        }
      }
   }
}



Another important idea is to think of every object as an individual, having its own behavior, not being strictly bound with actions of particular character. For example, lever can be pulled by player too, which means it should be scripted in such a way, that game should not care whether it is player, or NPC pulled the lever, and act the same.

Icey

@Snarky and Crimson: Ok I think just about understand now, I'm going try and test this out in test game. Just so I can get the hang of it.

SMF spam blocked by CleanTalk