NPC's and regions [SOLVED]

Started by sazterM, Sun 30/11/2008 01:57:53

Previous topic - Next topic

sazterM

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.

RickJ

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.

Trent R

Use Khris's code in that thread, that should give you want you want.

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

RickJ

#3
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.

Code: ags

// 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
     }
}

   

sazterM

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.   ???



RickJ

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.   :=

sazterM

 :D Managed to get it working. Thanks again for your help


RickJ

I'm glad.  Welcome to AGS ...  ;)

Dualnames

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.
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SMF spam blocked by CleanTalk