Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Author Topic: NPC and objects  (Read 3721 times)

0 Members and 1 Guest are viewing this topic.

YO

  • Our first adventure:
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
NPC and objects
« on: October 27, 2010, 03:39:52 PM »

Hi, (sorry but my english is not very good) I'm new here and I have a few weeks trying to create a game, my problems are several, some of these are:
- How do I make a NPC that is in a room to react and do not let me pick up an object? or how to make an NPC speak if I pick up an object, I try some code but no one runs well, the NPC has a code in Scene_init like this:(thanks to HelLRaiseR for the code)
Code: [Select]
var NPC = Scene.LoadActor("actors\molly2\molly2.actor");
NPC.SkipTo(300, 300);
var cocineroOcupado = false; // Para saber si el cocinero
var tiempoInicio = 0;
var sitioCocinero = 0; // 0 esta en la mesa, 1 esta en la despensa

while (true) // Este bucle se va a repetir siempre.
{
if (NPC.Ready) // Esto comprueba si un actor esta en su evento Idle, o sea no esta haciendo nada como andar, hablar u otra cosa
{
if(cocineroOcupado == false)
{
// Puesto que entramos aqui, el cocinero no esta haciendo nada, o sea, esta en la animacion idle, cortando sus cosas en la mesa.
cocineroOcupado = true; // Le ponemos como ocupado para que no salte el evento constantemente.
tiempoInicio = Game.CurrentTime; // Inicializamos el tiempo inicial, que es desde donde empezamos a contar para lanzar el evento cada x tiempo.
}
else
{
if (Game.CurrentTime - tiempoInicio > 10000) // Ya estando ocupado entrara por aqui y comprobamos si han pasado los 30 segundo, tiene puesto 30.000 porque WME cuenta en milisegundos.
{
if (sitioCocinero == 0) // Si el cocinero esta en la mesa
{
NPC.Direction=DI_UP;
NPC.GoTo(485,525); //Le decimos al cocinero que vaya a la despensa.
NPC.Active = false;
Sleep(3000);
NPC.Direction=DI_DOWN;
NPC.Active = true;
sitioCocinero = 1; // Marcamos como que esta en la despensa
}
}
if (Game.CurrentTime - tiempoInicio > 20000) // Ya estando ocupado entrara por aqui y comprobamos si han pasado los 30 segundo, tiene puesto 30.000 porque WME cuenta en milisegundos.
{

if (sitioCocinero == 1) // Si el cocinero esta en la mesa
{
  switch(Random(0, 2))
{

case 0:
// say something and wait
NPC.Talk("Que asco de vida!!! todo el dia cocinando!!!");
Sleep(100);
break;
     
     
case 1:
// walk around
NPC.GoTo(300,550);
Sleep(100);
NPC.GoTo(590,550);
Sleep(100);
break;
     
case 2:
// play some animation
NPC.GoTo(534, 535); //Le decimos al cocinero que vaya a la despensa.
NPC.GoTo(469, 569);
Sleep(100);
break;
}
tiempoInicio = Game.CurrentTime;
sitioCocinero = 0;

}
}
}
}
else
{
cocineroOcupado = false; // Si el cocinero esta haciendo algo como andar o hablar lo ponemos ocupado para que esto no interfiera con los eventos de WME.
}
Sleep(100); // Hacemos una parada, esto es importante para darle tiempo a WME para que procese otros eventos, si no se embucla y se cuelga.
}
the code works but if I want the NPC says something if I take an object the program give me an error
the book.script is
Code: [Select]
on "Take"
{
  actor.Talk("blah");
  NPC.Talk("blah");
}
but NPC don´t talk anything

can you help me?
thanks
Logged
Henry y El libro magico, proximamente sacaremos la demo en español...
Henry and the magic book, demo coming soon in English

HelLRaiseR

  • I don't want to make a Monkey Island clone :(
  • Wiki editor
  • Frequent poster
  • ****
  • Karma: 4
  • Offline Offline
  • Posts: 270
    • View Profile
    • Adventure Box Studios
Re: NPC and objects
« Reply #1 on: October 27, 2010, 07:38:05 PM »

Hi YO,

I'm afraid that you have an error.

In the first script (scene_init) the var NPC is a local object, but in the Talk event the var NPS isn't declare, I suppose that in this case you uses a global var.

Logged
Regards,

    Fernando

YO

  • Our first adventure:
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
Re: NPC and objects
« Reply #2 on: October 27, 2010, 07:44:16 PM »

I dont know how to make a global NPC, in book.script only write this:
Code: [Select]
var NPC = Scene.GetNode("NPC");
////////////////////////////////////////////////////////////////////////////////
on "Take"
{
  actor.Talk("blah");
  molly2.Talk("blah");
}

how i wrote that, its very dificult to me
XD


Logged
Henry y El libro magico, proximamente sacaremos la demo en español...
Henry and the magic book, demo coming soon in English

eborr

  • Regular poster
  • ***
  • Karma: 4
  • Offline Offline
  • Posts: 196
    • View Profile
Re: NPC and objects
« Reply #3 on: October 28, 2010, 08:33:16 AM »

you can make a variable global by using the prefix global

Code: [Select]
var anumber = 1;

// is only visible to the current script


where as

Code: [Select]
global anumber = 1;
// is available throughout the game
One comment to make though is that you need to declare a global variable in each script that may require it, that was something that caught me out.  If you want  to avoid this then you can put the declaration in one of the .inc files.
Logged

YO

  • Our first adventure:
  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 32
    • View Profile
Re: NPC and objects
« Reply #4 on: October 28, 2010, 01:30:57 PM »

thanks eborr!!!! its works very well!!!! only I change var for global in var NPC=LoadActor.... and in the book I write global NPC; and works ok,


thanks!!!!!!!!!!!
Logged
Henry y El libro magico, proximamente sacaremos la demo en español...
Henry and the magic book, demo coming soon in English
 

Page created in 0.079 seconds with 20 queries.