How do I get NPC's to walk around freely, going about there business WHILE I retain control of EGO? Something to do with Blocking, I wager, but I'm not sure which commands.
Could someone put up a simple script that could make a character walk from A to B, say something, B to C, say something, C to A, repeat. All while I can freely move EGO and maybe interrupt to talk to them, letting them continue afterwards. That mechanic dude from the start of Beneath A Steel Sky comes to mind.
Seek and you shall find:
http://www.adventuregamestudio.co.uk/yabb/index.php?topic=19441.msg236863#msg236863
I guess I really am a beginner. I eventually figured out (on my own), to paste his text into a run script in the room interaction dialog under repeatedly execute. But it still only gave me varying degrees of success (By that I mean, once he moved to one location and said something then kept saying it over and over, the other times he would just sit there and say one thing over and over). And yes, I renamed my character to match his and I tried altering his coordinates to some that wouldn't put the character outside the room.
Could someone be more specific about it. I mean, assume I've just started a default game and I want to move a new character called NEW. What would I do?
I'm sure it's just a matter of fixing the coordinates.
Please post the script you have now so we know what coordinates you want.
Well. I got it. I mustn't have tried the right combination of things before. Here's exactly what I did. This is after a lot of messing around... I went into the Room Interaction Dialog (little "i" icon), added a "Run script" under "Repeatedly execute", and pasted this...
------------------------------------------------------------------------------------
Ã, // script for room: Repeatedly execute
Ã, if (character[NEW].walking == 0) {
Ã, Ã, if (character[NEW].x == 150 && character[NEW].y == 150) {
Ã, Ã, Ã, DisplaySpeech(NEW, "Starting my walk now.");
Ã, Ã, Ã, MoveCharacter(NEW, 200, 75);
Ã, Ã, }
Ã, Ã, else if (character[NEW].x == 200 && character[NEW].y == 75) {
Ã, Ã, Ã, DisplaySpeech(NEW, "Finished 1st path.");
Ã, Ã, Ã, DisplaySpeechBackground(NEW, "Now at 200x75");
Ã, Ã, Ã, SetCharacterView(NEW,2);
Ã, Ã, Ã, AnimateCharacter(NEW,0,8,0);
Ã, Ã, Ã, while(character[NEW].animating) Wait(80);
Ã, Ã, Ã, ReleaseCharacterView(NEW);
Ã, Ã, Ã, MoveCharacter(NEW, 100, 100);
Ã, Ã, }
Ã, Ã, else if (character[NEW].x == 100 && character[NEW].y == 100) {
Ã, Ã, Ã, DisplaySpeech(NEW, "Finished 2nd path.");
Ã, Ã, Ã, DisplaySpeech(NEW, "Now at 100x100.");
Ã, Ã, Ã, MoveCharacter(NEW, 150, 75);
Ã, Ã, }
Ã, Ã, else if (character[NEW].x == 150 && character[NEW].y == 75) {
Ã, Ã, Ã, DisplaySpeech(NEW, "Finished 3rd path.");
Ã, Ã, Ã, DisplaySpeech(NEW, "Now at 150x75.");
Ã, Ã, Ã, MoveCharacter(NEW, 75, 150);
Ã, Ã, }
Ã, Ã, else if (character[NEW].x == 75 && character[NEW].y == 150) {
Ã, Ã, Ã, DisplaySpeech(NEW, "Finished 4th path.");
Ã, Ã, Ã, DisplaySpeech(NEW, "Now at 75x150.");
Ã, Ã, Ã, DisplaySpeechBackground(NEW, "It's a long walk over here");
Ã, Ã, Ã, MoveCharacter(NEW, 300, 200);
Ã, Ã, }
Ã, Ã, else {
Ã, Ã, Ã, DisplaySpeech(NEW, "Finished last path.");
Ã, Ã, Ã, DisplaySpeech(NEW, "Now at 300x200.");
Ã, Ã, Ã, MoveCharacter(NEW, 150, 150);
Ã, Ã, }
Ã, }
------------------------------------------------------------------------------------
... As you can see I modified it a bit. I'm not sure why, but the original had him saying which path he had done at the wrong time. So I fixed it and also made him say what x and y coordinates he was at, on another line. Also added an "AnimateCharacter" so it switches to a loop on another view, plays it at 8 speed (slow), waits for 80 cycles (2 seconds), Then releases the view (back to the walking one) so he can move to the next coordinates. He also says a few lines while walking at the same time with "DisplaySpeechBackground".
Basically that fixes all my issues. It was all about where to paste the script. What was the bit at the start of the original script about...
-----
function room_a() {
-----
That was screwing me up as it didn't need to be pasted. And there was an extra "}" at the end.
I'm putting this here for other script rookies like myself. This is all thanks to strazer's original script of course, so, big thanks to strazer. I do have one last small issue. The "DisplaySpeech" makes the mouse pointer go into thinking mode (can't tell the player character to do anything). It's not that bad because the player character will still move and do what he was doing before the "DisplaySpeech", but it would be nice to fix if possible.
QuoteWhat was the bit at the start of the original script about...
This and the extra brace at the end are the header and footer of the room's repeatedly execute function. They are generated automatically and you won't see them if you open the script through the interaction editor, only when opening the whole room script via the "{}" button.
I wrote them in my script example to show where to paste it.
Quote
The "DisplaySpeech" makes the mouse pointer go into thinking mode (can't tell the player character to do anything). It's not that bad because the player character will still move and do what he was doing before the "DisplaySpeech", but it would be nice to fix if possible.
If you only want to disable the wait cursor for DisplaySpeech commands, you could define a custom function that you can call instead of the regular DisplaySpeech command:
// main global script
function myDisplaySpeech(int charid, string text) {
int oldmode = GetCursorMode(); // save current cursor mode
SetCursorMode(7); // change cursor mode to wait
SetMouseCursor(oldmode); // change wait mode cursor graphic to previous mode
DisplaySpeech(charid, text);
SetDefaultCursor(); // change wait mode cursor graphic back to default sprite
SetCursorMode(oldmode); change cursor mode back to previous mode
}
// Main header script
import function myDisplaySpeech(int charid, string text); // to make function available in room scripts