Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Pages: [1] 2 3  All

Author Topic: actors as NPC's  (Read 14952 times)

0 Members and 1 Guest are viewing this topic.

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
actors as NPC's
« on: August 21, 2006, 04:08:22 AM »

I have read a few threads around here on actors used as NPC entities and was wondering how can i accomplish that.

In my game my character is being detained in a prison and my idea is that of having a few guards patrolling the area (walking randomly around) and a few inmates who also walk up and down the place. Of course since they would be walking around randomly i feel i am bound to using actors as NPC's. I had a look at the manual and there is indeed mention of instances in which it is possible to use actors as NPC's but i could not find any tutoriial or anything that would explain how to do it...

Also should i be able to do that, is there a way not to make the NPC's walk through each other?

Thank you and btw, WINTERMUTE ROCKS!!! ::rock

P.S.

Mnemonic you are truly a king among men!  ::rock
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

Altsaxofon

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 10
    • View Profile
Re: actors as NPC's
« Reply #1 on: August 21, 2006, 01:04:24 PM »

It's quite easy to use a actor as a NPC actually,

Just create your new actor with walking animations and all that,
and then load it into yor scene, in scene_init.script with

Code: [Select]
var NPC = Scene.LoadActor("actors\NPC\NPC.actor");
then you can let your NCP walk with the regular GoTo command.

Code: [Select]
NPC.GoTo( X, Y );
or talk, och play an animation or do anything else an actor can do
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: actors as NPC's
« Reply #2 on: August 21, 2006, 01:27:27 PM »

I would add a couple of things:

usually you should use this:

Code: [Select]
var NPC = Scene.LoadActor("your new actor there"); // or Scene.LoadActor3D(); for 3d actors
NPC.SkipTo(x,y); // some position on the hidden geometry so your NPC can also walk
NPC.Active = true; // this should show your actor in the scene. Depends on settings in act3d file;

Also if you note slowdowns on the scene entering it usually pays off to use zone based actor loading. This means
that you make the actor variables global and load actors through Game.LoadActor().

At the end of the zone you simply unload all NPC's used in current zone and load set of new. This way you cut the loading times for screens which significantly smoothes the gameplay. (the zone loading time will be longer though so you should divide the game space accordingly).

Hope that helps.



Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: actors as NPC's
« Reply #3 on: August 21, 2006, 08:45:56 PM »

Thanks guys! I'll try that,

Also i just opened my own website now and i'll be uploading all the updates on Shelter at www.fabiobasile.com under "projects". Hopefully it will be faster to download my demos than googlepages has been so far!  :)
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: actors as NPC's
« Reply #4 on: August 21, 2006, 09:35:52 PM »

Also should i be able to do that, is there a way not to make the NPC's walk through each other?
There is a still-undocumented way of doing that, see this post.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: actors as NPC's
« Reply #5 on: August 21, 2006, 10:53:46 PM »

mmh... i have managed to successfully insert an NPC in the scene but that's about it. I tried to paste the blocked region code in the NPC's script but it does nothing, the character walks through the NPC like a ghost... also i am quite confused on how to make the NPC clickable for interaction... :'(
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: actors as NPC's
« Reply #6 on: August 22, 2006, 03:38:21 AM »

Ok i better clarify what my intentions are: what i want to accomplish is to have my NPC's doing the following:

Guards:

- turning automaticallly in the direction of the actor
- walking randomly withing a region
- saying random sentences (text only)

Prisoners:

- walking around within a region
- saying random sentences (text only)
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: actors as NPC's
« Reply #7 on: August 22, 2006, 07:14:35 PM »

I tried to paste the blocked region code in the NPC's script but it does nothing, the character walks through the NPC like a ghost...
Not in script, it has to be added to the .actor definition file.


also i am quite confused on how to make the NPC clickable for interaction... :'(
Add:

  INTERACTIVE = TRUE

to the .actor file.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: actors as NPC's
« Reply #8 on: August 23, 2006, 08:10:54 AM »

Sorry to bother you still, lol i know i'm being a horrible nag  :P

everything works except for the interactivity... i tried to use the Take, Talk and LookAt codes in the NPC.script but nothing happens, and when i try to put that in the NPC.actor it gives an error and doesn't even load the NPC... How do i specify mouse actions on the actor entity (NPC)?

Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: actors as NPC's
« Reply #9 on: August 23, 2006, 08:24:56 AM »

basically you should put into NPC.script

on "LeftClick"
{
}

on "RightClick"
{
}

