Getting very close to object/hotspot.

Started by Meistari F, Sun 28/10/2007 15:27:18

Previous topic - Next topic

Meistari F

I'm still beginner here but I'm getting very good on this, but I need a code to do this thing, but I want the player reach to the door and open it only when he is standing very near it. And if the player is not standing on the region or near the door or the object, I want a mesage display then "You are not close enough to the hotspot/object". I just want to know what code do I use for this please.

.M.M.


Khris

You can do it using regions.
Region.GetAtRoomXY(player.x, player.y)
returns the region the player is standing on (or region[0] if there's none).
So in the interact door-script or whatever you're using, test for the correct region, otherwise display the message.

Another method is to determine the distance from the object/hotspot.

The distance between x1,y1 and x2,y2 is calculated so:
Code: ags
int Distance(int x1, int y1, int x2, int y2) {
  x1=x1-x2; x1=x1*x1;
  y1=y1-y2; y1=y1*y1;
  return FloatToInt(Maths.Sqrt(IntToFloat(x1)+IntToFloat(y1)));
}

Use another function to calculate the distance from the Player:
Code: ags
int DistancePl(int x, int y) {
  return Distance(player.x, player.y, x, y);
}


Example:
Code: ags
  // interact with object table
  if (DistancePl(oTable.x, oTable.y)>30) Display("You are too far away from the table.");
  else {
    ...
  }

Dualnames

I'm sure KhrisMUC has found a solution. but do tell if you want more help on that.
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)

Meistari F

Well my character is on second floor and I just wanted to know what the code I have to use when I touch the door wich is on 1 floor and display. "You need to get closer". But the elevator door are not suppose to open until I get close to the elevator door on the first floor.





SMF spam blocked by CleanTalk