/***********************************************
 * Title of script
 * 
 * Author: 
 * Date:   
 *
 * Desc:  
 *
 * Usage:
 *         
 ***********************************************/
#include <entity>
#include <general>
#include <animation>

//   Global Data


new Talking 		= false;    // Is the player currently talking to this NPC?
new param			= 0;
new stand[20];		// Holds the south standing animation ID
new trans = 255;
//----------------------------------------
// Name: main()
//----------------------------------------
main()
{
	if (FirstRun())
	{
		// Get the parameter for this script
		param = GetParam("this");
		
		// Set some general parameters
		SetActiveDist("this", 320);
		SetType("this", npcType);
		AllocateStrings("this", 10, 640 );   
		
		// Create the animation for the NPCs body
		CreateAnim(4, stand);
			
		// Add Different sprites depending on the parameter	
		// Theres a different parameter for each chatacter
				if ( param == 'a' ) // Old man waving
		{
			AddAnimframe(stand, 0, 0, "_npc30a");
			AddAnimframe(stand, 0, 0, "_npc30a1");
		    SetAnimSpeed(stand, 3);
		}
		    	if ( param == 'b' ) // yellowwoman waving
		{
			AddAnimframe(stand, 0, 0, "_npc30b");
			AddAnimframe(stand, 0, 0, "_npc30b1");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'c' ) // white haired woman waving
		{
			AddAnimframe(stand, 0, 0, "_npc30c");
			AddAnimframe(stand, 0, 0, "_npc30c1");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'd' ) // blackhaired man waving
		{
			AddAnimframe(stand, 0, 0, "_npc30d");
			AddAnimframe(stand, 0, 0, "_npc30d1");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'e' ) // blackhaired man waving
		{
			AddAnimframe(stand, 0, 0, "_npc30e");
			AddAnimframe(stand, 0, 0, "_npc30e1");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'f' ) // bluewoman waving
		{
			AddAnimframe(stand, 0, 0, "_npc30f");
			AddAnimframe(stand, 0, 0, "_npc30f1");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'g' ) // redman waving
		{
			AddAnimframe(stand, 0, 0, "_npc30g");
			AddAnimframe(stand, 0, 0, "_npc30g1");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'h' ) // Old man2 waving
		{
			AddAnimframe(stand, 0, 0, "_npc30h");
			AddAnimframe(stand, 0, 0, "_npc30h1");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'i' ) // Dwarf1 greets (left)
		{
			AddAnimframe(stand, 0, 0, "_npc30i");
			AddAnimframe(stand, 0, 0, "_npc30i");
			AddAnimframe(stand, 0, 0, "_npc30i");
			AddAnimframe(stand, 0, 0, "_npc30i1");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'j' ) // Dwarf2 greets (right)
		{
			AddAnimframe(stand, 0, 0, "_npc30j");
			AddAnimframe(stand, 0, 0, "_npc30j");
			AddAnimframe(stand, 0, 0, "_npc30j");
			AddAnimframe(stand, 0, 0, "_npc30j1");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'k' ) // Priest
		{
			AddAnimframe(stand, 0, 0, "_npc30k");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'l' ) // treeguy1 (left)
		{
			AddAnimframe(stand, 0, 0, "_npc30l");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'm' ) // treeguy2 (right)
		{
			AddAnimframe(stand, 0, 0, "_npc30m");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'n' ) // Old man greets
		{
			AddAnimframe(stand, 0, 0, "_npc30n");
			AddAnimframe(stand, 0, 0, "_npc30n1");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'p' ) // Uncle of Link
		{
			AddAnimframe(stand, 0, 0, "_npc30p");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'q' ) // uncle of Link K.O.
		{
			AddAnimframe(stand, 0, 0, "_npc30q");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 'r' ) // chestworker
		{
			AddAnimframe(stand, 0, 0, "_npc30r");
		    SetAnimSpeed(stand, 3);
		}
				if ( param == 't' ) // Drinking man
		{
			AddAnimframe(stand, 0, 0, "_npc30t");
			AddAnimframe(stand, 0, 0, "_npc30t");
			AddAnimframe(stand, 0, 0, "_npc30t");
			AddAnimframe(stand, 0, 0, "_npc30t");
			AddAnimframe(stand, 0, 0, "_npc30t");
			AddAnimframe(stand, 0, 0, "_npc30t1");
			AddAnimframe(stand, 0, 0, "_npc30t");
			AddAnimframe(stand, 0, 0, "_npc30t");
			AddAnimframe(stand, 0, 0, "_npc30t1");
		    SetAnimSpeed(stand, 3);
		}
	}
	
	// Check if the Player wants to talk to this NPC
	if ( CallFunction("_npclib", true, "CheckForTalk", "NULL") )
		Talking = true;
		
	// Check if the player has just finished talking to an NPC
	if (Talking && FinishedReading())
	{
		CallFunction("_npclib", true, "AfterTalk", "NULL");
		Talking = false;
	}
	
	Stand();
}

//----------------------------------------
// Name: Stand()
//----------------------------------------
Stand()
{
	new x = GetX("this");
	new y = GetY("this");
	
	
			
	// Get the width and height of the Current Image
	new width  = GetAnimWidth(stand);
	new height = GetAnimHeight(stand);
	
	// Draw the Body and the Head images
	if (isVisible("this"))
	{
		DrawAnim( stand, x, y, y + height ,0, 255,255,255,trans); 								// Draw the body

	
	
	// Set a solid collision rectangle around the NPC
	SetCollisionRect("this", 0, true, x, y, x + width, y + height);
}
}
//-----------------------------------
//Name: Ghost()
//-----------------------------------
public Ghost()
{
trans = 40;
}
//-----------------------------------
//Name: Transparent()
//-----------------------------------
public Transparent(tr)
{
trans = tr;
}