#include "Winsock2.h"
#include "Windows.h"
#include "scripts.h"
#include "engine.h"

extern "C" 
{
	#include "LuaLib\lua.h"
	#include "LuaLib\lualib.h"
	#include "LuaLib\lauxlib.h"
}
#include "sqlite3.h"

#define CCS const char *

#include "Misc.h"
#include "LuaManager.h"
#include "Lua_Class.h"
#include "time.h"
#include "Hooks.h"


#pragma warning(disable: 4244 4291)

Vector3 *Get_Vector3(lua_State *L, int index, Vector3 *v)
{
	if(lua_istable(L, index) != 1)
	{
		return 0;
	}
	lua_getfield(L, index, "X");
	v->X = lua_tonumber(L, lua_gettop(L));
	lua_pop(L,1);

	lua_getfield(L, index, "Y");
	v->Y = lua_tonumber(L, lua_gettop(L));
	lua_pop(L,1);

	lua_getfield(L, index, "Z");
	v->Z = lua_tonumber(L, lua_gettop(L));
	lua_pop(L,1);
	return v;
}


int Get_ID(GameObject *O)
{
	if(O)
	{
		return Commands->Get_ID(O);	
	}
	return 0;
}

int Lua_Get_ID(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}

int Lua_Console_Input(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(x)
	{
		Console_Input(x);	
	}
	return 0;
}

int Lua_Console_Output(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(x)
	{
		Console_Output(x);
	}
	return 0;
}

