allow a NPC to move while the player move

Started by deltree, Fri 26/09/2003 22:59:23

Previous topic - Next topic

deltree

hi,
I've a problem to solve:
I want my NPC to move around, just like a people in normal life, while I walk too.
but I can't do that!
when they move, I can't move myself, and vice-versa.
is there a way to do it?
NB: I don't want them to just "follow a line and stop", I want them to go repeatedly along a path for example.
If anyone have ever done it...

delta

you should show us the code you are currently using so we can point out mistakes.

Are you using movecharacterbloking? DON'T for NPCs.

You could also try the ccs_plugin with will move NPCs in the background until you stop them.

deltree

by using a timer properly, I can do it.

a-v-o

MoveCharacterPath might be helpful to create predefined paths. In repeatedly_execute you can check the last coordinates and when the character arrives there, then e.g. restart moving.
Defining several paths you can choose the next path by random.

deltree

Ok,
finally, I've used the movecharacter solution, but the problem with that instruction is that , for example, if you do this:

movecharacter(location 1);
movecharacter(location 2);

then the character will move directly to location 2.
Because he doesn't wait for the first insctruction to finish , he does the 2nd directly.
The only way to do it, is to FORCE the program to run the first instruction completly, that is to say, move the character to location 1 THEN to location 2

3 solutions for that:

1st: using a timer. between the first and the second, I will use a timer long enough for the 1st instruction to run fully.this solution is not very good indeed.

2nd: don't run the second until the location 1 has been reached. this solution is the best.

3rd: running the second instruction ONLY if character is NOT walking anymore.

Scummbuddy

why not try using this and make it nonblocking
------------------------
AnimateCharacterEx
AnimateCharacterEx (CHARID, int loop, int speed, int repeat, int direction, int blocking)

As AnimateCharacter, but with two extra options:
DIRECTION specifies which way the animation plays. 0 is forward (like AnimateCharacter), or pass 1 to play the loop backwards.

If BLOCKING is 1, the function will wait for the animation to finish before returning.

See the description of AnimateCharacter for more information.

Example:

AnimateCharacterEx(EGO, 3, 0, 0, 1, 1);

will animate the character once using loop number 3 of his current view backwards, and wait until the animation finishes before returning.
- Oh great, I'm stuck in colonial times, tentacles are taking over the world, and now the toilets backing up.
- No, I mean it's really STUCK. Like adventure-game stuck.
-Hoagie from DOTT

deltree

#6
It's ok, all these function are about the same (movecharacterblocking, movecharacterdirect...)

The basic one,  "movecharacter" is a non-blocking function.
it's the one I'm using.

the one you give me don't really solve the problem.
however, there's no more problem, I fixed it already, but thanx!

Timosity

#7
To do multiple non-blocking movements and animations of NPC's, it is possible but may require a bit of scripting.

Here's an example:

 // script for room: Repeatedly execute

if (GetGlobalInt(10)==1){ // set global int 10 to 1 to start things rolling (anywhere in the script)
MoveCharacter(NPC,248, 147);
SetGlobalInt(10,2); // for next stage
}


if (GetGlobalInt(10)==2){
if (character[NPC].walking == 0) { // this is a key line, uses an 'if' instead of a 'wait'
DisplaySpeech(NPC,"Hello");
Wait(1);
MoveCharacter(NPC,222, 157);
SetGlobalInt(10,3); // for next stage
}
}

if (GetGlobalInt(10)==3){
if (character[NPC].walking == 0) {
SetCharacterView(NPC,5);
AnimateCharacter(NPC,0,5,0);
SetGlobalInt(10,4); // for next stage
}
}

if (GetGlobalInt(10)==4){
if (character[NPC].animating == 0) { // this is a key line, uses an 'if' instead of a 'wait'
ReleaseCharacterView(NPC);

etc etc etc
}
}


This works fine, and I've used it many times before, It lets you have complete control of the player character while NPC's do whatever you want them to.

Hope this helps

~Tim

Sockmonkey

Hey guys!

I have been trying for days to do this (in a simpler way) with no luck. I am trying to make a character pace between two points within the same room (as though he is guarding something)...I've tried all of the solutions listed here with no luck. I get either one of two possible outcomes, 1. the NPC follows the path perfecty, but the player character cannot move or 2. The NPC seems to run in place. Here is my code as it stands, perhaps someone can see what I cannot. (the character is COP and the coordinates are 74, 169 and 259, 155 (the characters starting position)


THANKS!

 // script for room: Repeatedly execute
MoveCharacter (COP, 74, 169);
MoveCharacter (COP, 259, 155);


}

http://www.sockmonkeygame.com

"Never hold discussions with the monkey when the organ grinder is in the room." -Sir Winston Churchill

a-v-o

OK, here is the tested script with 2 versions of repeatedly_execute. The first one is easier, but the NPC moves directly ignoring walking areas and stuff. I used 3 waypoints to show how more complex paths can be defined.

// --- room script file ---

int GUARD_CHAR = BERN;
#define GUARD_SX 308
#define GUARD_SY 129
#define GUARD_EX 400
#define GUARD_EY 136

function room_a() {
 // script for room: Player enters screen (before fadein)

 // set start position
 character [GUARD_CHAR].x = GUARD_SX;
 character [GUARD_CHAR].y = GUARD_SY;
}

1. version of repeatedly_execute

function room_b() {
 // script for room: Repeatedly execute
 if (character [GUARD_CHAR].walking <= 0)
 {
   if (character [GUARD_CHAR].x <= GUARD_SX)
   {
     MoveCharacter (GUARD_CHAR, GUARD_EX, GUARD_SY);
     MoveCharacterPath (GUARD_CHAR, GUARD_EX, GUARD_EY);
     MoveCharacterPath (GUARD_CHAR, GUARD_SX, GUARD_SY);
   }
 }
}

2. version of repeatedly_execute

function room_b() {
 // script for room: Repeatedly execute
 if (character [GUARD_CHAR].walking <= 0)
 {
   if (character [GUARD_CHAR].x <= GUARD_SX)
   {
     MoveCharacter (GUARD_CHAR, GUARD_EX, GUARD_SY);
   }
   else if (character [GUARD_CHAR].y <= GUARD_SY)
   {
     MoveCharacter (GUARD_CHAR, GUARD_EX, GUARD_EY);
   }
   else
   {
     MoveCharacter (GUARD_CHAR, GUARD_SX, GUARD_SY);
   }
 }
}


Sockmonkey

a-v-o

This works perfectly! Exactly what I was looking for. You've saved my game.

Thanks!

http://www.sockmonkeygame.com

"Never hold discussions with the monkey when the organ grinder is in the room." -Sir Winston Churchill

SMF spam blocked by CleanTalk