etc. depending on the action you're performing. Inside of those actions you will then (for example based on some internal global variables or object attributes decide what to do with the actor upon clicking on him). I fear that you're approaching this problem the other way around, but there is no way how could WME pair those events unless you script them in LeftClick or RightClick event defintions in game.script which would be too complicated and meaningless IMO.
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: actors as NPC's
« Reply #10 on: August 23, 2006, 04:25:02 PM »

By specifying INTERACTIVE = TRUE you make the actor "clickable", i.e. it can receive mouse events. If your problem is the action menu isn't shown when you right click the actor, it's because its script doesn't contain neither of the on "Talk", on "LookAt" and on "Take" event handlers. If you add one of those to the actor's script, the menu will pop up on right click.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: actors as NPC's
« Reply #11 on: August 23, 2006, 09:39:24 PM »

ok here is what i included in the NPC script "prisoner.script"

Code: [Select]
#include "scripts\base.inc"


////////////////////////////////////////////////////////////////////////////////
on "LookAt"

{
  NPC.Talk("you got a quarter, my friend?");
}

////////////////////////////////////////////////////////////////////////////////
on "Take"

{
NPC.Talk("wuzzaaaaaap!!!");
}

////////////////////////////////////////////////////////////////////////////////
on "Talk"

{
NPC.Talk("hey my man...");
}

it gives me 1 compiler error and one runtime error but nothing shows in any of the log files, the view of the scene is stuck in the upper left corner and nothing responds.

same thing if i put the code in the main actor's script "player.script". :'(
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

fabiobasile

  • Occasional poster
  • **
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 74
    • View Profile
    • my brand new website!!
Re: actors as NPC's
« Reply #12 on: August 23, 2006, 11:38:34 PM »

ok i think i'm getting it...

Now the NPC can be clicked and spoken to, metamorphium you are actually right, the reason i was stuck was that i started with the idea that the NPC should speak first by using NPC.Talk instead of actor.Talk, which i can only assume is the reason why i kept getting those errors, i guess i must have broken a few laws without noticing lol :)


Just another thing i tried to implement and modify the code for the random actor actions on the NPC but it lead me nowhere...

Is there a way to modify this code and insert it somewhere so that the NPC will say random sentences every 15 seconds and walk around  at random, making a stop every 15 seconds?

Code: [Select]
#include "scripts\base.inc"
 
var IsIdle = false;
var IdleStartTime = 0;
 
while(true) // endless loop
{
  if(actor.Ready) // is the actor doing something
  {
    if(!IsIdle)
    {
      // actor enters idle state
      IsIdle = true;
      IdleStartTime = Game.CurrentTime;
    }
    else if(Game.CurrentTime - IdleStartTime > 10000) // is the actor idle for 5 seconds
    {
      IdleStartTime = Game.CurrentTime;
      actor.ApplyEvent("idle");
    }
  }
  else IsIdle = false; // actor is busy; set IsIdle to false
  Sleep(100); // wait for 100 milliseconds
}
 
////////////////////////////////////////////////////////////////////////////////
on "idle"
{
  // do some idle processing here
  actor.Talk("dude... are we going to do *something* anytime soon?");
//  actor.GoTo(Random(800, 1000), Random(400, 600), Random(500, 1000));
}
Logged
What would i do with a million dollar? I'd give it to what's left of Black Isle/Interplay and tell them to finish the damn game!!!

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: actors as NPC's
« Reply #13 on: August 24, 2006, 07:41:27 PM »

Perhaps it would be easier to prepare several "actions" for the NPC, and execute them randomly?

Code: [Select]
// endless loop
while(true)
{
  // choose a random action
  switch(Random(0, 3))
  {
    case 0:
      // say something and wait
      this.Talk("Damn, I'm so bored.");
      Sleep(2000);
      break;
     
     
    case 1:
      // walk around
      this.GoTo(100, 200);
      Sleep(2000);
      this.GoTo(300, 400);
      Sleep(2000);
      this.GoTo(100, 200);
      break;
     
    case 2:
      // play some animation
      this.PlayAnim("smoke_cigarette.sprite");
      break;

    case 3:
      // do nothing for a while
      Sleep(3000);
      break; 
  }
}
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: actors as NPC's
« Reply #14 on: August 24, 2006, 07:44:33 PM »

it gives me 1 compiler error and one runtime error but nothing shows in any of the log files, the view of the scene is stuck in the upper left corner and nothing responds.
If you're getting compile and runtime errors, they have to be logged in the log file. UNLESS you disabled "debug mode" in ProjectMan. It's definitely worth enabling the debug mode while developing the game, really :)
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave
Pages: [1] 2 3  All
 

Page created in 0.143 seconds with 20 queries.