Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: sazterM on Sun 30/11/2008 01:57:53

Title: NPC's and regions [SOLVED]
Post by: sazterM on Sun 30/11/2008 01:57:53
Hi.

I've searched on the forums and have read a few posts on this as well as looking in the manual, but i still don't understand how to do it:

What i want is for one of my NPC characters to set a variable to 'false' when he stands on a particular region but what i don't understand is how to make AGS recognise the NPC as standing on said region.

As i've said i've read through a couple of other threads (http://www.adventuregamestudio.co.uk/yabb/index.php?topic=34472.0) on this but i still don't get it. could anyone take me through a solution, preferably in a way that a chimp would understand.

Any help would be greatly appreciated.
Title: Re: NPC's and regions
Post by: RickJ on Sun 30/11/2008 03:29:28
Why don't you post links to the threads which you have referenced, it may make thing s easier for everyone.   basically AGS doesn't generate events for NPCs. So what is normally done is to put some code in repeatedly execute that examines the x,y location of each NPC of interest.  There is a series of GetAtXY functions that return info about what if anything is under the cursor.  Presumably that's what the other threads are talking about.
Title: Re: NPC's and regions
Post by: Trent R on Sun 30/11/2008 07:01:08
Use Khris's code in that thread, that should give you want you want.

~Trent
Title: Re: NPC's and regions
Post by: RickJ on Sun 30/11/2008 21:46:46
Here is another version of Khris's code.  I have commented it for you so you can understand what each line is doing.  Let us know if you have any other questions.


// The RepExec() function is in the room script.  It is created using the room editor's lighting bolt icon
// located in the properties pane.  It is an event handler function that is called by the AGS runtime
// engine. 
function RepExec() {
     // Create a variable named region to hold the identity of the region under the NPC
     Region *region;

     // Get the Region at NPC's feet.  The script name of the NPC in this example is cNpc.
     // Substitute the name of your NPC for cNpc below.
     region = Region.GetAtRoomXY(cNpc.x, cNpc.y);

     // See which if any region is under the player's feat
     // No region found
     if (region==null) {   
          // Nothing to do, NPC not on a region
     }
     // Region #1     
     else if (region.ID==1) {   
          // NPC on region #1, do region #1 stuff
     }
     // Region #2     
     else if (region.ID==2) {   
          // NPC on region #2, do region #2 stuff
     }
     // Region #3     
     else if (region.ID==3) {   
          // NPC on region #3, do region #3 stuff
     }
     // Any other defined regions
     else  {   
          // NPC on some region other than #1, #2, or #3, do other region stuff
     }
}

   
Title: Re: NPC's and regions
Post by: sazterM on Fri 05/12/2008 00:18:52
Thanks for your help.

Iv'e been trying to get it to work but i keep getting the error message "Variable 'region' is already imported".
Where exactly do i create the 'region' variable - i keep getting that error.

I can't seem to wrap my head round this code.   ???


Title: Re: NPC's and regions
Post by: RickJ on Fri 05/12/2008 01:04:01
Either you have defined a variable named region elsewhere or region is a reserved word.  Just rename the variable to something like regionx or rgn.   

Oh and I've just noticed that I apparently had a bad case of cutnpastitous when I posted the sdample code.  Each if  statement should be checking for a numerical id in stead of whatever it is I currently have in there.  I have corrected the code so go back and see if it makes sense now.   :=
Title: Re: NPC's and regions
Post by: sazterM on Fri 05/12/2008 02:22:39
 :D Managed to get it working. Thanks again for your help

Title: Re: NPC's and regions [SOLVED]
Post by: RickJ on Fri 05/12/2008 06:33:01
I'm glad.  Welcome to AGS ...  ;)
Title: Re: NPC's and regions [SOLVED]
Post by: Dualnames on Fri 05/12/2008 09:32:46
Quote from: RickJ on Fri 05/12/2008 06:33:01
I'm glad.  Welcome to AGS ...  ;)

That's definetely an attitude I want to see people towards newbies.