update to sourcemod part
This commit is contained in:
parent
21b0456f84
commit
4c26d46016
@ -1,5 +1,6 @@
|
||||
# requirements
|
||||
steam account, x2go or nomachine or VNC etc etc
|
||||
steam account,
|
||||
x2go or nomachine or VNC
|
||||
steam account with css purchased
|
||||
# launch commands
|
||||
./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi -condebug +exec looptest.cfg
|
||||
|
@ -3,8 +3,9 @@
|
||||
#define DEBUG
|
||||
|
||||
#define PLUGIN_AUTHOR "jenz"
|
||||
#define PLUGIN_VERSION "1.00"
|
||||
#define PLUGIN_VERSION "1.2"
|
||||
#define generic_length 256
|
||||
#define rows_entry_cap 10
|
||||
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
@ -15,9 +16,18 @@ int present = 0;
|
||||
int targethuman = 0;
|
||||
int stuckcounterX = 0;
|
||||
int stuckcounterY = 0;
|
||||
bool hunt_or_mimic = false;
|
||||
Database database_connection_input;
|
||||
|
||||
//bot input
|
||||
int row_counter = 0;
|
||||
int stuckX = 0;
|
||||
int stuckY = 0;
|
||||
char keyinput[rows_entry_cap][generic_length];
|
||||
float clientangles[rows_entry_cap][3];
|
||||
float xyz[rows_entry_cap][3];
|
||||
float target_human_original_coord[3];
|
||||
bool hunt_or_mimic;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
name = "coordinates for the bot",
|
||||
@ -50,8 +60,7 @@ public void OnPluginStart()
|
||||
if (SQL_CheckConfig("css_autism_bot_info"))
|
||||
database_connection_input = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
||||
if (database_connection_input == null)
|
||||
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
|
||||
|
||||
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB! %s", error_connect);
|
||||
//mysql
|
||||
sql_create_table();
|
||||
}
|
||||
@ -62,7 +71,7 @@ public Action cmd_talk(int client, int args)
|
||||
GetCmdArgString(info, sizeof(info));
|
||||
if (strlen(info) == 0)
|
||||
{
|
||||
PrintToChat(client, "Add a message to the command if autism bot is ingame");
|
||||
PrintToChat(client, "Add a message to the command if autism bot is ingame and running on discord");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
char error_connect[generic_length];
|
||||
@ -71,8 +80,7 @@ public Action cmd_talk(int client, int args)
|
||||
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];
|
||||
char query_start[generic_length * 2];
|
||||
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`chatting` (`chatmessage`, `responsemessage`) VALUES ('%s', '')", info);
|
||||
//PrintToChatAll("query_start: %s", query_start);
|
||||
mysql_exec_prepared_statement(database_connection, query_start);
|
||||
@ -114,7 +122,8 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast
|
||||
public void OnMapStart()
|
||||
{
|
||||
sql_create_table();
|
||||
CreateTimer(1.3, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(0.2, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(2.0, mysql_send_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
}
|
||||
|
||||
public bool TraceEntityFilterPlayer(int entity, int contentsMask)
|
||||
@ -122,6 +131,12 @@ public bool TraceEntityFilterPlayer(int entity, int contentsMask)
|
||||
return (entity > GetMaxClients() || !entity);
|
||||
}
|
||||
|
||||
public Action mysql_send_pressing(Handle timer, any data)
|
||||
{
|
||||
if (present && IsPlayerAlive(present))
|
||||
mysql_send_input();
|
||||
}
|
||||
|
||||
public Action recursive_pressing(Handle timer, any data)
|
||||
{
|
||||
if (present && IsPlayerAlive(present))
|
||||
@ -131,11 +146,12 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
int targeteam = 0;
|
||||
if (GetClientTeam(present) != 3)
|
||||
{
|
||||
//2 = autismo is zm and follows closest zm
|
||||
//2 = autismo is zm and should follow closest moving zm
|
||||
targeteam = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
//3 = autismo is human and should follow closest moving ct
|
||||
targeteam = 3;
|
||||
}
|
||||
if (!IsValidClient(targethuman) || GetClientTeam(targethuman) != targeteam || !IsPlayerAlive(targethuman))
|
||||
@ -146,7 +162,7 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
|
||||
{
|
||||
float flVel[3];
|
||||
float minvelocity = 10.0;
|
||||
float minvelocity = 40.0;
|
||||
GetEntPropVector(i, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
if (flVel[0] < minvelocity && flVel[1] < minvelocity)
|
||||
continue;
|
||||
@ -162,75 +178,67 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
targethuman = i;
|
||||
}
|
||||
}
|
||||
if (IsValidClient(targethuman))
|
||||
GetClientAbsOrigin(targethuman, target_human_original_coord);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//get bot in distance, mimic all input until CT dead/round over
|
||||
|
||||
|
||||
//copy all input to track each origin correctly on path
|
||||
//prioritize with global lowest distance what coord point is closest to bot to start mimic entry
|
||||
//from which it can mimic input of player forward on each round, boolean
|
||||
|
||||
if (IsValidClient(targethuman))
|
||||
{
|
||||
float target_human_coords[3];
|
||||
int distance_limit = 105;
|
||||
GetClientAbsOrigin(targethuman, target_human_coords);
|
||||
float xyz[3];
|
||||
float dx = present_bot_coords[0] - target_human_coords[0];
|
||||
float dy = present_bot_coords[1] - target_human_coords[1];
|
||||
float dz = FloatAbs(present_bot_coords[2] - target_human_coords[2]);
|
||||
float dist = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
//PrintToChatAll("dist: %f", dist);
|
||||
if (dist < distance_limit)
|
||||
hunt_or_mimic = true;
|
||||
else
|
||||
hunt_or_mimic = false;
|
||||
dx = present_bot_coords[0] - target_human_coords[0];
|
||||
dy = present_bot_coords[1] - target_human_coords[1];
|
||||
dz = FloatAbs(present_bot_coords[2] - target_human_coords[2]);
|
||||
xyz[0] = dx;
|
||||
xyz[1] = dy;
|
||||
xyz[2] = dz;
|
||||
if (!hunt_or_mimic)
|
||||
{
|
||||
int distance_limit = 50;
|
||||
float dx = present_bot_coords[0] - target_human_original_coord[0];
|
||||
float dy = present_bot_coords[1] - target_human_original_coord[1];
|
||||
float dz = FloatAbs(present_bot_coords[2] - target_human_original_coord[2]);
|
||||
float dist = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
//PrintToChatAll("dist: %f", dist);
|
||||
if (dist < distance_limit)
|
||||
hunt_or_mimic = true;
|
||||
xyz[row_counter][0] = dx;
|
||||
xyz[row_counter][1] = dy;
|
||||
xyz[row_counter][2] = dz;
|
||||
|
||||
float flVel[3];
|
||||
GetEntPropVector(present, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
int stuckcap = 3;
|
||||
float mincapvelocity = 10.0;
|
||||
if (flVel[0] < mincapvelocity)
|
||||
{
|
||||
stuckcounterX++;
|
||||
if (stuckcounterX > stuckcap)
|
||||
{
|
||||
stuckcounterX = 0;
|
||||
stuckX = 1;
|
||||
}
|
||||
}
|
||||
if (flVel[1] < mincapvelocity)
|
||||
{
|
||||
stuckcounterY++;
|
||||
if (stuckcounterY > stuckcap)
|
||||
{
|
||||
stuckcounterY = 0;
|
||||
stuckY = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
int keys = GetClientButtons(targethuman);
|
||||
char keyinput[generic_length];
|
||||
//if true mimicing human input
|
||||
if (hunt_or_mimic)
|
||||
{
|
||||
if (keys & IN_FORWARD)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "-back; wait 5; +forward; wait 5;");
|
||||
}
|
||||
else if (keys & IN_BACK)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "-forward; wait 5; +back; wait 5;");
|
||||
}
|
||||
if (keys & IN_MOVELEFT)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "-moveright; wait 5; +moveleft; wait 5;");
|
||||
}
|
||||
else if (keys & IN_MOVERIGHT)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "-moveleft; wait 5; +moveright; wait 5;");
|
||||
}
|
||||
}
|
||||
if (keys & IN_FORWARD)
|
||||
StrCat(keyinput[row_counter], sizeof(keyinput[]), "-back; wait 5; +forward; wait 5; ");
|
||||
else if (keys & IN_BACK)
|
||||
StrCat(keyinput[row_counter], sizeof(keyinput[]), "-forward; wait 5; +back; wait 5; ");
|
||||
if (keys & IN_MOVELEFT)
|
||||
StrCat(keyinput[row_counter], sizeof(keyinput[]), "-moveright; wait 5; +moveleft; wait 5; ");
|
||||
else if (keys & IN_MOVERIGHT)
|
||||
StrCat(keyinput[row_counter], sizeof(keyinput[]), "-moveleft; wait 5; +moveright; wait 5; ");
|
||||
if (keys & IN_JUMP)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "+jump; ");
|
||||
}
|
||||
StrCat(keyinput[row_counter], sizeof(keyinput[]), "+jump; wait 5; ");
|
||||
if (keys & IN_DUCK)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "+duck; ");
|
||||
}
|
||||
StrCat(keyinput[row_counter], sizeof(keyinput[]), "+duck; wait 5; ");
|
||||
GetClientAbsAngles(targethuman, clientangles[row_counter]);
|
||||
//PrintToChatAll("targethuman: %N", targethuman);
|
||||
float clientangles[3];
|
||||
GetClientAbsAngles(targethuman, clientangles);
|
||||
mysql_send_input(keyinput, clientangles, xyz, target_human_coords, hunt_or_mimic);
|
||||
}
|
||||
}
|
||||
if (row_counter < rows_entry_cap - 1)
|
||||
row_counter++;
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
@ -275,7 +283,7 @@ public void sql_create_table()
|
||||
char query_start[generic_length * 3];
|
||||
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` DECIMAL(13, 8) DEFAULT 0.000, `clientangles_1` DECIMAL(13, 8) DEFAULT 0.000, `clientangles_2` DECIMAL(13, 8) DEFAULT 0.000, `xyz_0` DECIMAL(13, 8) DEFAULT 0.000, `xyz_1` DECIMAL(13, 8) DEFAULT 0.000, `xyz_2` DECIMAL(13, 8) DEFAULT 0.000, `client_coord_0` DECIMAL(13, 8) DEFAULT 0.000, `client_coord_1` DECIMAL(13, 8) DEFAULT 0.000, `client_coord_2` DECIMAL(13, 8) DEFAULT 0.000, `hunt_or_mimic` BOOLEAN DEFAULT false, `stuckX` BOOLEAN DEFAULT false, `stuckY` BOOLEAN DEFAULT false, `entry_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP)");
|
||||
Format(query_start, sizeof(query_start), "CREATE TABLE IF NOT EXISTS unloze_css_autism_bot.`bot movement input` (`keyinput` text NOT NULL, `clientangles_0` DECIMAL(13, 8) DEFAULT 0.000, `clientangles_1` DECIMAL(13, 8) DEFAULT 0.000, `clientangles_2` DECIMAL(13, 8) DEFAULT 0.000, `xyz_0` DECIMAL(13, 8) DEFAULT 0.000, `xyz_1` DECIMAL(13, 8) DEFAULT 0.000, `xyz_2` DECIMAL(13, 8) DEFAULT 0.000, `hunt_or_mimic` BOOLEAN DEFAULT false, `stuckX` BOOLEAN DEFAULT false, `stuckY` BOOLEAN DEFAULT false, `entry_time` DATETIME 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);
|
||||
@ -342,39 +350,48 @@ public void mysql_enable_disable_connected(int state)
|
||||
delete database_connection;
|
||||
}
|
||||
|
||||
public void mysql_send_input(char []keyinput, float clientangles[3], float xyz[3], float client_coord[3], bool hunt_or_mimicb)
|
||||
public void mysql_send_input()
|
||||
{
|
||||
//TODO maybe add autism bot coords too as information
|
||||
char query_start[generic_length];
|
||||
float flVel[3];
|
||||
GetEntPropVector(present, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
int stuckX = 0;
|
||||
int stuckY = 0;
|
||||
int stuckcap = 3;
|
||||
float mincapvelocity = 10.0;
|
||||
if (flVel[0] < mincapvelocity)
|
||||
char query_start[generic_length * 7];
|
||||
int iterator = 0;
|
||||
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot movement input` VALUES ");
|
||||
while (iterator < row_counter)
|
||||
{
|
||||
stuckcounterX++;
|
||||
if (stuckcounterX > stuckcap)
|
||||
char row[generic_length];
|
||||
Format(row, sizeof(row), " ('%s', %f, %f, %f, %f, %f, %f, %i, %i, %i, NOW()),", keyinput[iterator], clientangles[iterator][0], clientangles[iterator][1], clientangles[iterator][2], xyz[iterator][0], xyz[iterator][1], xyz[iterator][2], hunt_or_mimic, stuckX, stuckY);
|
||||
StrCat(query_start, sizeof(query_start), row);
|
||||
Format(keyinput[iterator], sizeof(keyinput), " ");
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
stuckcounterX = 0;
|
||||
stuckX = 1;
|
||||
clientangles[iterator][i] = 0.0;
|
||||
xyz[iterator][i] = 0.0;
|
||||
}
|
||||
iterator++;
|
||||
}
|
||||
if (flVel[1] < mincapvelocity)
|
||||
{
|
||||
stuckcounterY++;
|
||||
if (stuckcounterY > stuckcap)
|
||||
{
|
||||
stuckcounterY = 0;
|
||||
stuckY = 1;
|
||||
}
|
||||
}
|
||||
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, %i, %i, %i, NOW())", keyinput, clientangles[0], clientangles[1], clientangles[2], xyz[0], xyz[1], xyz[2], client_coord[0], client_coord[1], client_coord[2], hunt_or_mimicb, stuckX, stuckY);
|
||||
mysql_exec_prepared_statement(database_connection_input, query_start);
|
||||
row_counter = 0;
|
||||
if (stuckX)
|
||||
stuckX = !stuckX;
|
||||
if (stuckY)
|
||||
stuckY = !stuckY;
|
||||
int querylen = strlen(query_start);
|
||||
query_start[querylen - 1] = '\0';
|
||||
|
||||
//PrintToChatAll("flVel: %f %f %f", flVel[0], flVel[1], flVel[2]);
|
||||
//PrintToChatAll("query_start: %s", query_start);
|
||||
//debugging
|
||||
/*
|
||||
PrintToChatAll("query_start final length: %i", querylen);
|
||||
char g_sConfigzones[PLATFORM_MAX_PATH];
|
||||
Handle inputfile = INVALID_HANDLE;
|
||||
BuildPath(Path_SM, g_sConfigzones, sizeof(g_sConfigzones), "configs/autism_insert_debug.txt");
|
||||
inputfile = OpenFile(g_sConfigzones, "w");
|
||||
if (inputfile != INVALID_HANDLE)
|
||||
{
|
||||
WriteFileLine(inputfile, "%s", query_start);
|
||||
}
|
||||
delete inputfile;
|
||||
*/
|
||||
|
||||
//mysql_exec_prepared_statement(database_connection_input, query_start);
|
||||
SQL_TQuery(database_connection_input, DummyCallbackSimple, query_start);
|
||||
}
|
||||
|
||||
public void mysql_exec_prepared_statement(Database database_connection, char []query_statement)
|
||||
@ -388,4 +405,10 @@ public void mysql_exec_prepared_statement(Database database_connection, char []q
|
||||
}
|
||||
SQL_Execute(create_statement);
|
||||
CloseHandle(create_statement);
|
||||
}
|
||||
|
||||
public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1)
|
||||
{
|
||||
if (hOwner == null || hChild == null)
|
||||
LogError("Query error. (%s)", err);
|
||||
}
|
Loading…
Reference in New Issue
Block a user