Player character and npc contact

Started by Amiga1, Mon 12/05/2014 02:26:06

Previous topic - Next topic

Amiga1

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

Scavenger

#1
Spoiler
That's pretty simple. In your room's Rep_Exec function, add this:

Code: AGS

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
if (AreCharactersColliding (EGO,NPC))
{
       character[NPC].room = -1;
}


Khris

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.

Amiga1

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

Khris

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

Amiga1

#5
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

SMF spam blocked by CleanTalk