int Lua_Get_Definition_Name(lua_State *L)
{
	lua_pushstring(L, Get_Definition_Name(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Definition_ID(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(x)
	{
		lua_pushnumber(L, Get_Definition_ID(x));
	}
	return 1;
}
int Lua_Get_Definition_Class_ID(lua_State *L) 
{
	const char *x = luaL_checkstring(L, 1);
	if(x)
	{
		lua_pushnumber(L, Get_Definition_Class_ID(x));
	}
	return 1;
}
int Lua_Is_Valid_Preset_ID(lua_State *L) 
{
	lua_pushboolean(L, Is_Valid_Preset_ID(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Is_Valid_Preset(lua_State *L) 
{
	const char *x = luaL_checkstring(L, 1);
	if(x)
	{
		lua_pushboolean(L, Is_Valid_Preset(x));
	}
	else
	{
		return 0;
	}
	return 1;
}
int Lua_Set_Max_Health(lua_State *L)
{
	Set_Max_Health(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Set_Max_Shield_Strength(lua_State *L)
{
	Set_Max_Shield_Strength(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Get_Shield_Type(lua_State *L)
{
	lua_pushstring(L, Get_Shield_Type(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Skin(lua_State *L)
{
	lua_pushstring(L, Get_Skin(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 0;
}
int Lua_Set_Skin(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(x)
	{
		Set_Skin(Commands->Find_Object(luaL_checknumber(L, 1)), x);
	}
	return 0;
}
int Lua_Power_Base(lua_State *L) 
{
	Power_Base(luaL_checknumber(L, 1), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Set_Can_Generate_Soldiers(lua_State *L)
{
	Set_Can_Generate_Soldiers(luaL_checknumber(L, 1), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Set_Can_Generate_Vehicles(lua_State *L) 
{
	Set_Can_Generate_Vehicles(luaL_checknumber(L, 1), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Destroy_Base(lua_State *L)
{
	Destroy_Base(luaL_checknumber(L, 1));
	return 0;
}
int Lua_Beacon_Destroyed_Base(lua_State *L)
{
	Beacon_Destroyed_Base(luaL_checknumber(L, 1), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Enable_Base_Radar(lua_State *L)
{
	Enable_Base_Radar(luaL_checknumber(L, 1), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Is_Harvester(lua_State *L)
{
	lua_pushboolean(L, Is_Harvester(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 0;
}
int Lua_Is_Radar_Enabled(lua_State *L) 
{
	lua_pushboolean(L, Is_Radar_Enabled(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Building_Type(lua_State *L) 
{
	lua_pushnumber(L, Building_Type(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Building_Dead(lua_State *L) 
{
	lua_pushboolean(L, Is_Building_Dead(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Find_Building(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Building(luaL_checknumber(L, 1), luaL_checknumber(L, 2)))); 
	return 1;
}
int Lua_Find_Base_Defense(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Base_Defense(luaL_checknumber(L, 1)))); 
	return 1;
}
int Lua_Is_Map_Flying(lua_State *L) 
{
	lua_pushboolean(L, Is_Map_Flying());
	return 0;
}
int Lua_Find_Harvester(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Harvester(luaL_checknumber(L, 1)))); 
	return 1;
}
int Lua_Is_Base_Powered(lua_State *L)
{
	lua_pushboolean(L, Is_Base_Powered(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Can_Generate_Vehicles(lua_State *L)
{
	lua_pushboolean(L, Can_Generate_Vehicles(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Can_Generate_Soliders(lua_State *L)
{
	lua_pushboolean(L, Can_Generate_Soliders(luaL_checknumber(L, 1)));
	return 1;
}

int Lua_Is_A_Building(lua_State *L)
{
	lua_pushboolean(L, Is_A_Building(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Building_Count_Team(lua_State *L)
{
	lua_pushnumber(L, Get_Building_Count_Team(luaL_checknumber(L, 1)));
	return 0;
}

int Lua_Find_Building_By_Team(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Building_By_Team(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Find_Building_By_Name(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Building_By_Team(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Find_Power_Plant(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Power_Plant(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Find_Refinery(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Refinery(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Find_Repair_Bay(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Repair_Bay(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Find_Soldier_Factory(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Soldier_Factory(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Find_Airstrip(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Airstrip(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Find_War_Factory(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_War_Factory(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Find_Vehicle_Factory(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Vehicle_Factory(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Find_Com_Center(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Com_Center(luaL_checknumber(L, 1))));
	return 0;
}
int Lua_Is_Gameplay_Permitted(lua_State *L)
{
	lua_pushboolean(L, Is_Gameplay_Permitted());
	return 1;
}
int Lua_Is_Dedicated(lua_State *L) 
{
	lua_pushboolean(L, Is_Dedicated());
	return 1;
}
int Lua_Is_Linux(lua_State *L)
{
	lua_pushboolean(L, Is_Linux());
	return 1;
}
int Lua_Get_Current_Game_Mode(lua_State *L)
{
	lua_pushnumber(L, Get_Current_Game_Mode());
	return 1;
}
int Lua_Get_Harvester_Preset_ID(lua_State *L)
{
	lua_pushnumber(L, Get_Harvester_Preset_ID(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Is_Harvester_Preset(lua_State *L)
{
	lua_pushboolean(L, Is_Harvester_Preset(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Destroy_Connection(lua_State *L)
{
	Destroy_Connection(luaL_checknumber(L, 1));
	return 0;
}
int Lua_Get_IP_Address(lua_State *L)
{
	const char *IP = Get_IP_Address(luaL_checknumber(L, 1));
	if(!IP)
	{
		return 0;
	}
	lua_pushstring(L, IP);
	delete []IP;
	return 1;
}
int Lua_Get_IP_Port(lua_State *L)
{
	const char *IP = Get_IP_Port(luaL_checknumber(L, 1));
	if(!IP)
	{
		return 0;
	}
	lua_pushstring(L, IP);
	delete []IP;
	return 1;
}
int Lua_Get_Bandwidth(lua_State *L)
{
	lua_pushnumber(L, Get_Bandwidth(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Ping(lua_State *L)
{
	lua_pushnumber(L, Get_Ping(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Kbits(lua_State *L)
{
	lua_pushnumber(L, Get_Kbits(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Object_Type(lua_State *L)
{
	lua_pushnumber(L, Get_Object_Type(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Set_Object_Type(lua_State *L)
{
	Set_Object_Type(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Is_Building(lua_State *L)
{
	lua_pushboolean(L, Is_Building(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Soldier(lua_State *L)
{
	lua_pushboolean(L, Is_Soldier(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Vehicle(lua_State *L)
{
	lua_pushboolean(L, Is_Vehicle(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Cinematic(lua_State *L)
{
	lua_pushboolean(L, Is_Cinematic(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_ScriptZone(lua_State *L)
{
	lua_pushboolean(L, Is_ScriptZone(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Powerup(lua_State *L)
{
	lua_pushboolean(L, Is_Powerup(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_C4(lua_State *L)
{
	lua_pushboolean(L, Is_C4(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Beacon(lua_State *L)
{
	lua_pushboolean(L, Is_Beacon(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Armed(lua_State *L)
{
	lua_pushboolean(L, Is_Armed(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Simple(lua_State *L)
{
	lua_pushboolean(L, Is_Simple(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_PowerPlant(lua_State *L)
{
	lua_pushboolean(L, Is_PowerPlant(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_SoldierFactory(lua_State *L)
{
	lua_pushboolean(L, Is_SoldierFactory(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_VehicleFactory(lua_State *L)
{
	lua_pushboolean(L, Is_VehicleFactory(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Airstrip(lua_State *L)
{
	lua_pushboolean(L, Is_Airstrip(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_WarFactory(lua_State *L)
{
	lua_pushboolean(L, Is_WarFactory(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Refinery(lua_State *L)
{
	lua_pushboolean(L, Is_Refinery(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_ComCenter(lua_State *L)
{
	lua_pushboolean(L, Is_ComCenter(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_RepairBay(lua_State *L)
{
	lua_pushboolean(L, Is_RepairBay(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Scriptable(lua_State *L)
{
	lua_pushboolean(L, Is_Scriptable(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Building_Type(lua_State *L)
{
	lua_pushstring(L, Get_Building_Type(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Object_Count(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;

	lua_pushnumber(L, Get_Object_Count(luaL_checknumber(L, 2), x));
	return 1;
}

int Lua_Find_Random_Preset(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	lua_pushnumber(L, Get_ID(Find_Random_Preset(x, luaL_checknumber(L, 2), luaL_checknumber(L, 2))));
	return 1;
}
int Lua_Send_Custom_To_Team_Buildings(lua_State *L)
{
	Send_Custom_To_Team_Buildings(luaL_checknumber(L, 1), Commands->Find_Object(luaL_checknumber(L, 2)), luaL_checknumber(L, 3), luaL_checknumber(L,3), luaL_checknumber(L, 4));
	return 0;
}
int Lua_Send_Custom_To_Team_Preset(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	Send_Custom_To_Team_Preset(luaL_checknumber(L, 1), x, Commands->Find_Object(luaL_checknumber(L, 3)), luaL_checknumber(L, 4), luaL_checknumber(L, 5), luaL_checknumber(L, 6));
	return 0;
}

int Lua_Send_Custom_All_Objects(lua_State *L)
{
	Send_Custom_All_Objects(luaL_checknumber(L, 1), Commands->Find_Object(luaL_checknumber(L, 2)), luaL_checknumber(L, 3));
	return 0;
}
int Lua_Send_Custom_Event_To_Object(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;

	Send_Custom_Event_To_Object(Commands->Find_Object(luaL_checknumber(L, 1)), x, luaL_checknumber(L, 3), luaL_checknumber(L, 4), luaL_checknumber(L, 5));
	return 0;
}

int Lua_Get_Is_Powerup_Persistant(lua_State *L)
{
	lua_pushboolean(L, Get_Is_Powerup_Persistant(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Set_Is_Powerup_Persistant(lua_State *L)
{
	Set_Is_Powerup_Persistant(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Get_Powerup_Always_Allow_Grant(lua_State *L)
{
	lua_pushboolean(L, Get_Powerup_Always_Allow_Grant(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 0;
}
int Lua_Set_Powerup_Always_Allow_Grant(lua_State *L)
{
	Set_Powerup_Always_Allow_Grant(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Get_Powerup_Grant_Sound(lua_State *L)
{
	lua_pushnumber(L, Get_Powerup_Grant_Sound(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;	
}
int Lua_Set_Powerup_Grant_Sound(lua_State *L)
{
	Set_Powerup_Grant_Sound(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Grant_Powerup(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	Grant_Powerup(Commands->Find_Object(luaL_checknumber(L, 1)), x);
	return 0;
}
int Lua_Get_Vehicle(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_Vehicle(Commands->Find_Object(luaL_checknumber(L, 1)))));
	return 1;
}
int Lua_Grant_Refill(lua_State *L)
{
	Grant_Refill(Commands->Find_Object(luaL_checknumber(L, 1)));
	return 0;
}
int Lua_Change_Character(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	lua_pushnumber(L, Change_Character(Commands->Find_Object(luaL_checknumber(L, 1)), x));
	return 1;
}
int Lua_Create_Vehicle(lua_State *L)
{
	const char *x = luaL_checkstring(L, 4);
	if(!x) return 0;
	Create_Vehicle(x, luaL_checknumber(L, 3), Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)); 
	return 0;
}
int Lua_Toggle_Fly_Mode(lua_State *L)
{
	Toggle_Fly_Mode(Commands->Find_Object(luaL_checknumber(L, 1)));
	return 0;
}
int Lua_Get_Vehicle_Occupant_Count(lua_State *L)
{
	lua_pushnumber(L, Get_Vehicle_Occupant_Count(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Vehicle_Occupant(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_Vehicle_Occupant(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2))));
	return 1;
}
int Lua_Get_Vehicle_Driver(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_Vehicle_Driver(Commands->Find_Object(luaL_checknumber(L, 1)))));
	return 1;
}
int Lua_Get_Vehicle_Gunner(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_Vehicle_Gunner(Commands->Find_Object(luaL_checknumber(L, 1)))));
	return 1;
}
int Lua_Force_Occupant_Exit(lua_State *L)
{
	Force_Occupant_Exit(Commands->Find_Object(luaL_checknumber(L, 2)), luaL_checknumber(L, 1));
	return 0;
}
int Lua_Force_Occupants_Exit(lua_State *L)
{
	Force_Occupants_Exit(Commands->Find_Object(luaL_checknumber(L, 1)));
	return 0;
}
int Lua_Get_Vehicle_Return(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_Vehicle_Return(Commands->Find_Object(luaL_checknumber(L, 1)))));
	return 1;
}
int Lua_Is_Stealth(lua_State *L)
{
	lua_pushboolean(L, Is_Stealth(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Fly_Mode(lua_State *L)
{
	lua_pushnumber(L, Get_Fly_Mode(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Vehicle_Seat_Count(lua_State *L)
{
	lua_pushnumber(L, Get_Vehicle_Seat_Count(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Spawn_Char(lua_State *L)
{
	lua_pushstring(L, Get_Spawn_Char(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Change_Spawn_Char(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	Change_Spawn_Char(luaL_checknumber(L, 2), x);
	return 0;
}
int Lua_Soldier_Transition_Vehicle(lua_State *L)
{
	Soldier_Transition_Vehicle(Commands->Find_Object(luaL_checknumber(L, 1)));
	return 0;
}
int Lua_Get_Vehicle_Mode(lua_State *L)
{
	lua_pushnumber(L, Get_Vehicle_Mode(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Team_Vehicle_Count(lua_State *L)
{
	lua_pushnumber(L, Get_Team_Vehicle_Count(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Vehicle_Owner(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_Vehicle_Owner(Commands->Find_Object(luaL_checknumber(L, 1)))));
	return 1;
}
int Lua_Force_Occupants_Exit_Team(lua_State *L)
{
	Force_Occupants_Exit_Team(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Get_Vehicle_Definition_Mode(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	lua_pushnumber(L, Get_Vehicle_Definition_Mode(x));
	return 1;
}

int Lua_IsInsideZone(lua_State *L)
{
	lua_pushnumber(L, IsInsideZone(Commands->Find_Object(luaL_checknumber(L, 1)), Commands->Find_Object(luaL_checknumber(L, 2))));
	return 1;
}
int Lua_Get_Vehicle_Definition_Mode_By_ID(lua_State *L)
{
	lua_pushnumber(L, Get_Vehicle_Definition_Mode_By_ID(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Zone_Type(lua_State *L)
{
	lua_pushnumber(L, Get_Zone_Type(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}

int Lua_IsAvailableForPurchase(lua_State *L)
{
	lua_pushnumber(L, IsAvailableForPurchase(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Check_Transitions(lua_State *L)
{
	lua_pushnumber(L, Check_Transitions(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Get_Vehicle_Gunner_Pos(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_Vehicle_Gunner_Pos(Commands->Find_Object(luaL_checknumber(L, 1)))));
	return 1;
}
int Lua_Set_Vehicle_Is_Visible(lua_State *L)
{
	Set_Vehicle_Is_Visible(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Set_Vehicle_Gunner(lua_State *L)
{
	Set_Vehicle_Gunner(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Get_Model(lua_State *L)
{
	lua_pushstring(L, Get_Model(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Animation_Frame(lua_State *L)
{
	lua_pushnumber(L, Get_Animation_Frame(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_TrackedVehicle(lua_State *L)
{
	lua_pushboolean(L, Is_TrackedVehicle(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_VTOLVehicle(lua_State *L)
{
	lua_pushboolean(L, Is_VTOLVehicle(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_WheeledVehicle(lua_State *L)
{
	lua_pushboolean(L, Is_WheeledVehicle(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Motorcycle(lua_State *L)
{
	lua_pushboolean(L, Is_Motorcycle(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Door(lua_State *L)
{
	lua_pushboolean(L, Is_Door(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Elevator(lua_State *L)
{
	lua_pushboolean(L, Is_Elevator(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_DamageableStaticPhys(lua_State *L)
{
	lua_pushboolean(L, Is_DamageableStaticPhys(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_AccessablePhys(lua_State *L)
{
	lua_pushboolean(L, Is_AccessablePhys(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_DecorationPhys(lua_State *L)
{
	lua_pushboolean(L, Is_DecorationPhys(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_HumanPhys(lua_State *L)
{
	lua_pushboolean(L, Is_HumanPhys(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_MotorVehicle(lua_State *L)
{
	lua_pushboolean(L, Is_MotorVehicle(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Phys3(lua_State *L)
{
	lua_pushboolean(L, Is_Phys3(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_RigidBody(lua_State *L)
{
	lua_pushboolean(L, Is_RigidBody(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_ShakeableStatricPhys(lua_State *L)
{
	lua_pushboolean(L, Is_ShakeableStatricPhys(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_StaticAnimPhys(lua_State *L)
{
	lua_pushboolean(L, Is_StaticAnimPhys(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_StaticPhys(lua_State *L)
{
	lua_pushboolean(L, Is_StaticPhys(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_TimedDecorationPhys(lua_State *L)
{
	lua_pushboolean(L, Is_TimedDecorationPhys(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_VehiclePhys(lua_State *L)
{
	lua_pushnumber(L, Is_VehiclePhys(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_DynamicAnimPhys(lua_State *L)
{
	lua_pushboolean(L, Is_DynamicAnimPhys(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_BuildingAggregate(lua_State *L)
{
	lua_pushboolean(L, Is_BuildingAggregate(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Is_Projectile(lua_State *L)
{
	lua_pushboolean(L, Is_Projectile(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Physics(lua_State *L)
{
	lua_pushstring(L, Get_Physics(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Copy_Transform(lua_State *L)
{
	Copy_Transform(Commands->Find_Object(luaL_checknumber(L, 1)), Commands->Find_Object(luaL_checknumber(L, 2)));
	return 0;
}
int Lua_Get_Mass(lua_State *L)
{
	lua_pushnumber(L, Get_Mass(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Htree_Name(lua_State *L)
{
	lua_pushstring(L, Get_Htree_Name(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Sex(lua_State *L)
{
	lua_pushnumber(L, Get_Sex(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}

int Lua_Create_Effect_All_Of_Preset(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	const char *y = luaL_checkstring(L, 2);
	if(!x || !y) return 0;

	Create_Effect_All_Of_Preset(x, y,  luaL_checknumber(L, 3), luaL_checknumber(L, 4));
	return 0;
}
int Lua_Get_GameObj(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_GameObj(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Player_ID(lua_State *L)
{
	lua_pushnumber(L, Get_Player_ID(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Player_Name(lua_State *L)
{
	const char *ptr = Get_Player_Name(Commands->Find_Object(luaL_checknumber(L, 1)));
	if(!ptr)
	{
		return 0;
	}
	lua_pushstring(L, ptr);
	delete []ptr;
	return 1;
}
int Lua_Get_Player_Name_By_ID(lua_State *L)
{
	const char *ptr = Get_Player_Name_By_ID(luaL_checknumber(L, 1));
	if(!ptr)
	{
		return 0;
	}
	lua_pushstring(L, ptr);
	delete []ptr;
	return 1;
}
int Lua_Change_Team(lua_State *L)
{
	Change_Team(Commands->Find_Object(luaL_checknumber(L, 2)), luaL_checknumber(L, 1));
	return 0;
}
int Lua_Change_Team_By_ID(lua_State *L)
{
	Change_Team_By_ID(luaL_checknumber(L, 2), luaL_checknumber(L, 1));
	return 0;
}
int Lua_Get_Player_Count(lua_State *L)
{
	lua_pushnumber(L, Get_Player_Count());
	return 1;
}
int Lua_Get_Team_Player_Count(lua_State *L)
{
	lua_pushnumber(L, Get_Team_Player_Count(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Team(lua_State *L)
{
	lua_pushnumber(L, Get_Team(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Rank(lua_State *L)
{
	lua_pushnumber(L, Get_Rank(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Kills(lua_State *L)
{
	lua_pushnumber(L, Get_Kills(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Deaths(lua_State *L)
{
	lua_pushnumber(L, Get_Deaths(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Score(lua_State *L)
{
	lua_pushnumber(L, Get_Score(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Money(lua_State *L)
{
	lua_pushnumber(L, Get_Money(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Kill_To_Death_Ratio(lua_State *L)
{
	lua_pushnumber(L, Get_Kill_To_Death_Ratio(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Part_Name(lua_State *L)
{
	lua_pushnumber(L, Commands->Get_ID(Get_Part_Name(luaL_checkstring(L, 1))));
	return 1;
}
int Lua_Get_Part_Names(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	lua_pushnumber(L, Get_Part_Names(x));
	return 1;
}

int Lua_Get_GameObj_By_Player_Name(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	lua_pushnumber(L, Get_ID(Get_GameObj_By_Player_Name(x)));
	return 1;
}
int Lua_Purchase_Item(lua_State *L)
{
	lua_pushnumber(L, Purchase_Item(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Set_Ladder_Points(lua_State *L)
{
	Set_Ladder_Points(luaL_checknumber(L,1), luaL_checknumber(L,2));
	return 0;
}
int Lua_Set_Rung(lua_State *L)
{
	Set_Rung(luaL_checknumber(L, 1), luaL_checknumber(L, 3));
	return 0;
}
int Lua_Set_Money(lua_State *L)
{
	Set_Money(luaL_checknumber(L, 1), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Set_Score(lua_State *L)
{
	Set_Score(luaL_checknumber(L, 1), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Find_First_Player(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_First_Player(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Change_Player_Team(lua_State *L)
{
	lua_pushnumber(L, Change_Player_Team(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4)));
	return 1;
}
int Lua_Tally_Team_Size(lua_State *L)
{
	lua_pushnumber(L, Tally_Team_Size(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Team_Score(lua_State *L)
{
	lua_pushnumber(L, Get_Team_Score(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Send_Custom_All_Players(lua_State *L)
{
	 Send_Custom_All_Players(luaL_checknumber(L, 1), Commands->Find_Object(luaL_checknumber(L, 2)), luaL_checknumber(L, 3));
	return 0;
}
int Lua_Steal_Team_Credits(lua_State *L)
{
	lua_pushnumber(L, Steal_Team_Credits(luaL_checknumber(L, 1), luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Get_Team_Credits(lua_State *L)
{
	lua_pushnumber(L, Get_Team_Credits(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Change_Team_2(lua_State *L)
{
	Change_Team_2(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Get_Player_Type(lua_State *L)
{
	lua_pushnumber(L, Get_Player_Type(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Team_Cost(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	lua_pushnumber(L, Get_Team_Cost(x, luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Get_Cost(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	lua_pushnumber(L, Get_Cost(x));
	return 1;
}
int Lua_Set_Enlisted(lua_State *L)
{
	const char *x = luaL_checkstring(L, 5);
	if(!x) return 0;
	Set_Enlisted(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4), x);
	return 0;
}
int Lua_Set_Beacon(lua_State *L)
{
	const char *x = luaL_checkstring(L, 5);
	if(!x) return 0;
	Set_Beacon(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4), x);
	return 0;
}
int Lua_Set_Refill(lua_State *L)
{
	const char *x = luaL_checkstring(L, 3);
	if(!x) return 0;
	Set_Refill(luaL_checknumber(L, 1), luaL_checknumber(L, 2), x);
	return 0;
}
int Lua_Set_Preset(lua_State *L)
{
	const char *x = luaL_checkstring(L, 7);
	if(!x) return 0;
	Set_Preset(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4), luaL_checknumber(L, 5), luaL_checknumber(L, 6), x);
	return 0;
}
int Lua_Set_Alternate(lua_State *L)
{
	const char *x = luaL_checkstring(L, 6);
	if(!x) return 0;
	Set_Alternate(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4), luaL_checknumber(L, 5), x);
	return 0;
}
int Lua_Disable_Enlisted(lua_State *L)
{
	Disable_Enlisted(luaL_checknumber(L, 1), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Disable_Preset(lua_State *L)
{
	Disable_Preset(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3));
	return 0;
}
int Lua_Disable_Enlisted_By_Name(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	Disable_Enlisted_By_Name(luaL_checknumber(L, 1), x);
	return 0;
}
int Lua_Disable_Preset_By_Name(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	Disable_Preset_By_Name(luaL_checknumber(L, 1), x);
	return 0;
}
int Lua_Disable_All_Ground_Vehicles(lua_State *L)
{
	Disable_All_Ground_Vehicles(luaL_checknumber(L, 1));
	return 0;
}
int Lua_Disable_All_Flying_Vehicles(lua_State *L)
{
	Disable_All_Flying_Vehicles(luaL_checknumber(L, 1));
	return 0;
}
int Lua_Get_Team_Icon(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	lua_pushstring(L, Get_Team_Icon(x, luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Get_Icon(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	const char *y = Get_Icon(x);
	if(!y)
	{
		return 0;
	}
	lua_pushstring(L, y);
	return 1;
}
int Lua_Remove_Script(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	Remove_Script(Commands->Find_Object(luaL_checknumber(L, 1)), x);
	return 0;
}
int Lua_Remove_All_Scripts(lua_State *L)
{
	Remove_All_Scripts(Commands->Find_Object(luaL_checknumber(L, 1)));
	return 0;
}
int Lua_Attach_Script_Preset(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	const char *y = luaL_checkstring(L, 2);
	const char *z = luaL_checkstring(L, 3);
	if(!x || !y || !z) return 0;
	Attach_Script_Preset(x, y, z, luaL_checknumber(L, 4));
	return 0;
}
int Lua_Attach_Script_Type(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	const char *y = luaL_checkstring(L, 2);
	if(!x || !y) return 0;

	Attach_Script_Type(x, y, luaL_checknumber(L, 3), luaL_checknumber(L, 4));
	return 0;
}
int Lua_Remove_Script_Preset(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	const char *y = luaL_checkstring(L, 2);
	if(!x || !y) return 0;
	Remove_Script_Preset(x, y, luaL_checknumber(L, 3));
	return 0;
}
int Lua_Remove_Script_Type(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	Remove_Script_Type(x, luaL_checknumber(L, 2), luaL_checknumber(L, 3));
	return 0;
}
int Lua_Is_Script_Attached(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	lua_pushboolean(L, Is_Script_Attached(Commands->Find_Object(luaL_checknumber(L, 1)), x));
	return 1;
}
int Lua_Attach_Script_Once(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	const char *y = luaL_checkstring(L, 3);
	if(!x || !y) return 0;
	Attach_Script_Once(Commands->Find_Object(luaL_checknumber(L, 1)), x, y);
	return 0;
}
int Lua_Attach_Script_Preset_Once(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	const char *y = luaL_checkstring(L, 2);
	const char *z = luaL_checkstring(L, 3);
	if(!x || !y || !z) return 0;
	Attach_Script_Preset_Once(x, y, z, luaL_checknumber(L, 4));	
	return 0;
}
int Lua_Attach_Script_Type_Once(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	const char *y = luaL_checkstring(L, 2);
	if(!x || !y) return 0;
	Attach_Script_Type_Once(x, y, luaL_checknumber(L, 3), luaL_checknumber(L, 4));
	return 0;
}
int Lua_Attach_Script_Building(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	const char *y = luaL_checkstring(L, 2);
	if(!x || !y) return 0;
	Attach_Script_Building(x, y, luaL_checknumber(L, 3));
	return 0;
}
int Lua_Attach_Script_Is_Preset(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	const char *y = luaL_checkstring(L, 3);
	const char *z = luaL_checkstring(L, 4);
	if(!x || !y || !x) return 0;
	Attach_Script_Is_Preset(Commands->Find_Object(luaL_checknumber(L, 1)), x, y, z, luaL_checknumber(L, 5));

	return 0;
}
int Lua_Attach_Script_Is_Type(lua_State *L)
{
	const char *x = luaL_checkstring(L, 3);
	const char *y = luaL_checkstring(L, 4);
	if(!x || !y) return 0;
	Attach_Script_Is_Type(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2), x, y, luaL_checknumber(L, 5));
	return 0;
}
int Lua_Attach_Script_Player_Once(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	const char *y = luaL_checkstring(L, 2);
	if(!x ||!y) return 0;
	Attach_Script_Player_Once(x, y, luaL_checknumber(L, 2));
	return 0;
}
int Lua_Remove_Duplicate_Script(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	Remove_Duplicate_Script(Commands->Find_Object(luaL_checknumber(L, 1)), x);
	return 0;
}
int Lua_Attach_Script_All_Buildings_Team(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	const char *y = luaL_checkstring(L, 3);
	if(!x || !y) return 0;
	Attach_Script_All_Buildings_Team(luaL_checknumber(L, 1), x, y, luaL_checknumber(L, 4));
	return 0;
}
int Lua_Attach_Script_All_Turrets_Team(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	const char *y = luaL_checkstring(L, 3);
	if(!x || !y) return 0;
	Attach_Script_All_Turrets_Team(luaL_checknumber(L, 1), x, y, luaL_checknumber(L, 4));
	return 0;
}
int Lua_Find_Building_With_Script(lua_State *L)
{
	const char *x = luaL_checkstring(L, 3);
	if(!x) return 0;
	lua_pushnumber(L, Get_ID(Find_Building_With_Script(luaL_checknumber(L, 1), luaL_checknumber(L, 2), x, Commands->Find_Object(luaL_checknumber(L, 4)))));
	return 1;
}
int Lua_Find_Object_With_Script(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	lua_pushnumber(L, Get_ID(Find_Object_With_Script(x)));
	return 1;
}
int Lua_Get_Translated_String(lua_State *L)
{
	const wchar_t *ptr = Translate_Preset_ID_To_PT_String_Name(luaL_checknumber(L, 1), luaL_checknumber(L, 2));
	if(!ptr)
	{
		return 0;
	}
	
	char tmp[256];
	wcstombs(tmp, ptr, 256);
	lua_pushstring(L, tmp);
	return 1;
}
int Lua_Get_Translated_Preset_Name(lua_State *L)
{
	const char *ptr = Get_Translated_Preset_Name(Commands->Find_Object(luaL_checknumber(L, 1)));
	if(!ptr)
	{
		return 0;
	}
	lua_pushstring(L, ptr);
	delete []ptr;
	return 1;
}
int Lua_Get_Translated_Weapon(lua_State *L)
{
	const char *ptr = Get_Translated_Weapon(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	if(!ptr)
	{
		return 0;
	}
	lua_pushstring(L, ptr);
	delete []ptr;
	return 1;
}
int Lua_Get_Current_Translated_Weapon(lua_State *L)
{
	const char *ptr = Get_Current_Translated_Weapon(Commands->Find_Object(luaL_checknumber(L, 1)));
	if(!ptr)
	{
		return 0;
	}
	lua_pushstring(L, ptr);
	delete []ptr;
	return 1;
}
int Lua_Get_Team_Name(lua_State *L)
{
	const char *ptr = Get_Team_Name(luaL_checknumber(L, 1));
	if(!ptr)
	{
		return 0;
	}
	lua_pushstring(L, ptr);
	delete []ptr;
	return 1;
}
int Lua_Get_Vehicle_Name(lua_State *L)
{
	const char *ptr = Get_Vehicle_Name(Commands->Find_Object(luaL_checknumber(L, 1)));
	if(!ptr)
	{
		return 0;
	}
	lua_pushstring(L, ptr);
	delete []ptr;
	return 1;
}
int Lua_Get_Translated_Definition_Name(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	const char *ptr = Get_Translated_Definition_Name(x);
	if(!ptr)
	{
		return 0;
	}
	lua_pushstring(L, ptr);
	delete []ptr;
	return 1;
}
int Lua_Get_Current_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Current_Bullets(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Current_Clip_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Current_Clip_Bullets(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Current_Total_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Current_Total_Bullets(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Total_Bullets(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	lua_pushnumber(L, Get_Total_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), x));
	return 1;
}
int Lua_Get_Clip_Bullets(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	lua_pushnumber(L, Get_Clip_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), x));
	return 1;
}
int Lua_Get_Bullets(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	lua_pushnumber(L, Get_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), x));
	return 1;
}
int Lua_Get_Current_Max_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Current_Max_Bullets(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Current_Clip_Max_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Current_Clip_Max_Bullets(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Current_Total_Max_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Current_Total_Max_Bullets(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Max_Total_Bullets(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	lua_pushnumber(L, Get_Max_Total_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), x));
	return 1;
}
int Lua_Get_Max_Clip_Bullets(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	lua_pushnumber(L, Get_Max_Total_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), x));
	return 1;
}
int Lua_Get_Max_Bullets(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	lua_pushnumber(L, Get_Max_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), x));
	return 1;
}
int Lua_Get_Position_Total_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Position_Total_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Get_Position_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Position_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Get_Position_Clip_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Position_Clip_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Get_Position_Total_Max_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Position_Total_Max_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Get_Position_Max_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Position_Max_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Get_Position_Clip_Max_Bullets(lua_State *L)
{
	lua_pushnumber(L, Get_Position_Clip_Max_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Set_Current_Bullets(lua_State *L)
{
	Set_Current_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Set_Current_Clip_Bullets(lua_State *L)
{
	Set_Current_Clip_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Set_Position_Bullets(lua_State *L)
{
	Set_Position_Bullets(Commands->Find_Object(luaL_checknumber(L, 3)), luaL_checknumber(L, 1), luaL_checknumber(L, 2));
	return 0;
}
int Lua_Set_Position_Clip_Bullets(lua_State *L)
{
	Set_Position_Clip_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2), luaL_checknumber(L, 3));
	return 0;
}
int Lua_Set_Bullets(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	Set_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), x, luaL_checknumber(L, 3));
	return 0;
}
int Lua_Set_Clip_Bullets(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	Set_Clip_Bullets(Commands->Find_Object(luaL_checknumber(L, 1)), x, luaL_checknumber(L, 3));
	return 0;
}
int Lua_Get_Powerup_Weapon(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	if(!x) return 0;
	lua_pushstring(L, Get_Powerup_Weapon(x));
	return 1;
}

int Lua_Get_Powerup_Weapon_By_Obj(lua_State *L)
{
	lua_pushstring(L, Get_Powerup_Weapon_By_Obj(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Current_Weapon_Style(lua_State *L)
{
	lua_pushnumber(L, Get_Current_Weapon_Style(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Get_Position_Weapon_Style(lua_State *L)
{
	lua_pushnumber(L, Get_Position_Weapon_Style(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)));
	return 1;
}
int Get_Weapon_Style(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	lua_pushnumber(L, Get_Weapon_Style(Commands->Find_Object(luaL_checknumber(L, 1)), x));
	return 1;
}
int Lua_Disarm_Beacon(lua_State *L)
{
	Disarm_Beacon(Commands->Find_Object(luaL_checknumber(L, 1)));
	return 0;
}
int Lua_Disarm_Beacons(lua_State *L)
{
	Disarm_Beacons(luaL_checknumber(L, 1));
	return 0;
}
int Lua_Disarm_Nearest_Beacon(lua_State *L)
{
	Disarm_Nearest_Beacon(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2), luaL_checknumber(L, 3));
	return 0;
}
int Lua_Disarm_C4(lua_State *L)
{
	Disarm_C4(Commands->Find_Object(luaL_checknumber(L, 1)));
	return 0;
}
int Lua_Disarm_All_Proxy_C4(lua_State *L)
{
	Disarm_All_Proxy_C4(luaL_checknumber(L, 1));
	return 0;
}
int Lua_Disarm_All_C4(lua_State *L)
{
	Disarm_All_C4(luaL_checknumber(L, 1));
	return 0;
}
int Lua_Get_Current_Weapon(lua_State *L)
{
	lua_pushstring(L, Get_Current_Weapon(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 0;
}
int Lua_Get_Weapon_Count(lua_State *L)
{
	lua_pushnumber(L, Get_Weapon_Count(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_Weapon(lua_State *L)
{
	lua_pushstring(L, Get_Weapon(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2)));
	return 1;
}
int Lua_Has_Weapon(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	lua_pushnumber(L, Has_Weapon(Commands->Find_Object(luaL_checknumber(L, 1)), x));
	return 1;
}
int Lua_Find_Beacon(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Find_Beacon(luaL_checknumber(L, 1), luaL_checknumber(L, 2))));
	return 1;
}
int Lua_Get_C4_Count(lua_State *L)
{
	lua_pushnumber(L, Get_C4_Count(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Beacon_Count(lua_State *L)
{
	lua_pushnumber(L, Get_Beacon_Count(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_Mine_Limit(lua_State *L)
{
	lua_pushnumber(L, Get_Mine_Limit());
	return 1;
}
int Lua_Get_C4_Mode(lua_State *L)
{
	lua_pushnumber(L, Get_C4_Mode(Commands->Find_Object(luaL_checknumber(L, 1))));
	return 1;
}
int Lua_Get_C4_Count_Proximity(lua_State *L)
{
	lua_pushnumber(L, Get_C4_Count_Proximity(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_C4_Count_Remote(lua_State *L)
{
	lua_pushnumber(L, Get_C4_Count_Remote(luaL_checknumber(L, 1)));
	return 1;
}
int Lua_Get_C4_Planter(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_C4_Planter(Commands->Find_Object(luaL_checknumber(L, 1)))));
	return 1;
}
int Lua_Get_C4_Attached(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_C4_Attached(Commands->Find_Object(luaL_checknumber(L, 1)))));
	return 1;
}
int Lua_Get_Beacon_Planter(lua_State *L)
{
	lua_pushnumber(L, Get_ID(Get_Beacon_Planter(Commands->Find_Object(luaL_checknumber(L, 1)))));
	return 1;
}

int Lua_Create_Object(lua_State *L)
{
	const char *preset = luaL_checkstring(L, 1);
	if(!preset)
	{
		return 0;
	}
	Vector3 pos;
	if(!Get_Vector3(L, -1, &pos))
	{
		luaL_error(L, "Invalid argument, expected a table.");
		return 0;
	}


	lua_pushnumber(L, Commands->Get_ID(Commands->Create_Object(preset, pos)));
	return 1;
}
int Lua_Destroy_Object(lua_State *L)
{
  Commands->Destroy_Object(Commands->Find_Object(luaL_checknumber(L, 1)));
  return 0;
}

int Lua_Get_Preset_Name(lua_State *L)
{
	const char *ptr = Commands->Get_Preset_Name(Commands->Find_Object(luaL_checknumber(L, 1)));
	if(!ptr)
	{
		return 0;
	}
	lua_pushstring(L, ptr);
	return 1;
}

int Lua_Get_Position(lua_State *L)
{
	Vector3 pos = Commands->Get_Position(Commands->Find_Object(luaL_checknumber(L, 1)));

	lua_newtable(L);
	int objectTable = lua_gettop(L);

	lua_pushstring(L, "X");
	lua_pushnumber(L, pos.X);
	lua_settable(L, objectTable);

	lua_pushstring(L, "Y");
	lua_pushnumber(L,pos.Y);
	lua_settable(L, objectTable);

	lua_pushstring(L, "Z");
	lua_pushnumber(L, pos.Z);
	lua_settable(L, objectTable);

	return 1;
}
int Lua_Enable_Vehicle_Transitions(lua_State *L)
{
	Commands->Enable_Vehicle_Transitions(Commands->Find_Object(luaL_checknumber(L, 1)), luaL_checknumber(L, 2));
	return 0;
}

int Lua_Set_Model(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	if(!x) return 0;
	Commands->Set_Model(Commands->Find_Object(luaL_checknumber(L, 1)), x);
	return 0;
}

int Lua_Goto_Location(lua_State *L)
{
  ActionParamsStruct aps;
  Vector3 pos;
  if(!Get_Vector3(L, 1, &pos))
  {
	  luaL_error(L, "Invalid argument #1. Expected a table.");
	  return 0;
  }

  aps.Set_Goto_Location(pos, luaL_checknumber(L, 5), luaL_checknumber(L, 6), luaL_checknumber(L, 7));
  Commands->Action_Goto(Commands->Find_Object(luaL_checknumber(L, 1)), aps); 
  return 0;
}
int Lua_Goto_Object(lua_State *L)
{
  ActionParamsStruct aps;
  aps.Set_Goto(Commands->Find_Object(luaL_checknumber(L, 2)), luaL_checknumber(L, 3), luaL_checknumber(L,4));
  Commands->Action_Goto(Commands->Find_Object(luaL_checknumber(L, 1)), aps); 
  return 0;
}

int Lua_Disable_Physical_Collisions(lua_State *L)
{
	Commands->Disable_Physical_Collisions(Commands->Find_Object(luaL_checknumber(L, 1)));
	return 0;
}

int Lua_Enable_Collisions(lua_State *L)
{
	Commands->Enable_Collisions(Commands->Find_Object(luaL_checknumber(L, 1)));
	return 0;
}

int Lua_Random_Building(lua_State *L)
{
	GameObject *obj = Find_Building(Commands->Get_Random_Int(0, 1), Commands->Get_Random_Int(0, 9));
	while(!obj)
	{
		obj = Find_Building(Commands->Get_Random_Int(0, 1), Commands->Get_Random_Int(0, 9));
	}
	lua_pushnumber(L, Commands->Get_ID(obj));
	return 1;
}
int Lua_Get_Current_Map(lua_State *L)
{
	lua_pushstring(L, The_Game()->MapName);
	return 1;
}
int Lua_Get_Next_Map(lua_State *L)
{
	lua_pushstring(L, (The_Game()->MapList[The_Game()->MapNumber+1] == 0 ? The_Game()->MapList[0] : The_Game()->MapList[The_Game()->MapNumber+1]));
	return 1;
}
int Lua_Set_Position(lua_State *L)
{
	Vector3 pos;
	if(!Get_Vector3(L, 2, &pos))
	{
		luaL_error(L, "Bad argument #2, expected table.");
		return 0;
	}
	GameObject *obj = Commands->Find_Object(luaL_checknumber(L, 1));
	Commands->Set_Position(obj, pos);
	return 0;
}
int Lua_Apply_Damage(lua_State *L)
{
	int argc = lua_gettop(L);
	GameObject *obj = Commands->Find_Object(luaL_checknumber(L, 1));
	float amount = (float)luaL_checknumber(L, 2);
	const char *type = luaL_checkstring(L, 3);
	if(type)
	{
		GameObject *obj2 = (argc > 3 ? Commands->Find_Object(luaL_checknumber(L, 4)) : 0);
		Commands->Apply_Damage(obj, amount, type, obj2);
	}
	return 0;
}
int Lua_Get_Facing(lua_State *L)
{
	GameObject *obj = Commands->Find_Object(luaL_checknumber(L, 1));
	lua_pushnumber(L, Commands->Get_Facing(obj));
	return 1;
}
int Lua_Set_Facing(lua_State *L)
{
	GameObject *obj = Commands->Find_Object(luaL_checknumber(L, 1));
	float facing = (float)luaL_checknumber(L, 2);
	Commands->Set_Facing(obj, facing);
	return 0;
}

int Lua_Set_Clouds(lua_State *L)
{
	Commands->Set_Clouds(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3));
	return 0;
}
int Lua_Set_Ash(lua_State *L)
{
	bool enable = (luaL_checknumber(L, 3) > 0 ? 1 : 0);
	Commands->Set_Ash(luaL_checknumber(L, 1), luaL_checknumber(L, 2), enable);
	return 0;
}
int Lua_Set_Rain(lua_State *L)
{
	bool enable = (luaL_checknumber(L, 3) > 0 ? 1 : 0);
	Commands->Set_Snow(luaL_checknumber(L, 1), luaL_checknumber(L, 2), enable);
	return 0;
}
int Lua_Set_Snow(lua_State *L)
{
	bool enable = (luaL_checknumber(L, 3) > 0 ? 1 : 0);
	Commands->Set_Snow(luaL_checknumber(L, 1), luaL_checknumber(L, 2), enable);
	return 0;
}
int Lua_Set_Wind(lua_State *L)
{
	Commands->Set_Wind(luaL_checknumber(L, 1), luaL_checknumber(L, 2), luaL_checknumber(L, 3), luaL_checknumber(L, 4));
	return 0;
}
int Lua_Attach_Script(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	const char *y = luaL_checkstring(L, 3);
	if(!x || !y) return 0;
	Commands->Attach_Script(Commands->Find_Object(luaL_checknumber(L, 1)), x, y);
	return 0;
}
int Lua_Create_Object_At_Bone(lua_State *L)
{
	const char *x = luaL_checkstring(L, 2);
	const char *y = luaL_checkstring(L, 3);
	if(x && y)
	{
		lua_pushnumber(L, Commands->Get_ID(Commands->Create_Object_At_Bone(Commands->Find_Object(luaL_checknumber(L, 1)), x, y)));
		return 1;
	}
	return 0;
}
int Lua_Attach_To_Object_Bone(lua_State *L)
{
	const char *x = luaL_checkstring(L, 3);
	if(x)
	{
		Commands->Attach_To_Object_Bone(Commands->Find_Object(luaL_checknumber(L, 1)), Commands->Find_Object(luaL_checknumber(L, 2)), x);
	}
	return 0;
}
int Lua_Display_Health_Bar(lua_State *L)
{
	bool enable = (luaL_checknumber(L, 2) > 0 ? 1 : 0);
	Commands->Display_Health_Bar(Commands->Find_Object(luaL_checknumber(L, 1)), enable);
	return 0;
}

int Lua_Create_Script_Zone(lua_State *L)
{	
	if(!lua_istable(L, -1))
	{
		luaL_error(L, "Invalid argument #3 to Create_Script_Zone. Expected table");
		return 0;
	}

	if(!lua_istable(L, -2))
	{
		luaL_error(L, "Invalid argument #2 to Create_Script_Zone. Expected table");
		return 0;
	}

	const char *preset = luaL_checkstring(L, 1);
	if(!preset) return 0;

	Vector3 position,extent;
	Get_Vector3(L, -2, &position);
	Get_Vector3(L, -1, &extent);

	OBBoxClass box;
	memset((void *)&box.Basis, 0, 3*3);
	box.Basis[0][0] = 1.0f;
	box.Basis[1][1] = 1.0f;
	box.Center = position;
	box.Extent = extent;
	
	lua_pushnumber(L, Commands->Get_ID(Create_Zone(preset, box)));	
	return 1;
}

int Lua_tClock(lua_State *L)
{
	lua_pushnumber(L, clock());
	return 1;
}

int Lua_Invoke(lua_State *L)
{
	const char *x = luaL_checkstring(L, 1);
	const char *y = luaL_checkstring(L, 2);
	if(x && y)
	{
		LuaManager::CallInvoke(x, y);
	}
	
	return 0;
}

int Lua_RequestSerial(lua_State *L)
{
	StringClass stub;
	stub.Format("%d", Commands->Get_Random_Int(0, 0xFFFFFF));
	RequestSerial(luaL_checknumber(L, 1), stub);
	return 0;
}

int Lua_GetTimeRemaining(lua_State *L)
{
	lua_pushnumber(L, The_Game()->GameDuration_Seconds > 0 ? The_Game()->TimeRemaining_Seconds : -1);
	return 1;
}

int Lua_Get_Health(lua_State *L)
{
	GameObject *x = Commands->Find_Object(luaL_checknumber(L, 1));
	if(!x) return 0;

	lua_pushnumber(L, Commands->Get_Health(x));
	return 1;
}

int Lua_Get_Max_Health(lua_State *L)
{
	GameObject *x = Commands->Find_Object(luaL_checknumber(L, 1));
	if(!x) return 0;

	lua_pushnumber(L, Commands->Get_Max_Health(x));
	return 1;
}

int Lua_Get_Shield_Strength(lua_State *L)
{
	GameObject *x = Commands->Find_Object(luaL_checknumber(L, 1));
	if(!x) return 0;

	lua_pushnumber(L, Commands->Get_Shield_Strength(x));
	return 1;
}

int Lua_Get_Max_Shield_Strength(lua_State *L)
{
	GameObject *x = Commands->Find_Object(luaL_checknumber(L, 1));
	if(!x) return 0;

	lua_pushnumber(L, Commands->Get_Max_Shield_Strength(x));
	return 1;
}

int Lua_LongToIP(lua_State*L)
{
	unsigned long lIP = luaL_checknumber(L, 1);	
	unsigned char *IP = (unsigned char *)&lIP;
	lua_pushnumber(L, IP[3]);
	lua_pushnumber(L, IP[2]);
	lua_pushnumber(L, IP[1]);
	lua_pushnumber(L, IP[0]);
	return 4;
}

int Lua_IPToLong(lua_State*L)
{
	unsigned long IP = 0;
	unsigned char *x = (unsigned char *)&IP;
	x[3] = luaL_checknumber(L, 1);
	x[2] = luaL_checknumber(L, 2);
	x[1] = luaL_checknumber(L, 3);
	x[0] = luaL_checknumber(L, 4);
	char str[256];
	sprintf(str, "%lu", IP);
	lua_pushstring(L, str);
	return 1;
}

int Lua_Is_A_Star(lua_State *L)
{
	unsigned int obj = luaL_checknumber(L, 1);
	GameObject *x = Commands->Find_Object(obj);
	if(!x)
	{
		lua_pushboolean(L, 0);
	}
	else
	{
		if(Commands->Is_A_Star(x))
		{
			lua_pushboolean(L, 1);
		}
		else
		{
			lua_pushboolean(L, 0);
		}
	}
	return 1;
}	

int Lua_Enable_Stealth(lua_State *L)
{
	unsigned int obj = luaL_checknumber(L, 1);
	int stealth = luaL_checknumber(L, 2);
	GameObject *o = Commands->Find_Object(obj);
	if(o)
	{
		Commands->Enable_Stealth(o, stealth == 0 ? false : true);
	}
	else
	{
		luaL_argerror(L, 1, "Not a valid GameObject");
	}
	return 0;	
}

int Lua_Get_Rotation(lua_State *L)
{
	lua_newtable(L);
	int rotationTable = lua_gettop(L);
	for(int i = 0;; i++)
	{
		const char *x = The_Game()->MapList[i];
		if(*x != 0)
		{
			lua_pushstring(L, x);
			lua_rawseti(L, rotationTable, i+1);
		}
		else
		{
			break;
		}
	}
	return 1;
}

int Lua_Get_All_Players(lua_State *L)
{
	lua_newtable(L);
	int playerTable = lua_gettop(L);
	int index = 1;

	for(GenericSLNode *x = PlayerList->HeadNode; x; x = x->NodeNext)
	{
		cPlayer *p = (cPlayer *)x->NodeData;
		if(!p->IsInGame || !p->IsActive)
		{
			continue;
		}

		lua_pushnumber(L, p->PlayerId);
		lua_rawseti(L, playerTable, index++);
	}
	return 1;
}

int Lua_Get_All_Vehicles(lua_State *L)
{
	lua_newtable(L);
	int vehicleTable = lua_gettop(L);
	int index = 1;

	for(GenericSLNode *x = SmartGameObjList->HeadNode; x; x = x->NodeNext)
	{
		GameObject *o = (GameObject *)x->NodeData;
		if(!Is_Vehicle(o))
		{
			continue;
		}

		lua_pushnumber(L, Commands->Get_ID(o));
		lua_rawseti(L, vehicleTable, index++);
	}
	return 1;
}

int Lua_Get_All_Buildings(lua_State *L)
{
	lua_newtable(L);
	int buildingTable = lua_gettop(L);
	int index = 1;

	for(GenericSLNode *x = BuildingGameObjList->HeadNode; x; x = x->NodeNext)
	{
		GameObject *o = (GameObject *)x->NodeData;

		lua_pushnumber(L, Commands->Get_ID(o));
		lua_rawseti(L, buildingTable, index++);
	}
	return 1;
}

int Lua_Get_All_Objects(lua_State *L)
{
	lua_newtable(L);
	int objectTable = lua_gettop(L);
	int index = 1;

	for(GenericSLNode *x = BaseGameObjList->HeadNode; x; x = x->NodeNext)
	{
		GameObject *o = (GameObject *)x->NodeData;

		lua_pushnumber(L, Commands->Get_ID(o));
		lua_rawseti(L, objectTable, index++);
	}
	return 1;
}

int Lua_Display_GDI_Player_Terminal_Player(lua_State *L)
{
	GameObject *o = Commands->Find_Object(luaL_checknumber(L, 1));
	if(o)
	{
		Display_GDI_Player_Terminal_Player(o);
	}
	return 0;
}

int Lua_Display_Nod_Player_Terminal_Player(lua_State *L)
{
	GameObject *o = Commands->Find_Object(luaL_checknumber(L, 1));
	if(o)
	{
		Display_NOD_Player_Terminal_Player(o);
	}
	return 0;
}

int Lua_Reload_All_Plugins(lua_State *L)
{
	LuaManager::Reload_Flag = 1;
	return 0;
}

int Lua_Set_Health(lua_State *L)
{
	GameObject *obj = Commands->Find_Object(luaL_checknumber(L, 1));
	if(!obj) return 0;
	Commands->Set_Health(obj, luaL_checknumber(L, 2));
	return 0;
}

int Lua_Set_Shield_Strength(lua_State *L)
{
	GameObject *obj = Commands->Find_Object(luaL_checknumber(L, 1));
	if(!obj) return 0;
	Commands->Set_Shield_Strength(obj, luaL_checknumber(L, 2));
	return 0;
}

int Lua_cPlayer(lua_State *L)
{
	int ID = luaL_checknumber(L, 1);
	if(ID == 0)
	{
		return 0;
	}

	cPlayer *p = 0;
	for(GenericSLNode *x = PlayerList->HeadNode; x; x = x->NodeNext)
	{
		if(((cPlayer *)x->NodeData)->PlayerId == ID)
		{
			p = (cPlayer *)x->NodeData;
			break;
		}
	}

	if(p)
	{
		lua_newtable(L);

		lua_pushnumber(L, p->AlliesKilled);
		lua_setfield(L, -2, "AlliesKilled");
		lua_pushnumber(L, p->ArmHit);
		lua_setfield(L, -2, "ArmHit");
		lua_pushnumber(L, p->ArmShots);
		lua_setfield(L, -2, "ArmShots");
		lua_pushnumber(L, p->BuildingDestroyed);
		lua_setfield(L, -2, "BuildingDestroyed");
		lua_pushnumber(L, p->ClientUpdateFrequency);
		lua_setfield(L, -2, "ClientUpdateFrequency");
		lua_pushnumber(L, p->CreationTime);
		lua_setfield(L, -2, "CreationTime");
		lua_pushnumber(L, p->CreditGrant);
		lua_setfield(L, -2, "CreditGrant");
		lua_pushnumber(L, p->CrotchHit);
		lua_setfield(L, -2, "CrotchHit");
		lua_pushnumber(L, p->CrotchShots);
		lua_setfield(L, -2, "CrotchShots");
		lua_pushnumber(L, p->DamageScaleFactor);
		lua_setfield(L, -2, "DamageScaleFactor");
		lua_pushnumber(L, p->Deaths.Get());
		lua_setfield(L, -2, "Deaths");
		lua_pushnumber(L, p->EnemiesKilled);
		lua_setfield(L, -2, "EnemiesKilled");
		lua_pushnumber(L, p->FinalHealth);
		lua_setfield(L, -2, "FinalHealth");
		lua_pushnumber(L, p->Fps);
		lua_setfield(L, -2, "Fps");
		lua_pushnumber(L, p->GameTime);
		lua_setfield(L, -2, "GameTime");
		lua_pushnumber(L, p->HeadHit);
		lua_setfield(L, -2, "HeadHit");
		lua_pushnumber(L, p->HeadShots);
		lua_setfield(L, -2, "HeadShots");
		lua_pushnumber(L, p->IpAddress);
		lua_setfield(L, -2, "IpAddress");
		lua_pushboolean(L, p->IsActive);
		lua_setfield(L, -2, "IsActive");
		lua_pushboolean(L, p->IsHuman);
		lua_setfield(L, -2, "IsHuman");
		lua_pushboolean(L, p->IsInGame);
		lua_setfield(L, -2, "IsInGame");
		lua_pushboolean(L, p->IsWaitingForIntermission);
		lua_setfield(L, -2, "IsWaitingForIntermission");
		lua_pushnumber(L, p->JoinTime);
		lua_setfield(L, -2, "JoinTime");
		lua_pushnumber(L, p->Kills.Get());
		lua_setfield(L, -2, "Kills");
		lua_pushnumber(L, p->KillsFromVehicle);
		lua_setfield(L, -2, "KillsFromVehicle");
		lua_pushnumber(L, p->LastDamaged);
		lua_setfield(L, -2, "LastDamaged");
		lua_pushnumber(L, p->LastDamager);
		lua_setfield(L, -2, "LastDamager");
		lua_pushnumber(L, p->LegHit);
		lua_setfield(L, -2, "LegHit");
		lua_pushnumber(L, p->LegShots);
		lua_setfield(L, -2, "LegShots");
		lua_pushnumber(L, p->Money.Get());
		lua_setfield(L, -2, "Money");
		lua_pushnumber(L, p->Ping);
		lua_setfield(L, -2, "Ping");
		lua_pushnumber(L, p->PlayerId);
		lua_setfield(L, -2, "PlayerId");
		
		char pName[256];
		sprintf(pName, "%S", (const wchar_t *)p->PlayerName);
		lua_pushstring(L, pName);
		lua_setfield(L, -2, "PlayerName");

		lua_pushnumber(L, p->PlayerType.Get());
		lua_setfield(L, -2, "PlayerType");
		lua_pushnumber(L, p->PowerupsCollected);
		lua_setfield(L, -2, "PowerupsCollected");
		lua_pushnumber(L, p->Rung.Get());
		lua_setfield(L, -2, "Rung");
		lua_pushnumber(L, p->Score.Get());
		lua_setfield(L, -2, "Score");
		lua_pushnumber(L, p->SessionTime);
		lua_setfield(L, -2, "SessionTime");
		lua_pushnumber(L, p->ShotsFired);
		lua_setfield(L, -2, "ShotsFired");
		lua_pushnumber(L, p->Squishes);
		lua_setfield(L, -2, "Squishes");
		lua_pushnumber(L, p->TorsoHit);
		lua_setfield(L, -2, "TorsoHit");
		lua_pushnumber(L, p->TorsoShots);
		lua_setfield(L, -2, "TorsoShots");
		lua_pushnumber(L, p->TotalTime);
		lua_setfield(L, -2, "TotalTime");
		lua_pushnumber(L, p->VehiclesDestroyed);
		lua_setfield(L, -2, "VehiclesDestroyed");
		lua_pushnumber(L, p->VehicleTime);
		lua_setfield(L, -2, "VehicleTime");

		return 1;
	}

	return 0;
}

int Lua_The_Game(lua_State *L)
{
	lua_newtable(L);
	cGameData *data = The_Game();
	lua_pushboolean(L, data->CanRepairBuildings);
	lua_setfield(L, -2, "CanRepairBuildings");
	lua_pushnumber(L, data->CFGModTime);
	lua_setfield(L, -2, "CFGModTime");
	lua_pushnumber(L, data->CurrentPlayers);
	lua_setfield(L, -2, "CurrentPlayers");
	lua_pushboolean(L, data->DoMapsLoop);
	lua_setfield(L, -2, "DoMapsLoop");
	lua_pushboolean(L, data->DriverIsAlwaysGunner);
	lua_setfield(L, -2, "DriverIsAlwaysGunner");
	lua_pushnumber(L, data->FrameCount);
	lua_setfield(L, -2, "FrameCount");
	lua_pushnumber(L, data->GameDuration_Seconds);
	lua_setfield(L, -2, "GameDuration_Seconds");
	lua_pushboolean(L, data->GameplayPermitted);
	lua_setfield(L, -2, "GameplayPermitted");
	lua_pushnumber(L, data->GameStartTime);
	lua_setfield(L, -2, "GameStartTime");
	char GameTitle[256];
	wcstombs(GameTitle, (const wchar_t *)data->GameTitle, 256);
	lua_pushstring(L, GameTitle);
	lua_setfield(L, -2, "GameTitle");
	lua_pushboolean(L, data->GrantWeapons);
	lua_setfield(L, -2, "GrantWeapons");
	lua_pushstring(L, data->INI);
	lua_setfield(L, -2, "INI");
	lua_pushnumber(L, data->IntermissionTime_Seconds);
	lua_setfield(L, -2, "IntermissionTime_Seconds");
	lua_pushnumber(L, data->IntermissionTimeLeft);
	lua_setfield(L, -2, "IntermissionTimeLeft");
	lua_pushnumber(L, data->IP);
	lua_setfield(L, -2, "IP");
	lua_pushboolean(L, data->IsAutoRestart);
	lua_setfield(L, -2, "IsAutoRestart");
	lua_pushboolean(L, data->IsClanGame);
	lua_setfield(L, -2, "IsClanGame");
	lua_pushboolean(L, data->IsDedicated);
	lua_setfield(L, -2, "IsDedicated");
	lua_pushboolean(L, data->IsFriendlyFirePermitted);
	lua_setfield(L, -2, "IsFriendlyFirePermitted");
	lua_pushboolean(L, data->IsLaddered);
	lua_setfield(L, -2, "IsLaddered");
	lua_pushboolean(L, data->IsPassworded);
	lua_setfield(L, -2, "IsPassworded");
	lua_pushboolean(L, data->IsQuickMatch);
	lua_setfield(L, -2, "IsQuickMatch");
	lua_pushboolean(L, data->IsTeamChangingAllowed);
	lua_setfield(L, -2, "IsTeamChangingAllowed");
	lua_pushboolean(L, data->MapCycleOver);
	lua_setfield(L, -2, "MapCycleOver");
	lua_pushstring(L, data->MapName);
	lua_setfield(L, -2, "MapName");
	lua_pushnumber(L, data->MapNumber);
	lua_setfield(L, -2, "MapNumber");
	lua_pushnumber(L, data->MaxPlayers);
	lua_setfield(L, -2, "MaxPlayers");
	lua_pushnumber(L, data->MaxWorldDistance);
	lua_setfield(L, -2, "MaxWorldDistance");
	lua_pushnumber(L, data->MinQualifyingTime_Minutes);
	lua_setfield(L, -2, "MinQualifyingTime_Minutes");
	lua_pushstring(L, data->ModName);
	lua_setfield(L, -2, "ModName");
	char Motd[256];
	wcstombs(Motd, (const wchar_t *)data->Motd, 256);
	lua_pushstring(L, Motd);
	lua_setfield(L, -2, "Motd");
	lua_pushnumber(L, data->MVPCount);
	lua_setfield(L, -2, "MVPCount");
	char MVPName[256];
	wcstombs(MVPName, (const wchar_t *)data->MVPName, 256);
	lua_pushstring(L, MVPName);
	lua_setfield(L, -2, "MVPName");
	char Owner[256];
	wcstombs(Owner, (const wchar_t *)data->Owner, 256);
	lua_pushstring(L, Owner);
	lua_setfield(L, -2, "Owner");
	char Password[256];
	wcstombs(Password, (const wchar_t *)data->Password, 256);
	lua_pushstring(L, Password);
	lua_setfield(L, -2, "Password");
	lua_pushnumber(L, data->Port);
	lua_setfield(L, -2, "Port");
	lua_pushnumber(L, data->RadarMode);
	lua_setfield(L, -2, "RadarMode");
	lua_pushboolean(L, data->RemixTeams);
	lua_setfield(L, -2, "RemixTeams");
	char SettingsDescription[256];
	wcstombs(SettingsDescription, (const wchar_t *)data->SettingsDescription, 256);
	lua_pushstring(L, SettingsDescription);
	lua_setfield(L, -2, "SettingsDescription");
	lua_pushboolean(L, data->SpawnWeapons);
	lua_setfield(L, -2, "SpawnWeapons");
	lua_pushboolean(L, data->StringVersionsMatch);
	lua_setfield(L, -2, "StringVersionsMatch");
	lua_pushnumber(L, data->TimeLimit_Minutes);
	lua_setfield(L, -2, "TimeLimit_Minutes");
	lua_pushnumber(L, data->TimeRemaining_Seconds);
	lua_setfield(L, -2, "TimeRemaining_Seconds");
	lua_pushboolean(L, data->UseLagReduction);
	lua_setfield(L, -2, "UseLagReduction");
	lua_pushnumber(L, data->WinnerID);
	lua_setfield(L, -2, "WinnerID");
	lua_pushnumber(L, data->WinType);
	lua_setfield(L, -2, "WinType");

	return 1;
}

int Lua_Set_cPlayer(lua_State *L)
{
	int ID = luaL_checknumber(L, 1);
	if(ID == 0)
	{
		return 0;
	}
	if(!lua_istable(L, 2))
	{
		luaL_error(L, "Invalid argument #2 to Set_cPlayer. Expected a table.");
		return 0;
	}

	cPlayer *p = 0;
	for(GenericSLNode *x = PlayerList->HeadNode; x; x = x->NodeNext)
	{
		if(((cPlayer *)x->NodeData)->PlayerId == ID)
		{
			p = (cPlayer *)x->NodeData;
			break;
		}
	}

	if(p)
	{
		lua_getfield(L, -1, "AlliesKilled");
		if(lua_type(L, -1) > 0) p->AlliesKilled = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "ArmHit");
		if(lua_type(L, -1) > 0) p->ArmHit = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "ArmShots");
		if(lua_type(L, -1) > 0) p->ArmShots = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "BuildingDestroyed");
		if(lua_type(L, -1) > 0) p->BuildingDestroyed = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "ClientUpdateFrequency");
		if(lua_type(L, -1) > 0) p->ClientUpdateFrequency = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "CreditGrant");
		if(lua_type(L, -1) > 0) p->CreditGrant = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "CrotchHit");
		if(lua_type(L, -1) > 0) p->CrotchHit = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "CrotchShots");
		if(lua_type(L, -1) > 0) p->CrotchShots = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "DamageScaleFactor");
		if(lua_type(L, -1) > 0) p->DamageScaleFactor = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "Deaths");
		if(lua_type(L, -1) > 0) 
		{
			int Deaths = lua_tonumber(L, -1);
			p->Deaths.Set(Deaths);
		}
		lua_pop(L, 1);

		lua_getfield(L, -1, "EnemiesKilled");
		if(lua_type(L, -1) > 0) p->EnemiesKilled = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "GameTime");
		if(lua_type(L, -1) > 0) p->GameTime = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "HeadHit");
		if(lua_type(L, -1) > 0) p->HeadHit = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "HeadShots");
		if(lua_type(L, -1) > 0) p->HeadShots = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "IsHuman");
		if(lua_type(L, -1) > 0) p->IsHuman = lua_toboolean(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "Kills");
		if(lua_type(L, -1) > 0) 
		{
			int Kills = lua_tonumber(L, -1);
			p->Kills.Set(Kills);
		}
		lua_pop(L, 1);

		lua_getfield(L, -1, "KillsFromVehicle");
		if(lua_type(L, -1) > 0) p->KillsFromVehicle = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "LastDamaged");
		if(lua_type(L, -1) > 0) p->LastDamaged = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "LastDamager");
		if(lua_type(L, -1) > 0) p->LastDamager = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "LegHit");
		if(lua_type(L, -1) > 0) p->LegHit = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "LegShots");
		if(lua_type(L, -1) > 0) p->LegShots = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "Money");
		if(lua_type(L, -1) > 0) 
		{
			float Money = lua_tonumber(L, -1);
			p->Money.Set(Money);
		}
		lua_pop(L, 1);

		lua_getfield(L, -1, "Ping");
		if(lua_type(L, -1) > 0) p->Ping = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "PlayerId");
		if(lua_type(L, -1) > 0) p->PlayerId = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "PlayerType");
		if(lua_type(L, -1) > 0) 
		{
			int PlayerType = lua_tonumber(L, -1);
			p->PlayerType.Set(PlayerType);
		}
		lua_pop(L, 1);

		lua_getfield(L, -1, "PowerupsCollected");
		if(lua_type(L, -1) > 0) p->PowerupsCollected = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "Rung");
		if(lua_type(L, -1) > 0) 
		{
			int Rung = lua_tonumber(L, -1);
			p->Rung.Set(Rung);
		}
		lua_pop(L, 1);

		lua_getfield(L, -1, "Score");
		if(lua_type(L, -1) > 0) 
		{
			float Score = lua_tonumber(L, -1);
			p->Score.Set(Score);
		}
		lua_pop(L, 1);

		lua_getfield(L, -1, "SessionTime");
		if(lua_type(L, -1) > 0) p->SessionTime = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "ShotsFired");
		if(lua_type(L, -1) > 0) p->ShotsFired = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "Squishes");
		if(lua_type(L, -1) > 0) p->Squishes = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "TorsoHit");
		if(lua_type(L, -1) > 0) p->TorsoHit = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "TorsoShots");
		if(lua_type(L, -1) > 0) p->TorsoShots = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "TotalTime");
		if(lua_type(L, -1) > 0) p->TotalTime = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "VehiclesDestroyed");
		if(lua_type(L, -1) > 0) p->VehiclesDestroyed = lua_tonumber(L, -1);
		lua_pop(L, 1);

		lua_getfield(L, -1, "VehicleTime");
		if(lua_type(L, -1) > 0) p->VehicleTime = lua_tonumber(L, -1);
		lua_pop(L, 1);


		return 1;
	}

	return 0;
}

int Lua_Set_The_Game(lua_State *L)
{
	if(!lua_istable(L, -1))
	{
		luaL_error(L, "Invalid argument #1 to Set_The_Game. Expected table.");
		return 0;
	}
	cGameData *data = The_Game();
	lua_getfield(L, -1, "CanRepairBuildings");
	if(lua_type(L, -1) > 0) data->CanRepairBuildings = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "DoMapsLoop");
	if(lua_type(L, -1) > 0) data->DoMapsLoop = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "DriverIsAlwaysGunner");
	if(lua_type(L, -1) > 0) data->DriverIsAlwaysGunner = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "GameplayPermitted");
	if(lua_type(L, -1) > 0) data->GameplayPermitted = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "GameTitle");
	if(lua_type(L, -1) > 0) data->GameTitle.Convert_From(lua_tostring(L, -1));
	lua_pop(L, 1);

	lua_getfield(L, -1, "GrantWeapons");
	if(lua_type(L, -1) > 0) data->GrantWeapons = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "IntermissionTime_Seconds");
	if(lua_type(L, -1) > 0) data->IntermissionTime_Seconds = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "IntermissionTimeLeft");
	if(lua_type(L, -1) > 0) data->IntermissionTimeLeft = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "IsAutoRestart");
	if(lua_type(L, -1) > 0) data->IsAutoRestart = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "IsClanGame");
	if(lua_type(L, -1) > 0) data->IsClanGame = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "IsDedicated");
	if(lua_type(L, -1) > 0) data->IsDedicated = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "IsFriendlyFirePermitted");
	if(lua_type(L, -1) > 0) data->IsFriendlyFirePermitted = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "IsLaddered");
	if(lua_type(L, -1) > 0) data->IsLaddered = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "IsPassworded");
	if(lua_type(L, -1) > 0) data->IsPassworded = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "IsQuickMatch");
	if(lua_type(L, -1) > 0) data->IsQuickMatch = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "IsTeamChangingAllowed");
	if(lua_type(L, -1) > 0) data->IsTeamChangingAllowed = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "MapCycleOver");
	if(lua_type(L, -1) > 0) data->MapCycleOver = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "MapNumber");
	if(lua_type(L, -1) > 0) data->MapNumber = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "MaxPlayers");
	if(lua_type(L, -1) > 0) data->MaxPlayers = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "MaxWorldDistance");
	if(lua_type(L, -1) > 0) data->MaxWorldDistance = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "MinQualifyingTime_Minutes");
	if(lua_type(L, -1) > 0) data->MinQualifyingTime_Minutes = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "Motd");
	if(lua_type(L, -1) > 0) data->Motd.Convert_From(lua_tostring(L, -1));
	lua_pop(L, 1);

	lua_getfield(L, -1, "MVPCount");
	if(lua_type(L, -1) > 0) data->MVPCount = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "MVPName");
	if(lua_type(L, -1) > 0) data->MVPName.Convert_From(lua_tostring(L, -1));
	lua_pop(L, 1);

	lua_getfield(L, -1, "Password");
	if(lua_type(L, -1) > 0) data->Password.Convert_From(lua_tostring(L, -1));
	lua_pop(L, 1);

	lua_getfield(L, -1, "RadarMode");
	if(lua_type(L, -1) > 0) data->RadarMode = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "RemixTeams");
	if(lua_type(L, -1) > 0) data->RemixTeams = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "SettingsDescription");
	if(lua_type(L, -1) > 0) data->SettingsDescription.Convert_From(lua_tostring(L, -1));
	lua_pop(L, 1);

	lua_getfield(L, -1, "SpawnWeapons");
	if(lua_type(L, -1) > 0) data->SpawnWeapons = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "StringVersionsMatch");
	if(lua_type(L, -1) > 0) data->StringVersionsMatch = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "TimeLimit_Minutes");
	if(lua_type(L, -1) > 0) data->TimeLimit_Minutes = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "TimeRemaining_Seconds");
	if(lua_type(L, -1) > 0) data->TimeRemaining_Seconds = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "UseLagReduction");
	if(lua_type(L, -1) > 0) data->UseLagReduction = lua_toboolean(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "WinnerID");
	if(lua_type(L, -1) > 0) data->WinnerID = lua_tonumber(L, -1);
	lua_pop(L, 1);

	lua_getfield(L, -1, "WinType");
	if(lua_type(L, -1) > 0) data->WinType = lua_tonumber(L, -1);
	lua_pop(L, 1);

	return 0;
}

void inline MemoryWrite(void *address, unsigned char c)
{
	DWORD old;
	VirtualProtect((void *)address, 1, PAGE_EXECUTE_READWRITE, &old);
	memcpy((void *)address, &c, 1);
	VirtualProtect((void *)address, 1, old, &old);
}

void inline MemoryRead(void *address, unsigned char *c)
{
	DWORD old;
	VirtualProtect((void *)address, 1, PAGE_EXECUTE_READWRITE, &old);
	memcpy(c, address, 1);
	VirtualProtect((void *)address, 1, old, &old);
}

int Lua_Memory_Write(lua_State *L)
{
	unsigned int Address = luaL_checknumber(L, 1);
	if(Address == 0)
	{
		return 0;
	}

	if(!lua_istable(L, 2))
	{
		luaL_typerror(L, 2, lua_typename(L, LUA_TTABLE));
		return 0;
	}

	for(int i = 1;;i++)
	{
		lua_rawgeti(L, 2, i);
		if(lua_type(L, -1) <= 0)
		{
			lua_pop(L, 1);
			break;
		}
		else
		{
			unsigned char c = lua_tonumber(L, -1);
			MemoryWrite((void *)(Address+i-1), c);
			lua_pop(L, 1);
		}
	}
	return 0;
}

int Lua_Memory_Read(lua_State *L)
{
	unsigned int Address = luaL_checknumber(L, 1);
	int Count = luaL_checknumber(L, 2);

	if(Address == 0 || Count == 0)
	{
		return 0;
	}

	lua_newtable(L);

	for(int i = 0; i < Count; i++)
	{
		unsigned char c;
		MemoryRead((void *)(Address+i), &c);
		lua_pushnumber(L, c);
		lua_rawseti(L, -2, i+1);
	}
	return 1;
}

int Lua_Set_Shield_Type(lua_State *L)
{
	GameObject *o = Commands->Find_Object(luaL_checknumber(L, 1));
	if(!o) return 0;

	const char *s = luaL_checkstring(L, 2);
	if(!s) return 0;

	Commands->Set_Shield_Type(o, s);
	return 0;
}

void AddFunctions(lua_State *L)
{
	lua_register(L, "Console_Input",Lua_Console_Input);
	lua_register(L, "Console_Output",Lua_Console_Output);
	lua_register(L, "Get_Definition_Name",Lua_Get_Definition_Name);
	lua_register(L, "Get_Definition_ID",Lua_Get_Definition_ID);
	lua_register(L, "Get_Definition_Class_ID",Lua_Get_Definition_Class_ID);
	lua_register(L, "Is_Valid_Preset_ID",Lua_Is_Valid_Preset_ID);
	lua_register(L, "Is_Valid_Preset",Lua_Is_Valid_Preset);
	lua_register(L, "Set_Max_Health",Lua_Set_Max_Health);
	lua_register(L, "Set_Max_Shield_Strength",Lua_Set_Max_Shield_Strength);
	lua_register(L, "Get_Shield_Type",Lua_Get_Shield_Type);
	lua_register(L, "Get_Skin",Lua_Get_Skin);
	lua_register(L, "Set_Skin",Lua_Set_Skin);
	lua_register(L, "Power_Base",Lua_Power_Base); 
	lua_register(L, "Set_Can_Generate_Soldiers",Lua_Set_Can_Generate_Soldiers);
	lua_register(L, "Set_Can_Generate_Vehicles",Lua_Set_Can_Generate_Vehicles); 
	lua_register(L, "Destroy_Base",Lua_Destroy_Base);
	lua_register(L, "Beacon_Destroyed_Base",Lua_Beacon_Destroyed_Base);
	lua_register(L, "Enable_Base_Radar",Lua_Enable_Base_Radar);
	lua_register(L, "Is_Harvester",Lua_Is_Harvester);
	lua_register(L, "Is_Radar_Enabled",Lua_Is_Radar_Enabled); 
	lua_register(L, "Building_Type",Lua_Building_Type); 
	lua_register(L, "Is_Building_Dead",Lua_Is_Building_Dead); 
	lua_register(L, "Find_Building",Lua_Find_Building);
	lua_register(L, "Find_Base_Defense",Lua_Find_Base_Defense);
	lua_register(L, "Is_Map_Flying",Lua_Is_Map_Flying); 
	lua_register(L, "Find_Harvester",Lua_Find_Harvester);
	lua_register(L, "Is_Base_Powered",Lua_Is_Base_Powered);
	lua_register(L, "Can_Generate_Vehicles",Lua_Can_Generate_Vehicles);
	lua_register(L, "Can_Generate_Soliders",Lua_Can_Generate_Soliders);
	lua_register(L, "Is_A_Building",Lua_Is_A_Building);
	lua_register(L, "Get_Building_Count_Team",Lua_Get_Building_Count_Team);
	lua_register(L, "Find_Building_By_Team",Lua_Find_Building_By_Team);
	lua_register(L, "Find_Building_By_Name",Lua_Find_Building_By_Name);
	lua_register(L, "Find_Power_Plant",Lua_Find_Power_Plant);
	lua_register(L, "Find_Refinery",Lua_Find_Refinery);
	lua_register(L, "Find_Repair_Bay",Lua_Find_Repair_Bay);
	lua_register(L, "Find_Soldier_Factory",Lua_Find_Soldier_Factory);
	lua_register(L, "Find_Airstrip",Lua_Find_Airstrip);
	lua_register(L, "Find_War_Factory",Lua_Find_War_Factory);
	lua_register(L, "Find_Vehicle_Factory",Lua_Find_Vehicle_Factory);
	lua_register(L, "Find_Com_Center",Lua_Find_Com_Center);
	lua_register(L, "Is_Gameplay_Permitted",Lua_Is_Gameplay_Permitted);
	lua_register(L, "Is_Dedicated",Lua_Is_Dedicated); 
	lua_register(L, "Is_Linux",Lua_Is_Linux);
	lua_register(L, "Get_Current_Game_Mode",Lua_Get_Current_Game_Mode);
	lua_register(L, "Get_Harvester_Preset_ID",Lua_Get_Harvester_Preset_ID);
	lua_register(L, "Is_Harvester_Preset",Lua_Is_Harvester_Preset);
	lua_register(L, "Destroy_Connection",Lua_Destroy_Connection);
	lua_register(L, "Get_IP_Address",Lua_Get_IP_Address);
	lua_register(L, "Get_IP_Port",Lua_Get_IP_Port);
	lua_register(L, "Get_Bandwidth",Lua_Get_Bandwidth);
	lua_register(L, "Get_Ping",Lua_Get_Ping);
	lua_register(L, "Get_Kbits",Lua_Get_Kbits);
	lua_register(L, "Get_Object_Type",Lua_Get_Object_Type);
	lua_register(L, "Set_Object_Type",Lua_Set_Object_Type);
	lua_register(L, "Is_Building",Lua_Is_Building);
	lua_register(L, "Is_Soldier",Lua_Is_Soldier);
	lua_register(L, "Is_Vehicle",Lua_Is_Vehicle);
	lua_register(L, "Is_Cinematic",Lua_Is_Cinematic);
	lua_register(L, "Is_ScriptZone",Lua_Is_ScriptZone);
	lua_register(L, "Is_Powerup",Lua_Is_Powerup);
	lua_register(L, "Is_C4",Lua_Is_C4);
	lua_register(L, "Is_Beacon",Lua_Is_Beacon);
	lua_register(L, "Is_Armed",Lua_Is_Armed);
	lua_register(L, "Is_Simple",Lua_Is_Simple);
	lua_register(L, "Is_PowerPlant",Lua_Is_PowerPlant);
	lua_register(L, "Is_SoldierFactory",Lua_Is_SoldierFactory);
	lua_register(L, "Is_VehicleFactory",Lua_Is_VehicleFactory);
	lua_register(L, "Is_Airstrip",Lua_Is_Airstrip);
	lua_register(L, "Is_WarFactory",Lua_Is_WarFactory);
	lua_register(L, "Is_Refinery",Lua_Is_Refinery);
	lua_register(L, "Is_ComCenter",Lua_Is_ComCenter);
	lua_register(L, "Is_RepairBay",Lua_Is_RepairBay);
	lua_register(L, "Is_Scriptable",Lua_Is_Scriptable);
	lua_register(L, "Get_Building_Type",Lua_Get_Building_Type);
	lua_register(L, "Get_Object_Count",Lua_Get_Object_Count);
	lua_register(L, "Find_Random_Preset",Lua_Find_Random_Preset);
	lua_register(L, "Send_Custom_To_Team_Buildings",Lua_Send_Custom_To_Team_Buildings);
	lua_register(L, "Send_Custom_To_Team_Preset",Lua_Send_Custom_To_Team_Preset);
	lua_register(L, "Send_Custom_All_Objects",Lua_Send_Custom_All_Objects);
	lua_register(L, "Send_Custom_Event_To_Object",Lua_Send_Custom_Event_To_Object);
	lua_register(L, "Get_Is_Powerup_Persistant",Lua_Get_Is_Powerup_Persistant);
	lua_register(L, "Set_Is_Powerup_Persistant",Lua_Set_Is_Powerup_Persistant);
	lua_register(L, "Get_Powerup_Always_Allow_Grant",Lua_Get_Powerup_Always_Allow_Grant);
	lua_register(L, "Set_Powerup_Always_Allow_Grant",Lua_Set_Powerup_Always_Allow_Grant);
	lua_register(L, "Get_Powerup_Grant_Sound",Lua_Get_Powerup_Grant_Sound);
	lua_register(L, "Set_Powerup_Grant_Sound",Lua_Set_Powerup_Grant_Sound);
	lua_register(L, "Grant_Powerup",Lua_Grant_Powerup);
	lua_register(L, "Get_Vehicle",Lua_Get_Vehicle);
	lua_register(L, "Grant_Refill",Lua_Grant_Refill);
	lua_register(L, "Change_Character",Lua_Change_Character);
	lua_register(L, "Create_Vehicle",Lua_Create_Vehicle);
	lua_register(L, "Toggle_Fly_Mode",Lua_Toggle_Fly_Mode);
	lua_register(L, "Get_Vehicle_Occupant_Count",Lua_Get_Vehicle_Occupant_Count);
	lua_register(L, "Get_Vehicle_Occupant",Lua_Get_Vehicle_Occupant);
	lua_register(L, "Get_Vehicle_Driver",Lua_Get_Vehicle_Driver);
	lua_register(L, "Get_Vehicle_Gunner",Lua_Get_Vehicle_Gunner);
	lua_register(L, "Force_Occupant_Exit",Lua_Force_Occupant_Exit);
	lua_register(L, "Force_Occupants_Exit",Lua_Force_Occupants_Exit);
	lua_register(L, "Get_Vehicle_Return",Lua_Get_Vehicle_Return);
	lua_register(L, "Is_Stealth",Lua_Is_Stealth);
	lua_register(L, "Get_Fly_Mode",Lua_Get_Fly_Mode);
	lua_register(L, "Get_Vehicle_Seat_Count",Lua_Get_Vehicle_Seat_Count);
	lua_register(L, "Get_Spawn_Char",Lua_Get_Spawn_Char);
	lua_register(L, "Change_Spawn_Char",Lua_Change_Spawn_Char);
	lua_register(L, "Soldier_Transition_Vehicle",Lua_Soldier_Transition_Vehicle);
	lua_register(L, "Get_Vehicle_Mode",Lua_Get_Vehicle_Mode);
	lua_register(L, "Get_Team_Vehicle_Count",Lua_Get_Team_Vehicle_Count);
	lua_register(L, "Get_Vehicle_Owner",Lua_Get_Vehicle_Owner);
	lua_register(L, "Force_Occupants_Exit_Team",Lua_Force_Occupants_Exit_Team);
	lua_register(L, "Get_Vehicle_Definition_Mode",Lua_Get_Vehicle_Definition_Mode);
	lua_register(L, "IsInsideZone",Lua_IsInsideZone);
	lua_register(L, "Get_Vehicle_Definition_Mode_By_ID",Lua_Get_Vehicle_Definition_Mode_By_ID);
	lua_register(L, "Get_Zone_Type",Lua_Get_Zone_Type);
	lua_register(L, "IsAvailableForPurchase",Lua_IsAvailableForPurchase);
	lua_register(L, "Check_Transitions",Lua_Check_Transitions);
	lua_register(L, "Get_Vehicle_Gunner_Pos",Lua_Get_Vehicle_Gunner_Pos);
	lua_register(L, "Set_Vehicle_Is_Visible",Lua_Set_Vehicle_Is_Visible);
	lua_register(L, "Set_Vehicle_Gunner",Lua_Set_Vehicle_Gunner);
	lua_register(L, "Get_Model",Lua_Get_Model);
	lua_register(L, "Get_Animation_Frame",Lua_Get_Animation_Frame);
	lua_register(L, "Is_TrackedVehicle",Lua_Is_TrackedVehicle);
	lua_register(L, "Is_VTOLVehicle",Lua_Is_VTOLVehicle);
	lua_register(L, "Is_WheeledVehicle",Lua_Is_WheeledVehicle);
	lua_register(L, "Is_Motorcycle",Lua_Is_Motorcycle);
	lua_register(L, "Is_Door",Lua_Is_Door);
	lua_register(L, "Is_Elevator",Lua_Is_Elevator);
	lua_register(L, "Is_DamageableStaticPhys",Lua_Is_DamageableStaticPhys);
	lua_register(L, "Is_AccessablePhys",Lua_Is_AccessablePhys);
	lua_register(L, "Is_DecorationPhys",Lua_Is_DecorationPhys);
	lua_register(L, "Is_HumanPhys",Lua_Is_HumanPhys);
	lua_register(L, "Is_MotorVehicle",Lua_Is_MotorVehicle);
	lua_register(L, "Is_Phys3",Lua_Is_Phys3);
	lua_register(L, "Is_RigidBody",Lua_Is_RigidBody);
	lua_register(L, "Is_ShakeableStatricPhys",Lua_Is_ShakeableStatricPhys);
	lua_register(L, "Is_StaticAnimPhys",Lua_Is_StaticAnimPhys);
	lua_register(L, "Is_StaticPhys",Lua_Is_StaticPhys);
	lua_register(L, "Is_TimedDecorationPhys",Lua_Is_TimedDecorationPhys);
	lua_register(L, "Is_VehiclePhys",Lua_Is_VehiclePhys);
	lua_register(L, "Is_DynamicAnimPhys",Lua_Is_DynamicAnimPhys);
	lua_register(L, "Is_BuildingAggregate",Lua_Is_BuildingAggregate);
	lua_register(L, "Is_Projectile",Lua_Is_Projectile);
	lua_register(L, "Get_Physics",Lua_Get_Physics);
	lua_register(L, "Copy_Transform",Lua_Copy_Transform);
	lua_register(L, "Get_Mass",Lua_Get_Mass);
	lua_register(L, "Get_Htree_Name",Lua_Get_Htree_Name);
	lua_register(L, "Get_Sex",Lua_Get_Sex);
	lua_register(L, "Create_Effect_All_Of_Preset",Lua_Create_Effect_All_Of_Preset);
	lua_register(L, "Get_GameObj",Lua_Get_GameObj);
	lua_register(L, "Get_Player_ID",Lua_Get_Player_ID);
	lua_register(L, "Get_Player_Name",Lua_Get_Player_Name);
	lua_register(L, "Get_Player_Name_By_ID",Lua_Get_Player_Name_By_ID);
	lua_register(L, "Change_Team",Lua_Change_Team);
	lua_register(L, "Change_Team_By_ID",Lua_Change_Team_By_ID);
	lua_register(L, "Get_Player_Count",Lua_Get_Player_Count);
	lua_register(L, "Get_Team_Player_Count",Lua_Get_Team_Player_Count);
	lua_register(L, "Get_Team",Lua_Get_Team);
	lua_register(L, "Get_Rank",Lua_Get_Rank);
	lua_register(L, "Get_Kills",Lua_Get_Kills);
	lua_register(L, "Get_Deaths",Lua_Get_Deaths);
	lua_register(L, "Get_Score",Lua_Get_Score);
	lua_register(L, "Get_Money",Lua_Get_Money);
	lua_register(L, "Get_Kill_To_Death_Ratio",Lua_Get_Kill_To_Death_Ratio);
	lua_register(L, "Get_Part_Name",Lua_Get_Part_Name);
	lua_register(L, "Get_Part_Names",Lua_Get_Part_Names);
	lua_register(L, "Get_GameObj_By_Player_Name",Lua_Get_GameObj_By_Player_Name);
	lua_register(L, "Purchase_Item",Lua_Purchase_Item);
	lua_register(L, "Set_Ladder_Points",Lua_Set_Ladder_Points);
	lua_register(L, "Set_Rung",Lua_Set_Rung);
	lua_register(L, "Set_Money",Lua_Set_Money);
	lua_register(L, "Set_Score",Lua_Set_Score);
	lua_register(L, "Find_First_Player",Lua_Find_First_Player);
	lua_register(L, "Change_Player_Team",Lua_Change_Player_Team);
	lua_register(L, "Tally_Team_Size",Lua_Tally_Team_Size);
	lua_register(L, "Get_Team_Score",Lua_Get_Team_Score);
	lua_register(L, "Send_Custom_All_Players",Lua_Send_Custom_All_Players);
	lua_register(L, "Steal_Team_Credits",Lua_Steal_Team_Credits);
	lua_register(L, "Get_Team_Credits",Lua_Get_Team_Credits);
	lua_register(L, "Change_Team_2",Lua_Change_Team_2);
	lua_register(L, "Get_Player_Type",Lua_Get_Player_Type);
	lua_register(L, "Get_Team_Cost",Lua_Get_Team_Cost);
	lua_register(L, "Get_Cost",Lua_Get_Cost);
	lua_register(L, "Set_Enlisted",Lua_Set_Enlisted);
	lua_register(L, "Set_Beacon",Lua_Set_Beacon);
	lua_register(L, "Set_Refill",Lua_Set_Refill);
	lua_register(L, "Set_Preset",Lua_Set_Preset);
	lua_register(L, "Set_Alternate",Lua_Set_Alternate);
	lua_register(L, "Disable_Enlisted",Lua_Disable_Enlisted);
	lua_register(L, "Disable_Preset",Lua_Disable_Preset);
	lua_register(L, "Disable_Enlisted_By_Name",Lua_Disable_Enlisted_By_Name);
	lua_register(L, "Disable_Preset_By_Name",Lua_Disable_Preset_By_Name);
	lua_register(L, "Disable_All_Ground_Vehicles",Lua_Disable_All_Ground_Vehicles);
	lua_register(L, "Disable_All_Flying_Vehicles",Lua_Disable_All_Flying_Vehicles);
	lua_register(L, "Get_Team_Icon",Lua_Get_Team_Icon);
	lua_register(L, "Get_Icon",Lua_Get_Icon);
	lua_register(L, "Remove_Script",Lua_Remove_Script);
	lua_register(L, "Remove_All_Scripts",Lua_Remove_All_Scripts);
	lua_register(L, "Attach_Script_Preset",Lua_Attach_Script_Preset);
	lua_register(L, "Attach_Script_Type",Lua_Attach_Script_Type);
	lua_register(L, "Remove_Script_Preset",Lua_Remove_Script_Preset);
	lua_register(L, "Remove_Script_Type",Lua_Remove_Script_Type);
	lua_register(L, "Is_Script_Attached",Lua_Is_Script_Attached);
	lua_register(L, "Attach_Script_Once",Lua_Attach_Script_Once);
	lua_register(L, "Attach_Script_Preset_Once",Lua_Attach_Script_Preset_Once);
	lua_register(L, "Attach_Script_Type_Once",Lua_Attach_Script_Type_Once);
	lua_register(L, "Attach_Script_Building",Lua_Attach_Script_Building);
	lua_register(L, "Attach_Script_Is_Preset",Lua_Attach_Script_Is_Preset);
	lua_register(L, "Attach_Script_Is_Type",Lua_Attach_Script_Is_Type);
	lua_register(L, "Attach_Script_Player_Once",Lua_Attach_Script_Player_Once);
	lua_register(L, "Remove_Duplicate_Script",Lua_Remove_Duplicate_Script);
	lua_register(L, "Attach_Script_All_Buildings_Team",Lua_Attach_Script_All_Buildings_Team);
	lua_register(L, "Attach_Script_All_Turrets_Team",Lua_Attach_Script_All_Turrets_Team);
	lua_register(L, "Find_Building_With_Script",Lua_Find_Building_With_Script);
	lua_register(L, "Find_Object_With_Script",Lua_Find_Object_With_Script);
	lua_register(L, "Get_Translated_String",Lua_Get_Translated_String);
	lua_register(L, "Get_Translated_Preset_Name",Lua_Get_Translated_Preset_Name);
	lua_register(L, "Get_Translated_Weapon",Lua_Get_Translated_Weapon);
	lua_register(L, "Get_Current_Translated_Weapon",Lua_Get_Current_Translated_Weapon);
	lua_register(L, "Get_Team_Name",Lua_Get_Team_Name);
	lua_register(L, "Get_Vehicle_Name",Lua_Get_Vehicle_Name);
	lua_register(L, "Get_Translated_Definition_Name",Lua_Get_Translated_Definition_Name);
	lua_register(L, "Get_Current_Bullets",Lua_Get_Current_Bullets);
	lua_register(L, "Get_Current_Clip_Bullets",Lua_Get_Current_Clip_Bullets);
	lua_register(L, "Get_Current_Total_Bullets",Lua_Get_Current_Total_Bullets);
	lua_register(L, "Get_Total_Bullets",Lua_Get_Total_Bullets);
	lua_register(L, "Get_Clip_Bullets",Lua_Get_Clip_Bullets);
	lua_register(L, "Get_Bullets",Lua_Get_Bullets);
	lua_register(L, "Get_Current_Max_Bullets",Lua_Get_Current_Max_Bullets);
	lua_register(L, "Get_Current_Clip_Max_Bullets",Lua_Get_Current_Clip_Max_Bullets);
	lua_register(L, "Get_Current_Total_Max_Bullets",Lua_Get_Current_Total_Max_Bullets);
	lua_register(L, "Get_Max_Total_Bullets",Lua_Get_Max_Total_Bullets);
	lua_register(L, "Get_Max_Clip_Bullets",Lua_Get_Max_Clip_Bullets);
	lua_register(L, "Get_Max_Bullets",Lua_Get_Max_Bullets);
	lua_register(L, "Get_Position_Total_Bullets",Lua_Get_Position_Total_Bullets);
	lua_register(L, "Get_Position_Bullets",Lua_Get_Position_Bullets);
	lua_register(L, "Get_Position_Clip_Bullets",Lua_Get_Position_Clip_Bullets);
	lua_register(L, "Get_Position_Total_Max_Bullets",Lua_Get_Position_Total_Max_Bullets);
	lua_register(L, "Get_Position_Max_Bullets",Lua_Get_Position_Max_Bullets);
	lua_register(L, "Get_Position_Clip_Max_Bullets",Lua_Get_Position_Clip_Max_Bullets);
	lua_register(L, "Set_Current_Bullets",Lua_Set_Current_Bullets);
	lua_register(L, "Set_Current_Clip_Bullets",Lua_Set_Current_Clip_Bullets);
	lua_register(L, "Set_Position_Bullets",Lua_Set_Position_Bullets);
	lua_register(L, "Set_Position_Clip_Bullets",Lua_Set_Position_Clip_Bullets);
	lua_register(L, "Set_Bullets",Lua_Set_Bullets);
	lua_register(L, "Set_Clip_Bullets",Lua_Set_Clip_Bullets);
	lua_register(L, "Get_Powerup_Weapon",Lua_Get_Powerup_Weapon);
	lua_register(L, "Get_Powerup_Weapon_By_Obj",Lua_Get_Powerup_Weapon_By_Obj);
	lua_register(L, "Get_Current_Weapon_Style",Lua_Get_Current_Weapon_Style);
	lua_register(L, "Disarm_Beacon",Lua_Disarm_Beacon);
	lua_register(L, "Disarm_Beacons",Lua_Disarm_Beacons);
	lua_register(L, "Disarm_Nearest_Beacon",Lua_Disarm_Nearest_Beacon);
	lua_register(L, "Disarm_C4",Lua_Disarm_C4);
	lua_register(L, "Disarm_All_Proxy_C4",Lua_Disarm_All_Proxy_C4);
	lua_register(L, "Disarm_All_C4",Lua_Disarm_All_C4);
	lua_register(L, "Get_Current_Weapon",Lua_Get_Current_Weapon);
	lua_register(L, "Get_Weapon_Count",Lua_Get_Weapon_Count);
	lua_register(L, "Get_Weapon",Lua_Get_Weapon);
	lua_register(L, "Has_Weapon",Lua_Has_Weapon);
	lua_register(L, "Find_Beacon",Lua_Find_Beacon);
	lua_register(L, "Get_C4_Count",Lua_Get_C4_Count);
	lua_register(L, "Get_Beacon_Count",Lua_Get_Beacon_Count);
	lua_register(L, "Get_Mine_Limit",Lua_Get_Mine_Limit);
	lua_register(L, "Get_C4_Mode",Lua_Get_C4_Mode);
	lua_register(L, "Get_C4_Count_Proximity",Lua_Get_C4_Count_Proximity);
	lua_register(L, "Get_C4_Count_Remote",Lua_Get_C4_Count_Remote);
	lua_register(L, "Get_C4_Planter",Lua_Get_C4_Planter);
	lua_register(L, "Get_C4_Attached",Lua_Get_C4_Attached);
	lua_register(L, "Get_Beacon_Planter",Lua_Get_Beacon_Planter);
	lua_register(L, "Create_Object",Lua_Create_Object);
	lua_register(L, "Destroy_Object",Lua_Destroy_Object);
	lua_register(L, "Get_Preset_Name",Lua_Get_Preset_Name);
	lua_register(L, "Get_Position",Lua_Get_Position);
	lua_register(L, "Enable_Vehicle_Transitions", Lua_Enable_Vehicle_Transitions);
	lua_register(L, "Set_Model",Lua_Set_Model);
	lua_register(L, "Goto_Location",Lua_Goto_Location);
	lua_register(L, "Goto_Object",Lua_Goto_Object);
	lua_register(L, "Disable_Physical_Collisions", Lua_Disable_Physical_Collisions);
	lua_register(L, "Enable_Collisions", Lua_Enable_Collisions);
	lua_register(L, "Random_Building", Lua_Random_Building);
	lua_register(L, "Get_Current_Map", Lua_Get_Current_Map);
	lua_register(L, "Get_Next_Map", Lua_Get_Next_Map);
	lua_register(L, "Set_Position", Lua_Set_Position);
	lua_register(L, "Apply_Damage", Lua_Apply_Damage);
	lua_register(L, "Get_Facing", Lua_Get_Facing);
	lua_register(L, "Set_Facing", Lua_Set_Facing);
	lua_register(L, "Set_Clouds", Lua_Set_Clouds);
	lua_register(L, "Set_Ash", Lua_Set_Ash);
	lua_register(L, "Set_Rain", Lua_Set_Rain);
	lua_register(L, "Set_Snow", Lua_Set_Snow);
	lua_register(L, "Set_Wind", Lua_Set_Wind);
	lua_register(L, "Attach_Script", Lua_Attach_Script);
	lua_register(L, "Create_Object_At_Bone", Lua_Create_Object_At_Bone);
	lua_register(L, "Attach_To_Object_Bone", Lua_Attach_To_Object_Bone);
	lua_register(L, "Display_Health_Bar", Lua_Display_Health_Bar);
	lua_register(L, "Create_Script_Zone", Lua_Create_Script_Zone);
	lua_register(L, "Get_ID", Lua_Get_ID);
	lua_register(L, "tClock", Lua_tClock);
	lua_register(L, "Invoke", Lua_Invoke);
	lua_register(L, "RequestSerial", Lua_RequestSerial);
	lua_register(L, "GetTimeRemaining", Lua_GetTimeRemaining);
	lua_register(L, "Get_Health", Lua_Get_Health);
	lua_register(L, "Get_Max_Health", Lua_Get_Max_Health);
	lua_register(L, "Get_Shield_Strength", Lua_Get_Shield_Strength);
	lua_register(L, "Get_Max_Shield_Strength", Lua_Get_Max_Shield_Strength);
	lua_register(L, "LongToIP", Lua_LongToIP);
	lua_register(L, "IPToLong", Lua_IPToLong);
	lua_register(L, "Is_A_Star", Lua_Is_A_Star);
	lua_register(L, "Enable_Stealth", Lua_Enable_Stealth);
	lua_register(L, "Get_Rotation", Lua_Get_Rotation);
	lua_register(L, "Get_All_Players", Lua_Get_All_Players);
	lua_register(L, "Get_All_Vehicles", Lua_Get_All_Vehicles);
	lua_register(L, "Get_All_Buildings", Lua_Get_All_Buildings);
	lua_register(L, "Get_All_Objects", Lua_Get_All_Objects);
	lua_register(L, "Display_Nod_Player_Terminal_Player", Lua_Display_Nod_Player_Terminal_Player);
	lua_register(L, "Display_GDI_Player_Terminal_Player", Lua_Display_GDI_Player_Terminal_Player);
	lua_register(L, "Reload_All_Plugins", Lua_Reload_All_Plugins);
	lua_register(L, "Set_Shield_Strength", Lua_Set_Shield_Strength);
	lua_register(L, "Set_Health", Lua_Set_Health);
	lua_register(L, "cPlayer", Lua_cPlayer);
	lua_register(L, "The_Game", Lua_The_Game);
	lua_register(L, "Set_cPlayer", Lua_Set_cPlayer);
	lua_register(L, "Set_The_Game", Lua_Set_The_Game);
	lua_register(L, "MemoryWrite", Lua_Memory_Write);
	lua_register(L, "MemoryRead", Lua_Memory_Read);
	lua_register(L, "Set_Shield_Type", Lua_Set_Shield_Type);

  //Classes
	Lua_sqlite_wrapper::Register(L);
	LuaScriptManager::RegisterScriptFunctions(L);

}