Index: Daodan/src/Daodan_BSL.c
===================================================================
--- Daodan/src/Daodan_BSL.c	(revision 477)
+++ Daodan/src/Daodan_BSL.c	(revision 481)
@@ -3,5 +3,5 @@
 #include <time.h>
 #include <ffi.h>
-
+#include <math.h>
 #include "inifile.h"
 
@@ -218,5 +218,5 @@
 	else index = args[0].value_int32;
 	Character* Chr = ONgGameState + 0x1260 ;
-	int* health = (int*)&Chr[index] + 0x144;
+	int* health = (int)&Chr[index] + 0x144;
 
 	ret->value_int32 = *health;
@@ -226,9 +226,62 @@
 		*health = args[1].value_int32;
 	}
-	ret->value_int32 = *health;
-	ret->type = sl_int32;
-	return 0;
-}
-
+	return 0;
+}
+
+uint16_t ONICALL bsl_distance(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) {
+	
+	if (numargs < 2) return 1;
+	int index;
+	int index2;
+	if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
+	else index = args[0].value_int32;
+	if (index == -1) index = args[0].value_int32;
+
+	if (args[1].type == sl_str32) index2 = DDrGetCharacterIndexFromName(args[1].value_str32);
+	else index2 = args[1].value_int32;
+	if (index2 == -1) index2 = args[1].value_int32;
+	
+	Character* Chr = ONgGameState + 0x1260;
+	Character* Char1 = &Chr[index];
+	Character* Char2 = &Chr[index2];
+
+	ret->value_float = sqrt( pow((Char1->Location.X - Char2->Location.X), 2) + pow((Char1->Location.Y - Char2->Location.Y), 2) + pow((Char1->Location.Z - Char2->Location.Z),2));
+	ret->type = sl_float;
+	return 0;
+}
+uint16_t ONICALL bsl_location(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret) {
+	int index;
+	if (numargs < 2) return 1;
+	if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
+	else index = args[0].value_int32;
+	if (index == -1) index = args[0].value_int32;
+	Character* Chr = ONgGameState + 0x1260;
+	float* loc;
+	if (!strcmp(args[1].value_str32,"X") || !strcmp(args[1].value_str32,"x"))
+	loc = &(Chr[index].Position.X);
+	else if (!strcmp(args[1].value_str32,"Y") || !strcmp(args[1].value_str32,"y"))
+	loc = &(Chr[index].Position.Y);
+	else if (!strcmp(args[1].value_str32,"Z") || !strcmp(args[1].value_str32,"z"))
+	loc = &(Chr[index].Position.Z);
+	else if (numargs == 4) {
+		//currently broken. crashes oni.
+		Chr[index].Position.X = args[1].value_float;
+		Chr[index].Position.Y = args[2].value_float;
+		Chr[index].Position.Z = args[3].value_float;
+		ret->value_float = 1;
+		ret->type = sl_float;
+		return 0;
+	}
+	else return 1;
+	
+	ret->value_float = *loc;
+	ret->type = sl_float;
+	
+	if(numargs == 3) {
+		//currently broken, does nothing.
+		*loc = args[2].value_float;
+	}
+	return 0;
+}
 
 uint16_t ONICALL bsl_maxhealth(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
@@ -332,6 +385,8 @@
 uint16_t ONICALL bsl_nametoindex(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
 {
+
 	ret->type = sl_int32;
 	ret->value_int32 = DDrGetCharacterIndexFromName(args[0].value_str32);
+
 	return 0;
 }
@@ -397,8 +452,8 @@
 	{
 		int index;
-		if (numargs < 4) index = 0;
-		else	if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
+		
+		if (args[0].type == sl_str32) index = DDrGetCharacterIndexFromName(args[0].value_str32);
 		else index = args[0].value_int32;
-
+		
 		Character* Chr = ONgGameState + 0x1260;
 	ActiveCharacter* Active = (ActiveCharacter*)ONrGetActiveCharacter(&Chr[index]);
@@ -408,18 +463,30 @@
 	int Input1 = 0;
 	int Input2 = 0;
-	for(i = 1; i < numargs; i++) {
+	for(i = 1; i < numargs - 1; i++) {
 		for(j = 0; j < 32; j++) {
-			if(strcmp(args[i].value_str32, Actions1[j].Name)) Input1 = Input1 | Actions1[j].Bit;
-			DDrConsole_PrintF("Testing %s against %s 0x%x", args[i].value_str32, Actions1[j].Name, Actions1[j].Bit);
+			if(!strcmp(args[i].value_str32, Actions1[j].Name)) {
+				Input1 = Input1 | Actions1[j].Bit;
+			}
 		}
 		for(j = 0; j < 9; j++) {
-			if(!strcmp(args[i].value_str32, Actions2[j].Name)) Input2 = Input2 | Actions2[j].Bit;
-	
-		}
-		}
-	for(i = 0; i < numargs; i++) {
-		DDrConsole_PrintF("%s", args[i].value_str32);
-	}
-//	if
+			if(!strcmp(args[i].value_str32, Actions2[j].Name)) { 
+				Input2 = Input2 | Actions2[j].Bit;
+			}
+		}
+	}
+	Active->Input.Current.Actions1 = Active->Input.Current.Actions1 | Input1;
+	Active->Input.Current.Actions2 = Active->Input.Current.Actions1 | Input2;
+	if( Input1 + Input2 == 0 ) {
+		DDrConsole_PrintF("Func \"%s\", File \"%s\", Line %d: semantic error, \"%s\": No valid keys given.", callinfo->name, callinfo->calllocation, callinfo->linenumber, callinfo->name);
+		return 0;
+	}
+	if (  args[numargs - 1].value_int32 <= 0) {
+		return 0;
+	}
+	else {
+		 args[numargs - 1].value_int32 -= 1;
+		*dontuse2 = 1;
+		*dontuse1 = 1;
+	}
 	return 0;
 }
@@ -673,9 +740,4 @@
 }
 
