Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: Amiga1 on Mon 12/05/2014 02:26:06

Title: Player character and npc contact
Post by: Amiga1 on Mon 12/05/2014 02:26:06
I would like to make a situation where a character vanishes to another room when in direct contact with the player character how is that done. think pac man when he chomps a ghost or vice versa
Title: Re: Player character and npc contact
Post by: Scavenger on Mon 12/05/2014 03:25:38
Spoiler
That's pretty simple. In your room's Rep_Exec function, add this:

Code (AGS) Select

if (Character.IsCollidingWithChar (player))
{
    Character.ChangeRoom (TARGETROOM);
}


Just replace "Character" with the name of your NPC, and TARGETROOM with the number of the room you want them to go to.
[close]

Edit: v2.72? Uh. I /think/ this is the right syntax?

Code (AGS) Select
if (AreCharactersColliding (EGO,NPC))
{
       character[NPC].room = -1;
}

Title: Re: Player character and npc contact
Post by: Khris on Mon 12/05/2014 11:37:27
Amiga1:
since you are using AGS 2.72, you should say so in every tech forum topic of yours.
You'll need to add a RunScript action to the room's repeatedly execute event.
Title: Re: Player character and npc contact
Post by: Amiga1 on Tue 13/05/2014 12:38:37
Thank you both..i will :)

I think once i have an example of this script sorted it will be ok i think from there i will not need much script except for stuff i know how to do.

I currently have the player character ego and just one npc. npc script name is : c1

I presume the npc needs a script name so is it ok to call it c1   ?

once done would i would enter it into the room script?  the script look like this ?
if (AreCharactersColliding (EGO,c1))
{
       character[c1].room = -1;
}
also i need to create a room named -1 i am guessing.

If some one can suggest where i enter the script and how the script should look id really appreciate it.
i am not going to be doing much more scripting and should be able to use the standard features to work on the game.
thanks if you can help
Title: Re: Player character and npc contact
Post by: Khris on Tue 13/05/2014 14:49:29
Ok, first of all, every character needs a script name. AGS will make it all caps and auto assign a Script O-Name. AGS272 will put a lowercase c in front of it, then use its own capitalization.

Depending on the command, you need either the character's ID (old-style scripting), or the data object itself (new, object-oriented scripting).

To change a character's room, it used to be NewRoom(EGO, 2); which translates to NewRoom(0, 2); which tells AGS to move character #0 to room #2.
Since AGS 2.7, you can do this instead: cEgo.ChangeRoom(2); This is called object-oriented, because you're calling the .ChangeRoom() method of the cEgo data object.

AreCharactersColliding is old-style, you need cEgo.IsCollidingWithChar()
This will do a base line check however, so even if the character touch on screen, but one is standing a good deal "behind" the other, this will not trigger.
If you need a rectangular collision check instead, use AreThingsOverlapping.

So what you do is this:
-Open the character c1 and make sure it has a script name (AGS will change it to all caps)
-Open the room in the editor.
-Click the red i button.
-Right-click the interaction called "Repeatedly execute" and click on "New Run Script Interaction".
-In the script window, enter this:
Code (ags) Select
  int enemy = C1;  // replace C1 with character's all caps script name
  if (AreThingsOverlapping(EGO, enemy)) {
    character[enemy].ChangeRoom(-1);
  }


Sending a character to room -1 will remove them from the game (until you send them back to an existing room). You can't create room -1.
Title: Re: Player character and npc contact
Post by: Amiga1 on Tue 13/05/2014 16:12:56
That was Profoundly helpful ever consider being a tutor?
Thanks

I did it and it worked a charm.

one thing though it said that there was a no such room error regarding the -1 room thing (death room)
I decided to make room 2 the death room and its working ? dunno why that is but room 2 is gonna full of dead stuff lol