I am just starting on trying to create a system for the player to communicate with NPCs. I created a witch for this purpose, for the player to try to speak with.

So far, I programmed it so that if I get within 150 quants of the witch, and I press the "m" key to bring up the mouse cursor, the mouse cursor will turn a green color (from a white color originally). If I click on the witch in the green mouse cursor state, some text will show up on the screen, as follows:

Witch: Hello, my sweetie!
- Hello. How are you?
- Get away from me, witch!

My goal is to allow the player to click on a response to the witch, so that depending on the response, the witch will respond appropriately, basically following the idea behind NPC communication in the games Skyrim, Oblivion, and Fallout 3.

This is my code so far for this:

Code:
...

function witch_event()
{	
   if ((event_type == EVENT_CLICK) && (my.STATE == 2))
   {
      PANEL* my_panel = pan_create(NULL,0);
      FONT* my_font = font_create("Arial#30");   
  	
      pan_setstring(my_panel, 0, 300, 400, my_font, 
                    str_create("Witch:  Hello, my sweetie!"));
      pan_setstring(my_panel, 0, 300, 450, my_font, 
                    str_create("- Hello.  How are you?"));
      pan_setstring(my_panel, 0, 300, 500, my_font, 
                    str_create("- Get away from me, witch!"));
      set(my_panel,SHOW);
  		
      if ((mouse_left) && (mouse_pos.x > 315))
      {
         set(my_panel,NULL);
      }		
   }
}

...

action castle_witch() // COMMUNICATION SYSTEM STARTEE
{
   my.emask |= ENABLE_CLICK;
   my.event = witch_event;
	
   ...
	
   my.STATE = 1;

   while (1)
   {  
      ...
		
      if(my.STATE == 1) 
      {
         my.ANIMATION += 1*time_step;
			    
         ent_animate(me,"idle",my.ANIMATION,ANM_CYCLE);
			
	 c_scan(my.x, my.pan, vector(360,0,150), SCAN_ENTS | 
                SCAN_FLAG2 | IGNORE_ME);
			
	 // detect all FLAG2 entities within 150 
         // quants 	
			
	 if (you)
	 {
	    my.STATE = 2;
	 }
	 else
	 {
	    mouse_map = cursor_pcx;
	 }
      }
		
      if(my.STATE == 2)
      {
         my.ANIMATION += 1*time_step;
         ent_animate(me,"idle",my.ANIMATION,ANM_CYCLE);
			
	 mouse_map = cursor_green_pcx;
				
	 enemy = your.CREATOR;
			
	 // get the angle to the enemy			
	 VECTOR vDirection;
	 ANGLE vTargetAngle;
	 var speed = 1;
	 vec_diff(vDirection,enemy.x,my.x);
	 vec_to_angle(vTargetAngle,vDirection);
	 // vAngle is now the angle to the 
         // enemy.		
	 // Turn right or left depending on the difference
	 // between the current and the target pan 
         // angle			
	 my.pan += (time_step * sign(ang(vTargetAngle.pan - 
                    my.pan)) * speed);
      }

      wait(1);
   }   
}


So basically, I am trying to test out clicking some part of the screen where the text panel lies, with the idea that eventually the player will click a response on the screen, and something appropriate will happen, like a certain response from the NPC. In the code above, I am trying to make it so that if I click the left mouse button, and if the x coordinate of the mouse cursor is greater than 315 simultaneously (One of the text responses starts at x = 316 on the screen), then the text panel by the witch that was created will disappear. So far, this is not happening.

Am I even going about this correctly in creating an NPC communication system, or is there a better way?

Last edited by Ruben; 05/01/14 18:42.