Difference between revisions of "OnTouch"

From Hercules Wiki
Jump to: navigation, search
(Created page with "==Syntax== Map,X,Y,facing script NPCName ID,OnTouch_X,OnTouchY,{ OnTouch: ==Description== OnTouch is rather hard to explain. In the beginning of the script you specify th...")
 
(add description for OnUnTouch: label)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==Syntax==
+
=Syntax=
  Map,X,Y,facing script NPCName ID,OnTouch_X,OnTouchY,{
+
  Map,X,Y,facing%tab%script%tab%NPCName%TABID,<i>triggerX</i>,<i>triggerY</i>,{CODE}
 
   
 
   
 
  OnTouch:
 
  OnTouch:
 +
OnTouchNPC:
 +
OnUnTouch:
 +
<br>
  
==Description==
+
=Description=
OnTouch is rather hard to explain. In the beginning of the script you specify the area that when the player enters that specified area, the following script is executed. You cannot specify a specific area. If you do 3,3 if the player enters any 3 squares around the NPC, the script is executed.  
+
Defines an area that when walked into will trigger one of two event labels. If it is a Player, trigger OnTouch: label. If it is a monster, trigger OnTouchNPC: label.
 
+
The OnUnTouch: label works opposite way. This label trigger when a player leave the area.
 +
==Calculating spawned area==
 +
[[File:Ontouch.jpg|thumbnail|A 7*7 area spawned by X:3 Y:3]]
 +
These triggers will define an area, centered on the NPC and spanning <i>triggerX</i> cells in every direction across X coordinate axis and <i>triggerY</i> cells in every direction across Y coordinate axis. Thus each one will have N*2 cells, where N is <i>triggerX</i> or <i>triggerY</i>, plus the one that the NPC is.<br>
 +
Unlike in arithmetics X and Y will also be taken into account when calculating the area that will trigger the NPC. There are four quadrants, each with <i>triggerX</i>*<i>triggerY</i> cells plus both axes.<br>
 +
<br><u>Note that each coordinate is a <b>cell</b> and does not represent map coordinates!</u><br>
 +
4*(x*y) + 2*x + 2*y + 1
 +
A simple way to measure the area of any polygon that will be covered by OnTouch is <u>(<i>triggerX</i>*2+1)*(<i>triggerY</i>*2+1)</u>
 +
<br>
 
'''Trick''': Using "end;" at the beginning of the script stops players from executing the script by clicking on the NPC, so they can only execute it if they walk into the specified area.
 
'''Trick''': Using "end;" at the beginning of the script stops players from executing the script by clicking on the NPC, so they can only execute it if they walk into the specified area.
 
+
<br>
 +
==Event labels==
 +
Two event labels are defined and each one handles one of two block types BL_PC or BL_MOB <i>id est</i> a player or a mob.
 +
<br>
 +
OnTouch:
 +
Handles player types (BL_PC)
 +
OnTouchNPC:
 +
Handles mob types (BL_MOB)<br>
 +
If no trigger label is defined the code will execute from the beginning of the script, the same way that it would if someone clicked on the NPC.
 
==Example==
 
==Example==
 
  prontera,147,153,3 script Mary 71,3,3,{
 
  prontera,147,153,3 script Mary 71,3,3,{
Line 17: Line 36:
 
  mes "Have you seen my lamb?";
 
  mes "Have you seen my lamb?";
 
  close;
 
  close;
  }
+
OnTouchNPC: // NO ONE IS ATTACHED!
 
+
  announce "A mob passed here",bc_blue|bc_all;
 +
end;
 +
}
 +
This script will spawn 3 cells in each direction plus a cell in the center.
 +
4*<u>3</u>*<u>3</u>+2*<u>3</u>+2*<u>3</u>+1 = 49
 +
Or
 +
(<u>3</u>*2+1) * (<u>3</u>*2+1) =
 +
7*7 = 49
  
 
[[Category:Script Command]]
 
[[Category:Script Command]]

Latest revision as of 20:37, 10 December 2015

Contents

Syntax

Map,X,Y,facing%tab%script%tab%NPCName%TABID,triggerX,triggerY,{CODE}

OnTouch:
OnTouchNPC:
OnUnTouch:


Description

Defines an area that when walked into will trigger one of two event labels. If it is a Player, trigger OnTouch: label. If it is a monster, trigger OnTouchNPC: label. The OnUnTouch: label works opposite way. This label trigger when a player leave the area.

Calculating spawned area

A 7*7 area spawned by X:3 Y:3

These triggers will define an area, centered on the NPC and spanning triggerX cells in every direction across X coordinate axis and triggerY cells in every direction across Y coordinate axis. Thus each one will have N*2 cells, where N is triggerX or triggerY, plus the one that the NPC is.
Unlike in arithmetics X and Y will also be taken into account when calculating the area that will trigger the NPC. There are four quadrants, each with triggerX*triggerY cells plus both axes.

Note that each coordinate is a cell and does not represent map coordinates!

4*(x*y) + 2*x + 2*y + 1

A simple way to measure the area of any polygon that will be covered by OnTouch is (triggerX*2+1)*(triggerY*2+1)
Trick: Using "end;" at the beginning of the script stops players from executing the script by clicking on the NPC, so they can only execute it if they walk into the specified area.

Event labels

Two event labels are defined and each one handles one of two block types BL_PC or BL_MOB id est a player or a mob.

OnTouch:

Handles player types (BL_PC)

OnTouchNPC:

Handles mob types (BL_MOB)
If no trigger label is defined the code will execute from the beginning of the script, the same way that it would if someone clicked on the NPC.

Example

prontera,147,153,3	script	Mary	71,3,3,{
	end;

OnTouch:
	mes "[Mary]";
	mes "Have you seen my lamb?";
	close;
OnTouchNPC: // NO ONE IS ATTACHED!
	announce "A mob passed here",bc_blue|bc_all;
	end;
}

This script will spawn 3 cells in each direction plus a cell in the center.

4*3*3+2*3+2*3+1 = 49

Or

(3*2+1) * (3*2+1) =
7*7 = 49