How can I animate character, so that when player enters the room, the npc player is walking "around" all the time. When player tries to talk to him, he stops moving and starts to talk.
Thanks!
in room repeadetly_execute:
if (character[NPC].walking == 0) {
MoveCharacter(NPC, Random(319), Random(199));
}
This will move the NPC (replace the ID if you use a diffrent one) completely randomly around the walkable areas they can reach. If the talking to the character don't work properly, let us konw. I'm not sure if the engine will try to move the charcter while in a dialog...
(Ishmael posted while I was typing, but I'll post this anyway)
Or, to have NPC walking a path, you use MoveCharacterPath () (or Character[CHARID].AddWaypoint in new scripting). So, you'd have something like this, in repeatedly_execute (the comment-ed script is the new way, in case you're using 2.7):
if (character[NPC].walking == 0) { // if (cNPC.Moving == 0) {
MoveCharater (NPC, X1, Y1); // cNPC.Walk (X1, Y1);
MoveCharacterPath (NPC, X2, Y2); // cNPC.AddWaypoint (X2, Y2);
MoveCharacterPath (NPC, X3, Y3); // cNPC.AddWaypoint (X3, Y3);
// And so on
}
This has been asked before, so a search should turn up more detailed answers and a few different options, if you want/need them.
As Ishmael said, when you start talking to NPC (if you use a dialog, at least) the game is technically paused - the rep_ex isn't run, so NPC should stop moving to talk to you. If it doesn't work, you could use a variable to check whether NPC should be moving or not, e.g.:
if (character[NPC].walking == 0 && talknpc == 0) { // if (cNPC.Moving == 0 && talknpc == 0) {
Then, change the variable when talking:
talknpc = 1;
DisplaySpeech (EGO, "Can I talk to you for a minute?"); // cEgo.Say ("Can I talk to you for a minute?");
DisplaySpeech (NPC, "Sure!"); // cNpc.Say ("Sure!");
DisplaySpeech (EGO, "..."); // cEgo.Say ("...");
DisplaySpeech (EGO, "Thanks!"); // cEgo.Say ("Thanks!");
talknpc = 0;
Thanks they worked!
But how can I make it so, that they move to correct place to start talking? Now it could be that, they are shouting from a miles away :)
Extra question:
But what if I want, that when the NPC has walked enough he moves away from the room and disappear? Is this possible?
Sure. Just see the MoveCharacter* commands, and look into timers; SetTimer() and IsTimerExpired() ;)