-uint16_t ONICALL bsl_findmsg(sl_callinfo* callinfo, uint32_t numargs, sl_arg args[], int* dontuse1, int* dontuse2, sl_arg* ret)
-{
-	//DDrMake_Weapon_Message(args[0].value_str32);
-	return false;
-}
 void SLrDaodan_Initalize()
 {
@@ -689,5 +751,4 @@
 
 	SLrConfig();
-	SLrScript_Command_Register_ReturnType("d_wp", "Shows weapon message", "wpn:string", sl_void, bsl_findmsg);
 
 	SLrScript_Command_Register_ReturnType("int32mul", "Multiplies two numbers", "n1:int n2:int", sl_int32, bsl_int32mul);
@@ -703,17 +764,20 @@
 	SLrScript_Command_Register_ReturnType("d_getdamage","Gets the amount of damage a character has caused", "[ai_name:string | script_id:int]", sl_int32, bsl_getdamage);
 	SLrScript_Command_Register_ReturnType("d_name","Gets or sets a character's name", "[ai_name:str | script_id:int] [newname:string]", sl_str32, bsl_chrname);
-	SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "script_id:int", sl_int32, bsl_nametoindex);
+	SLrScript_Command_Register_ReturnType("d_getindex","Converts a character's name to its index", "ai_name:string", sl_int32, bsl_nametoindex);
 	SLrScript_Command_Register_ReturnType("d_health","Gets or sets a character's health", "[ai_name:str | script_id:int] [newhealth:int]", sl_str32, bsl_health);
 	SLrScript_Command_Register_ReturnType("d_regen","Gets or sets a character's health", "[ai_name:str | script_id:int] [newhealth:int]", sl_str32, bsl_regen);
 	SLrScript_Command_Register_ReturnType("d_maxhealth","Gets or sets a character's maximum health", "[ai_name:str | script_id:int] [newmaxhealth:int] [scalehealth:bool]", sl_str32, bsl_maxhealth);
 	SLrScript_Command_Register_ReturnType("d_powerup","Gets or sets a character's powerups", "ai_name:str|script_id:int powerup:str", sl_int32, bsl_powerup);
-	SLrScript_Command_Register_ReturnType("d_holdkey","Makes an AI hold a key", "[ai_name:string | script_id:int] keys", sl_int32, bsl_holdkey);
-	SLrScript_Command_Register_ReturnType("d_isheld","Checks for a held key", "keys", sl_int32, bsl_isheld);
-	SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress.", "keys", bsl_waitforkey);
-
-	//broken. sometimes crashes, and sometimes returns a string... : /
-	SLrScript_Command_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker);
-	
-	SLrScript_Command_Register_ReturnType("d_active","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset);
+	SLrScript_Command_Register_ReturnType("d_holdkey","Makes a character hold a key", "[ai_name:string | script_id:int] keys frames:int", sl_int32, bsl_holdkey);
+	SLrScript_Command_Register_ReturnType("d_isheld","Checks if player is holding a key", "keys", sl_int32, bsl_isheld);
+	SLrScript_Command_Register_ReturnType("d_location","Returns the X, Y or Z coord of a character", "ai_name:str | script_id:int xyz:string [newlocation:float]", sl_float, bsl_location);
+	SLrScript_Command_Register_ReturnType("d_distance","Returns the distance between two characters", "ai_name:str | script_id:int ai_name:str | script_id:int ", sl_float, bsl_distance);
+	SLrScript_Command_Register_Void("d_waitforkey","Waits for a keypress from the player", "keys", bsl_waitforkey);
+
+	//broken, only works for one damage type.
+	//SLrScript_Command_Register_ReturnType("d_getattacker","Gets the last person to hurt a character", "[ai_name:string | script_id:int]", sl_int32, bsl_getattacker);
+	
+	//used for debugging.
+	SLrScript_Command_Register_ReturnType("d_active","Returns a hex offset. ;)", "[ai_name:string | script_id:int]", sl_int32, bsl_getactiveoffset);
 
 	SLrScript_Command_Register_ReturnType("sprintf", "C-style sprintf.", "format:string arg1 arg2 ...", sl_str32, bsl_sprintf);
