2020-01-23 23:15:26 +01:00
|
|
|
#pragma semicolon 1
|
|
|
|
|
|
|
|
#define DEBUG
|
|
|
|
|
|
|
|
#define PLUGIN_AUTHOR "jenz"
|
|
|
|
#define PLUGIN_VERSION "1.00"
|
2020-04-22 00:17:28 +02:00
|
|
|
#define generic_length 256
|
2020-01-23 23:15:26 +01:00
|
|
|
|
|
|
|
#include <sourcemod>
|
|
|
|
#include <sdktools>
|
|
|
|
|
|
|
|
#pragma newdecls required
|
|
|
|
|
2020-02-28 22:00:22 +01:00
|
|
|
int present = 0;
|
2020-02-09 00:26:05 +01:00
|
|
|
int targethuman = 0;
|
2020-01-23 23:15:26 +01:00
|
|
|
|
|
|
|
public Plugin myinfo =
|
|
|
|
{
|
|
|
|
name = "coordinates for the bot",
|
|
|
|
author = PLUGIN_AUTHOR,
|
|
|
|
description = "hello ",
|
|
|
|
version = PLUGIN_VERSION,
|
|
|
|
url = ""
|
|
|
|
};
|
|
|
|
|
2020-02-28 22:00:22 +01:00
|
|
|
public void OnClientDisconnect(int client)
|
2020-01-23 23:15:26 +01:00
|
|
|
{
|
2020-02-28 22:00:22 +01:00
|
|
|
if (present == client)
|
2020-04-22 00:17:28 +02:00
|
|
|
{
|
2020-02-28 22:00:22 +01:00
|
|
|
present = 0;
|
2020-04-22 00:17:28 +02:00
|
|
|
mysql_enable_disable_connected(0);
|
|
|
|
}
|
|
|
|
|
2020-01-23 23:15:26 +01:00
|
|
|
}
|
|
|
|
|
2020-02-28 22:00:22 +01:00
|
|
|
public void OnPluginStart()
|
2020-01-23 23:15:26 +01:00
|
|
|
{
|
2020-02-28 22:00:22 +01:00
|
|
|
//hooks
|
|
|
|
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
|
2020-04-22 00:17:28 +02:00
|
|
|
HookEvent("player_team", event_playerteam, EventHookMode_PostNoCopy);
|
|
|
|
|
|
|
|
//mysql
|
|
|
|
sql_create_table();
|
2020-01-23 23:15:26 +01:00
|
|
|
}
|
|
|
|
|
2020-04-22 00:17:28 +02:00
|
|
|
public Action event_playerteam(Event event, const char[] name, bool dontBroadcast)
|
|
|
|
{
|
|
|
|
int client = GetClientOfUserId(event.GetInt("userid"));
|
|
|
|
if (client == present)
|
|
|
|
{
|
|
|
|
//PrintToChatAll("called event_playerteam");
|
|
|
|
int team = event.GetInt("team");
|
|
|
|
//PrintToChatAll("team: %i", team);
|
|
|
|
if (team == 2 || team == 3)
|
|
|
|
mysql_bot_not_spec();
|
|
|
|
}
|
|
|
|
}
|
2020-02-28 22:00:22 +01:00
|
|
|
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
|
2020-01-23 23:15:26 +01:00
|
|
|
{
|
2020-02-28 22:00:22 +01:00
|
|
|
targethuman = 0;
|
2020-04-22 00:17:28 +02:00
|
|
|
int server_port = GetConVarInt(FindConVar("hostport"));
|
|
|
|
if (server_port == 27015)
|
|
|
|
{
|
|
|
|
mysql_update_playercount();
|
|
|
|
}
|
|
|
|
if (present)
|
|
|
|
mysql_clean_movement_input();
|
2020-01-23 23:15:26 +01:00
|
|
|
}
|
|
|
|
|
2020-02-28 22:00:22 +01:00
|
|
|
public void OnMapStart()
|
2020-02-09 00:26:05 +01:00
|
|
|
{
|
2020-04-22 00:17:28 +02:00
|
|
|
sql_create_table();
|
|
|
|
CreateTimer(1.0, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
2020-02-09 00:26:05 +01:00
|
|
|
}
|
|
|
|
|
2020-02-28 22:00:22 +01:00
|
|
|
public bool TraceEntityFilterPlayer(int entity, int contentsMask)
|
2020-02-09 00:26:05 +01:00
|
|
|
{
|
2020-02-28 22:00:22 +01:00
|
|
|
return (entity > GetMaxClients() || !entity);
|
2020-02-09 00:26:05 +01:00
|
|
|
}
|
|
|
|
|
2020-02-28 22:00:22 +01:00
|
|
|
public Action recursive_pressing(Handle timer, any data)
|
2020-02-14 23:27:57 +01:00
|
|
|
{
|
2020-02-28 22:00:22 +01:00
|
|
|
//PrintToChatAll("present: %N", present);
|
2020-04-22 00:17:28 +02:00
|
|
|
if (present && IsPlayerAlive(present))
|
2020-02-14 23:27:57 +01:00
|
|
|
{
|
2020-02-28 22:00:22 +01:00
|
|
|
float client_coord[3];
|
|
|
|
float xyz[3];
|
2020-02-14 23:27:57 +01:00
|
|
|
float lowest_distance = 1000000.0;
|
2020-02-28 22:00:22 +01:00
|
|
|
float pos_client[3];
|
|
|
|
GetClientAbsOrigin(present, pos_client);
|
2020-02-14 23:27:57 +01:00
|
|
|
for (int i = 1; i <= MaxClients; i++)
|
2020-02-28 22:00:22 +01:00
|
|
|
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 3 && i != present)
|
2020-02-14 23:27:57 +01:00
|
|
|
{
|
|
|
|
float pos_i[3];
|
2020-02-28 22:00:22 +01:00
|
|
|
GetClientAbsOrigin(i, pos_i);
|
2020-02-14 23:27:57 +01:00
|
|
|
float dx = pos_client[0] - pos_i[0];
|
|
|
|
float dy = pos_client[1] - pos_i[1];
|
|
|
|
float dz = FloatAbs(pos_client[2] - pos_i[2]);
|
|
|
|
float dist = SquareRoot(dx*dx + dy*dy + dz*dz);
|
2020-02-28 22:00:22 +01:00
|
|
|
//PrintToChatAll("dist: %f", dist);
|
2020-02-14 23:27:57 +01:00
|
|
|
if (dist < lowest_distance)
|
|
|
|
{
|
|
|
|
lowest_distance = dist;
|
|
|
|
targethuman = i;
|
2020-02-28 22:00:22 +01:00
|
|
|
client_coord = pos_i;
|
|
|
|
xyz[0] = dx;
|
|
|
|
xyz[1] = dy;
|
|
|
|
xyz[2] = dz;
|
2020-02-14 23:27:57 +01:00
|
|
|
}
|
|
|
|
}
|
2020-02-28 22:00:22 +01:00
|
|
|
if (IsValidClient(targethuman))
|
2020-01-23 23:15:26 +01:00
|
|
|
{
|
2020-02-28 22:00:22 +01:00
|
|
|
//PrintToChatAll("targethuman: %N", targethuman);
|
|
|
|
float clientangles[3];
|
|
|
|
GetClientAbsAngles(targethuman, clientangles);
|
|
|
|
int keys = GetClientButtons(targethuman);
|
2020-04-22 00:17:28 +02:00
|
|
|
char keyinput[generic_length];
|
2020-02-28 22:00:22 +01:00
|
|
|
if (keys & IN_FORWARD)
|
|
|
|
{
|
2020-04-22 00:17:28 +02:00
|
|
|
StrCat(keyinput, sizeof(keyinput), "+forward; ");
|
2020-02-28 22:00:22 +01:00
|
|
|
}
|
|
|
|
if (keys & IN_BACK)
|
|
|
|
{
|
2020-04-22 00:17:28 +02:00
|
|
|
StrCat(keyinput, sizeof(keyinput), "+back; ");
|
2020-02-28 22:00:22 +01:00
|
|
|
}
|
|
|
|
if (keys & IN_MOVELEFT)
|
|
|
|
{
|
2020-04-22 00:17:28 +02:00
|
|
|
StrCat(keyinput, sizeof(keyinput), "+moveleft; ");
|
2020-02-28 22:00:22 +01:00
|
|
|
}
|
|
|
|
if (keys & IN_MOVERIGHT)
|
|
|
|
{
|
2020-04-22 00:17:28 +02:00
|
|
|
StrCat(keyinput, sizeof(keyinput), "+moveright; ");
|
2020-02-28 22:00:22 +01:00
|
|
|
}
|
|
|
|
if (keys & IN_JUMP)
|
|
|
|
{
|
2020-04-22 00:17:28 +02:00
|
|
|
StrCat(keyinput, sizeof(keyinput), "+jump; ");
|
2020-02-28 22:00:22 +01:00
|
|
|
}
|
2020-04-22 00:17:28 +02:00
|
|
|
if (keys & IN_DUCK)
|
|
|
|
{
|
|
|
|
StrCat(keyinput, sizeof(keyinput), "+duck; ");
|
|
|
|
}
|
|
|
|
mysql_send_input(keyinput, clientangles, xyz, client_coord, lowest_distance);
|
2020-01-23 23:15:26 +01:00
|
|
|
}
|
|
|
|
}
|
2020-02-28 22:00:22 +01:00
|
|
|
return Plugin_Handled;
|
2020-01-23 23:15:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stock bool IsValidClient(int client)
|
|
|
|
{
|
|
|
|
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnClientPostAdminCheck(int client)
|
|
|
|
{
|
|
|
|
//STEAM_0:1:34783317
|
|
|
|
//STEAM_0:1:60189040
|
|
|
|
//[U:1:120378081]
|
2020-02-14 23:27:57 +01:00
|
|
|
//[U:1:69566635]
|
2020-01-23 23:15:26 +01:00
|
|
|
char auth[50];
|
|
|
|
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
|
|
|
|
if (StrEqual("[U:1:120378081]", auth, false))
|
2020-04-22 00:17:28 +02:00
|
|
|
{
|
|
|
|
mysql_enable_disable_connected(1);
|
2020-02-28 22:00:22 +01:00
|
|
|
present = client;
|
2020-04-22 00:17:28 +02:00
|
|
|
}
|
2020-02-28 22:00:22 +01:00
|
|
|
else if (StrEqual("STEAM_0:1:60189040", auth, false))
|
2020-04-22 00:17:28 +02:00
|
|
|
{
|
|
|
|
mysql_enable_disable_connected(1);
|
2020-02-28 22:00:22 +01:00
|
|
|
present = client;
|
2020-04-22 00:17:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void sql_create_table()
|
|
|
|
{
|
|
|
|
char error_connect[generic_length];
|
|
|
|
Database database_connection;
|
|
|
|
if (SQL_CheckConfig("css_autism_bot_info"))
|
|
|
|
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
|
|
|
if (database_connection == null)
|
|
|
|
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
|
|
|
|
//256 not enough
|
|
|
|
char query_start[generic_length * 2];
|
|
|
|
Format(query_start, sizeof(query_start), "CREATE TABLE IF NOT EXISTS unloze_css_autism_bot.`bot status` (`connected` BOOL DEFAULT false, `spectate` BOOL DEFAULT true, `ID` INT NOT NULL DEFAULT 1, `playercount` INT DEFAULT 0, PRIMARY KEY (`ID`))");
|
|
|
|
mysql_exec_prepared_statement(database_connection, query_start);
|
|
|
|
Format(query_start, sizeof(query_start), "CREATE TABLE IF NOT EXISTS unloze_css_autism_bot.`bot movement input` (`keyinput` text NOT NULL, `clientangles_0` FLOAT DEFAULT 0.0, `clientangles_1` FLOAT DEFAULT 0.0, `clientangles_2` FLOAT DEFAULT 0.0, `xyz_0` FLOAT DEFAULT 0.0, `xyz_1` FLOAT DEFAULT 0.0, `xyz_2` FLOAT DEFAULT 0.0, `client_coord_0` FLOAT DEFAULT 0.0, `client_coord_1` FLOAT DEFAULT 0.0, `client_coord_2` FLOAT DEFAULT 0.0, `lowest_distance` FLOAT DEFAULT 0.0, `entry_time` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP)");
|
|
|
|
mysql_exec_prepared_statement(database_connection, query_start);
|
|
|
|
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot status` (connected, spectate, ID) VALUES (0, 1, 1) ON DUPLICATE KEY UPDATE connected = VALUES(connected), spectate = VALUES(spectate)");
|
|
|
|
mysql_exec_prepared_statement(database_connection, query_start);
|
|
|
|
delete database_connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mysql_clean_movement_input()
|
|
|
|
{
|
|
|
|
char error_connect[generic_length];
|
|
|
|
Database database_connection;
|
|
|
|
if (SQL_CheckConfig("css_autism_bot_info"))
|
|
|
|
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
|
|
|
if (database_connection == null)
|
|
|
|
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
|
|
|
|
char query_start[generic_length];
|
|
|
|
Format(query_start, sizeof(query_start), "delete from unloze_css_autism_bot.`bot movement input`");
|
|
|
|
mysql_exec_prepared_statement(database_connection, query_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mysql_update_playercount()
|
|
|
|
{
|
|
|
|
char error_connect[generic_length];
|
|
|
|
Database database_connection;
|
|
|
|
if (SQL_CheckConfig("css_autism_bot_info"))
|
|
|
|
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
|
|
|
if (database_connection == null)
|
|
|
|
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
|
|
|
|
char query_start[generic_length];
|
|
|
|
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot status` (playercount, ID) VALUES (%i, 1) ON DUPLICATE KEY UPDATE playercount = %i", MaxClients, MaxClients);
|
|
|
|
mysql_exec_prepared_statement(database_connection, query_start);
|
|
|
|
delete database_connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mysql_bot_not_spec()
|
|
|
|
{
|
|
|
|
char error_connect[generic_length];
|
|
|
|
Database database_connection;
|
|
|
|
if (SQL_CheckConfig("css_autism_bot_info"))
|
|
|
|
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
|
|
|
if (database_connection == null)
|
|
|
|
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
|
|
|
|
char query_start[generic_length];
|
|
|
|
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot status` (connected, spectate, ID) VALUES (1, 0, 1) ON DUPLICATE KEY UPDATE connected = VALUES(connected), spectate = VALUES(spectate)");
|
|
|
|
mysql_exec_prepared_statement(database_connection, query_start);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mysql_enable_disable_connected(int state)
|
|
|
|
{
|
|
|
|
char error_connect[generic_length];
|
|
|
|
Database database_connection;
|
|
|
|
if (SQL_CheckConfig("css_autism_bot_info"))
|
|
|
|
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
|
|
|
if (database_connection == null)
|
|
|
|
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
|
|
|
|
char query_start[generic_length];
|
|
|
|
if (!state)
|
|
|
|
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot status` (connected, spectate, ID) VALUES (0, 1, 1) ON DUPLICATE KEY UPDATE connected = VALUES(connected), spectate = VALUES(spectate)");
|
|
|
|
else
|
|
|
|
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot status` (connected, spectate, ID) VALUES (1, 1, 1) ON DUPLICATE KEY UPDATE connected = VALUES(connected), spectate = VALUES(spectate)");
|
|
|
|
//PrintToChatAll("query_start: %s", query_start);
|
|
|
|
mysql_exec_prepared_statement(database_connection, query_start);
|
|
|
|
delete database_connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mysql_send_input(char []keyinput, float clientangles[3], float xyz[3], float client_coord[3], float lowest_distance)
|
|
|
|
{
|
|
|
|
//TODO maybe add autism bot coords too as information
|
|
|
|
char error_connect[generic_length];
|
|
|
|
Database database_connection;
|
|
|
|
if (SQL_CheckConfig("css_autism_bot_info"))
|
|
|
|
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
|
|
|
if (database_connection == null)
|
|
|
|
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
|
|
|
|
char query_start[generic_length];
|
|
|
|
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot movement input` VALUES ('%s', %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, NOW())", keyinput, clientangles[0], clientangles[1], clientangles[2], xyz[0], xyz[1], xyz[2], client_coord[0], client_coord[1], client_coord[2], lowest_distance);
|
|
|
|
mysql_exec_prepared_statement(database_connection, query_start);
|
|
|
|
//PrintToChatAll("query_start: %s", query_start);
|
|
|
|
delete database_connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void mysql_exec_prepared_statement(Database database_connection, char []query_statement)
|
|
|
|
{
|
|
|
|
char error[generic_length];
|
|
|
|
DBStatement create_statement = SQL_PrepareQuery(database_connection, query_statement, error, sizeof(error));
|
|
|
|
if (create_statement == INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
CloseHandle(create_statement);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
SQL_Execute(create_statement);
|
|
|
|
CloseHandle(create_statement);
|
2020-01-23 23:15:26 +01:00
|
|
|
}
|