adding ingame chat support from sourcemod through java to python
This commit is contained in:
parent
1bb64ce55b
commit
dac167ba41
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package DataLayer;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.apache.commons.dbcp2.BasicDataSource;
|
||||
import DataLayer.settings;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author install1
|
||||
*/
|
||||
public class DBCPDataSourceAutismo {
|
||||
private static BasicDataSource ds = new BasicDataSource();
|
||||
static {
|
||||
try {
|
||||
ds.setDriver(new com.mysql.cj.jdbc.Driver());
|
||||
ds.setUrl(settings.autismo_url);
|
||||
ds.setUsername(settings.autismo_username);
|
||||
ds.setPassword(settings.autismo_password);
|
||||
ds.setMaxTotal(-1);
|
||||
ds.setMinIdle(5);
|
||||
ds.setMaxIdle(-1);
|
||||
ds.setMaxOpenPreparedStatements(100);
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DBCPDataSourceAutismo.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static Connection getConnection() throws SQLException {
|
||||
return ds.getConnection();
|
||||
}
|
||||
|
||||
private DBCPDataSourceAutismo() {
|
||||
}
|
||||
}
|
@ -105,6 +105,34 @@ public class DataMapper {
|
||||
return hlStatsMessages;
|
||||
}
|
||||
|
||||
public static String check_autismo_mysql() {
|
||||
String target = "";
|
||||
try (Connection l_cCon = DBCPDataSourceAutismo.getConnection()) {
|
||||
String l_sSQL = "SELECT chatmessage FROM unloze_css_autism_bot.chatting c WHERE c.responsemessage = '' LIMIT 1";
|
||||
try (PreparedStatement l_pStatement = l_cCon.prepareStatement(l_sSQL)) {
|
||||
try (ResultSet l_rsSearch = l_pStatement.executeQuery()) {
|
||||
while (l_rsSearch.next()) {
|
||||
target = l_rsSearch.getString(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
public static void update_autismo_mysql(String responseMsg, String update_string) {
|
||||
try (Connection l_cCon = DBCPDataSourceAutismo.getConnection()) {
|
||||
String l_sSQL = "UPDATE unloze_css_autism_bot.`chatting` SET `responsemessage` = '" + responseMsg + "' WHERE `chatmessage` = '" + update_string + "'";
|
||||
try (PreparedStatement l_pStatement = l_cCon.prepareStatement(l_sSQL)) {
|
||||
l_pStatement.execute();
|
||||
}
|
||||
} catch (SQLException ex) {
|
||||
Logger.getLogger(DataMapper.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void CloseConnections(PreparedStatement ps, ResultSet rs, Connection con) {
|
||||
if (rs != null) {
|
||||
try {
|
||||
|
@ -220,7 +220,7 @@ public class Datahandler {
|
||||
hlStatsMessages.put(str, hlStatsMessages.size());
|
||||
}
|
||||
}
|
||||
int capacity = 600;
|
||||
int capacity = 50;
|
||||
hlStatsMessages.keySet().forEach(str -> {
|
||||
if (!str.startsWith("!") && MessageResponseHandler.getStr().values().size() < capacity) {
|
||||
String orElse = strCacheLocal.values().parallelStream().filter(e -> e.equals(str)).findAny().orElse(null);
|
||||
@ -790,6 +790,18 @@ public class Datahandler {
|
||||
return stringCache.values().size() - (stringCache.values().size() / 10);
|
||||
}
|
||||
|
||||
public void update_autismo_mysql() {
|
||||
String update_string = DataMapper.check_autismo_mysql();
|
||||
if (!update_string.isEmpty()) {
|
||||
try {
|
||||
String getResponseMsg = getResponseMsg(update_string);
|
||||
DataMapper.update_autismo_mysql(getResponseMsg, update_string);
|
||||
} catch (CustomError ex) {
|
||||
Logger.getLogger(Datahandler.class.getName()).log(Level.SEVERE, null, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class AnnotationCollector<T> implements Consumer<T> {
|
||||
|
||||
private static int i = 0;
|
||||
|
@ -19,6 +19,8 @@ import FunctionLayer.DoStuff;
|
||||
import FunctionLayer.PipelineJMWESingleton;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.javacord.api.DiscordApi;
|
||||
@ -29,6 +31,12 @@ import org.javacord.api.DiscordApiBuilder;
|
||||
* @author install1
|
||||
*/
|
||||
public class DiscordHandler {
|
||||
public static class update_autismo_ingame_msgs extends TimerTask {
|
||||
@Override
|
||||
public void run() {
|
||||
Datahandler.instance.update_autismo_mysql();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.setProperty("java.util.concurrent.ForkJoinPool.common.parallelism", "15");
|
||||
@ -48,6 +56,8 @@ public class DiscordHandler {
|
||||
Datahandler.instance.updateStringCache();
|
||||
String token = "NTI5NzAxNTk5NjAyMjc4NDAx.Dw0vDg.7-aMjVWdQMYPl8qVNyvTCPS5F_A";
|
||||
DiscordApi api = new DiscordApiBuilder().setToken(token).login().join();
|
||||
Timer timer = new Timer();
|
||||
timer.scheduleAtFixedRate(new update_autismo_ingame_msgs(), 700, 700);
|
||||
api.addMessageCreateListener(event -> {
|
||||
if (!FunctionLayer.DoStuff.isOccupied()) {
|
||||
FunctionLayer.DoStuff.doStuff(event, api);
|
||||
|
@ -63,20 +63,6 @@ def mysql_check_spectator():
|
||||
cnx.close()
|
||||
|
||||
def mysql_get_player_info(movement_list):
|
||||
#1 = forward, 2 = back, 3 = left, 4 = right
|
||||
#use previous movement instead for evaluation
|
||||
strInput = "-attack; -jump; -duck; +attack; cl_minmodels 1; "
|
||||
print('movement_list[0]: ', movement_list[0], '#1 = forward, 2 = back, 3 = left, 4 = right')
|
||||
print('movement_list[1]: ', movement_list[1], '#1 = forward, 2 = back, 3 = left, 4 = right')
|
||||
if movement_list[0] == 1:
|
||||
strInput += " -back; wait 5;"
|
||||
else:
|
||||
strInput += " -forward; wait 5;"
|
||||
if movement_list[1] == 4:
|
||||
strInput += " -moveleft; wait 5;"
|
||||
else:
|
||||
strInput += " -moveright; wait 5;"
|
||||
#print('strInput movement_list:', strInput)
|
||||
cnx = get_connection()
|
||||
cur = cnx.cursor()
|
||||
sql_statement = f"""SELECT * from unloze_css_autism_bot.`bot movement input` ORDER BY entry_time LIMIT 1"""
|
||||
@ -86,47 +72,113 @@ def mysql_get_player_info(movement_list):
|
||||
cur.execute(sql_row_count)
|
||||
result_count = cur.fetchone()[0]
|
||||
if result:
|
||||
movement_list = []
|
||||
result = result[0]
|
||||
movement_input = result[0]
|
||||
client_angles = [result[1], result[2], result[3]]
|
||||
xyz_difference = [result[4], result[5], result[6]]
|
||||
client_coordinates = [result[7], result[8], result[9]]
|
||||
lowest_distance = result[10]
|
||||
client_coordinates = result[7], result[8], result[9]
|
||||
hunt_or_mimic = result[10]
|
||||
stuckX = result[11]
|
||||
stuckY = result[12]
|
||||
strInput = "-attack; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; "
|
||||
print('movement_list[0]: ', movement_list[0], '#false = forward, true = back')
|
||||
print('movement_list[1]: ', movement_list[1], '#false = left, true = right')
|
||||
print('result_count: ', result_count)
|
||||
if "+jump;" in movement_input:
|
||||
strInput += " +jump;"
|
||||
if "+duck;" in movement_input:
|
||||
strInput += " +duck;"
|
||||
#print('xyz_difference: ', xyz_difference)
|
||||
if xyz_difference[0] > 0:
|
||||
movement_list.append(1)
|
||||
strInput += " +forward; wait 5;"
|
||||
axis_distance = 105
|
||||
#print('stuckX: ', stuckX, ' stuckY: ', stuckY)
|
||||
if stuckX and xyz_difference[0] < -axis_distance or xyz_difference[0] > axis_distance:
|
||||
movement_list[0] = not movement_list[0]
|
||||
strInput += " +jump; wait 3; +duck; wait 5;"
|
||||
if stuckY and xyz_difference[1] < -axis_distance or xyz_difference[1] > axis_distance:
|
||||
movement_list[1] = not movement_list[1]
|
||||
strInput += " +jump; wait 3; +duck; wait 5;"
|
||||
if hunt_or_mimic:
|
||||
print('hunt_or_mimic enabled')
|
||||
bool_x_axis_permit = True
|
||||
bool_y_axis_permit = True
|
||||
sql_statement = f"""SELECT entry_time FROM unloze_css_autism_bot.`bot movement input` where client_coord_0 = '{client_coordinates[0]}' and client_coord_1 = '{client_coordinates[1]}'
|
||||
and client_coord_2 = '{client_coordinates[2]}' LIMIT 1"""
|
||||
cur.execute(sql_statement)
|
||||
entry_time = cur.fetchall()[0][0]
|
||||
#once hunt_or_mimic is reached it should remain true until round restart or ct death, once close enough distance bot has to copy its input for rest of round
|
||||
if not hunt_or_mimic:
|
||||
if xyz_difference[0] > axis_distance:
|
||||
movement_list[0] = True
|
||||
elif xyz_difference[0] < -axis_distance:
|
||||
movement_list[0] = False
|
||||
else:
|
||||
bool_x_axis_permit = False
|
||||
strInput += " -back; wait 5; -forward; wait 5;"
|
||||
if xyz_difference[1] < -axis_distance:
|
||||
movement_list[1] = True
|
||||
elif xyz_difference[1] > axis_distance:
|
||||
movement_list[1] = False
|
||||
else:
|
||||
bool_y_axis_permit = False
|
||||
strInput += " -moveright; wait 5; -moveleft; wait 5;"
|
||||
print('xyz_difference[0]: ', xyz_difference[0])
|
||||
print('xyz_difference[1]: ', xyz_difference[1])
|
||||
strInput += f""" setang 0 180 0; wait 5; """
|
||||
else:
|
||||
movement_list.append(2)
|
||||
strInput += " +back; wait 5;"
|
||||
if xyz_difference[1] < 0:
|
||||
movement_list.append(4)
|
||||
strInput += " +moveright; wait 5;"
|
||||
else:
|
||||
movement_list.append(3)
|
||||
strInput += " +moveleft; wait 5;"
|
||||
strInput += f""" setang 0 180 0; wait 5; """
|
||||
#print('client_angles: ', client_angles)
|
||||
print('movement_input: ', movement_input)
|
||||
strInput += f""" setang {client_angles[0]} {client_angles[1]} {client_angles[2]}; wait 5; {movement_input};"""
|
||||
#if xyz_difference[0] > -axis_distance and xyz_difference[0] < axis_distance and xyz_difference[1] > -axis_distance and xyz_difference[1] < axis_distance:
|
||||
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` where entry_time <= '{entry_time}'"""
|
||||
cur.execute(sql_statement)
|
||||
print('Deleted ', cur.rowcount, ' rows before/during entry_time:', entry_time)
|
||||
cnx.commit()
|
||||
if xyz_difference[0] > -25 and xyz_difference[0] < 25:
|
||||
strInput += "-back; wait 5; -forward; wait 5;"
|
||||
if xyz_difference[1] > -25 and xyz_difference[1] < 25:
|
||||
strInput += "-moveright; wait 5; -moveleft; wait 5;"
|
||||
if not hunt_or_mimic:
|
||||
if bool_x_axis_permit:
|
||||
if movement_list[0]:
|
||||
strInput += " -back; wait 5; +forward; wait 5;"
|
||||
else:
|
||||
strInput += " -forward; wait 5; +back; wait 5;"
|
||||
if bool_y_axis_permit:
|
||||
if movement_list[1]:
|
||||
strInput += " -moveleft; wait 5; +moveright; wait 5;"
|
||||
else:
|
||||
strInput += " -moveright; wait 5; +moveleft; wait 5;"
|
||||
|
||||
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` where entry_time <= '{entry_time}'"""
|
||||
cur.execute(sql_statement)
|
||||
#print('sql_statement: ', sql_statement)
|
||||
#print('Deleted ', cur.rowcount, ' rows before/during entry_time:', entry_time)
|
||||
cnx.commit()
|
||||
#print('strInput final:', strInput)
|
||||
writeCfgInput(strInput)
|
||||
time.sleep(0.20)
|
||||
time.sleep(0.10)
|
||||
writeCfgInput("wait 5;")
|
||||
limit = 0
|
||||
if result_count > 7:
|
||||
limit = result_count - 2
|
||||
else:
|
||||
limit = 1
|
||||
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` ORDER BY entry_time LIMIT {limit}"""
|
||||
cur.close()
|
||||
cnx.close()
|
||||
run_delay = 0.05 #0.05
|
||||
connectionTimer = Timer(run_delay, mysql_get_player_info, args=[movement_list])
|
||||
connectionTimer.daemon = True
|
||||
connectionTimer.start()
|
||||
|
||||
def mysql_check_messages():
|
||||
cnx = get_connection()
|
||||
cur = cnx.cursor()
|
||||
sql_statement = """SELECT responsemessage FROM unloze_css_autism_bot.chatting WHERE responsemessage != '' LIMIT 1"""
|
||||
cur.execute(sql_statement)
|
||||
result = cur.fetchall()
|
||||
if result:
|
||||
result = result[0][0]
|
||||
str = f"""say {result}"""
|
||||
print('str: ', str)
|
||||
writeCfgInput(str)
|
||||
time.sleep(0.2)
|
||||
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`chatting` WHERE `responsemessage` = '{result}'"""
|
||||
print('sql_statement: ', sql_statement)
|
||||
cur.execute(sql_statement)
|
||||
cnx.commit()
|
||||
cur.close()
|
||||
cnx.close()
|
||||
connectionTimer = Timer(0.10, mysql_get_player_info, args=[movement_list])
|
||||
connectionTimer = Timer(2, mysql_check_messages)
|
||||
connectionTimer.daemon = True
|
||||
connectionTimer.start()
|
||||
|
||||
@ -142,10 +194,10 @@ def mysql_check_if_connected():
|
||||
#playercount might not be updated ingame and auto leave?
|
||||
print('connected: ', connected)
|
||||
if connected == 0:
|
||||
str1 = "connect 151.80.230.149:27015;"
|
||||
str1 = "connect 151.80.230.149:27019/test132;"
|
||||
writeCfgInput(str1)
|
||||
time.sleep(0.5)
|
||||
writeCfgInput("wait 500;")
|
||||
time.sleep(0.2)
|
||||
writeCfgInput("wait 5;")
|
||||
time.sleep(15.50)
|
||||
print('not yet connected')
|
||||
mysql_check_if_connected()
|
||||
@ -164,6 +216,15 @@ def mysql_check_if_connected():
|
||||
cur.close()
|
||||
cnx.close()
|
||||
|
||||
def mysql_reset_input():
|
||||
cnx = get_connection()
|
||||
cur = cnx.cursor()
|
||||
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input`"""
|
||||
cur.execute(sql_statement)
|
||||
cnx.commit()
|
||||
cur.close()
|
||||
cnx.close()
|
||||
|
||||
def deadlock():
|
||||
try:
|
||||
while True: 42 == 42
|
||||
@ -176,12 +237,14 @@ if __name__ == '__main__':
|
||||
mysql_check_if_connected()
|
||||
checkbotteam()
|
||||
print('reached mysql _get_player_info')
|
||||
mysql_get_player_info([" +forward;", " +moveright;"])
|
||||
mysql_reset_input()
|
||||
mysql_get_player_info([False, True])
|
||||
mysql_check_messages()
|
||||
print('reached deadlock')
|
||||
deadlock()
|
||||
|
||||
#/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/autoexec.cfg:
|
||||
#alias loop "exec looptest.cfg; wait 300; loop;"; wait 5; loop;
|
||||
#alias loop "exec looptest.cfg; wait 5; loop;"; wait 5; loop;
|
||||
|
||||
#-condebug
|
||||
#cd /home/nonroot/.steam/
|
||||
|
@ -13,6 +13,10 @@
|
||||
|
||||
int present = 0;
|
||||
int targethuman = 0;
|
||||
int stuckcounterX = 0;
|
||||
int stuckcounterY = 0;
|
||||
bool hunt_or_mimic = false;
|
||||
Database database_connection_input;
|
||||
|
||||
public Plugin myinfo =
|
||||
{
|
||||
@ -30,19 +34,52 @@ public void OnClientDisconnect(int client)
|
||||
present = 0;
|
||||
mysql_enable_disable_connected(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
//talking
|
||||
RegConsoleCmd("sm_autism", cmd_talk, "talking to the bot through java application");
|
||||
|
||||
//hooks
|
||||
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
|
||||
HookEvent("player_team", event_playerteam, EventHookMode_PostNoCopy);
|
||||
|
||||
//global DB
|
||||
char error_connect[generic_length];
|
||||
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!");
|
||||
|
||||
//mysql
|
||||
sql_create_table();
|
||||
}
|
||||
|
||||
public Action cmd_talk(int client, int args)
|
||||
{
|
||||
char info[generic_length];
|
||||
GetCmdArgString(info, sizeof(info));
|
||||
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];
|
||||
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);
|
||||
delete database_connection;
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public void OnPluginEnd()
|
||||
{
|
||||
delete database_connection_input;
|
||||
}
|
||||
|
||||
public Action event_playerteam(Event event, const char[] name, bool dontBroadcast)
|
||||
{
|
||||
int client = GetClientOfUserId(event.GetInt("userid"));
|
||||
@ -55,6 +92,7 @@ public Action event_playerteam(Event event, const char[] name, bool dontBroadcas
|
||||
mysql_bot_not_spec();
|
||||
}
|
||||
}
|
||||
|
||||
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
|
||||
{
|
||||
targethuman = 0;
|
||||
@ -63,6 +101,7 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast
|
||||
{
|
||||
mysql_update_playercount();
|
||||
}
|
||||
hunt_or_mimic = false;
|
||||
if (present)
|
||||
mysql_clean_movement_input();
|
||||
}
|
||||
@ -70,7 +109,7 @@ public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast
|
||||
public void OnMapStart()
|
||||
{
|
||||
sql_create_table();
|
||||
CreateTimer(1.0, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(1.3, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
}
|
||||
|
||||
public bool TraceEntityFilterPlayer(int entity, int contentsMask)
|
||||
@ -80,56 +119,77 @@ public bool TraceEntityFilterPlayer(int entity, int contentsMask)
|
||||
|
||||
public Action recursive_pressing(Handle timer, any data)
|
||||
{
|
||||
//PrintToChatAll("present: %N", present);
|
||||
if (present && IsPlayerAlive(present))
|
||||
{
|
||||
float client_coord[3];
|
||||
float xyz[3];
|
||||
float lowest_distance = 1000000.0;
|
||||
float pos_client[3];
|
||||
GetClientAbsOrigin(present, pos_client);
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 3 && i != present)
|
||||
{
|
||||
float pos_i[3];
|
||||
GetClientAbsOrigin(i, pos_i);
|
||||
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);
|
||||
//PrintToChatAll("dist: %f", dist);
|
||||
if (dist < lowest_distance)
|
||||
float present_bot_coords[3];
|
||||
GetClientAbsOrigin(present, present_bot_coords);
|
||||
if (!IsValidClient(targethuman) || GetClientTeam(targethuman) != 3 || !IsPlayerAlive(targethuman))
|
||||
{
|
||||
hunt_or_mimic = false;
|
||||
float lowest_distance = 1000000.0;
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 3 && i != present)
|
||||
{
|
||||
lowest_distance = dist;
|
||||
targethuman = i;
|
||||
client_coord = pos_i;
|
||||
xyz[0] = dx;
|
||||
xyz[1] = dy;
|
||||
xyz[2] = dz;
|
||||
float pos[3];
|
||||
GetClientAbsOrigin(i, pos);
|
||||
float dx = present_bot_coords[0] - pos[0];
|
||||
float dy = present_bot_coords[1] - pos[1];
|
||||
float dz = FloatAbs(present_bot_coords[2] - pos[2]);
|
||||
float dist = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
if (dist < lowest_distance)
|
||||
{
|
||||
lowest_distance = dist;
|
||||
targethuman = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//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))
|
||||
{
|
||||
//PrintToChatAll("targethuman: %N", targethuman);
|
||||
float clientangles[3];
|
||||
GetClientAbsAngles(targethuman, clientangles);
|
||||
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;
|
||||
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;
|
||||
int keys = GetClientButtons(targethuman);
|
||||
char keyinput[generic_length];
|
||||
if (keys & IN_FORWARD)
|
||||
//if true mimicing human input
|
||||
if (hunt_or_mimic)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "+forward; ");
|
||||
}
|
||||
if (keys & IN_BACK)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "+back; ");
|
||||
}
|
||||
if (keys & IN_MOVELEFT)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "+moveleft; ");
|
||||
}
|
||||
if (keys & IN_MOVERIGHT)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "+moveright; ");
|
||||
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_JUMP)
|
||||
{
|
||||
@ -139,7 +199,10 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
{
|
||||
StrCat(keyinput, sizeof(keyinput), "+duck; ");
|
||||
}
|
||||
mysql_send_input(keyinput, clientangles, xyz, client_coord, lowest_distance);
|
||||
//PrintToChatAll("targethuman: %N", targethuman);
|
||||
float clientangles[3];
|
||||
GetClientAbsAngles(targethuman, clientangles);
|
||||
mysql_send_input(keyinput, clientangles, xyz, target_human_coords, hunt_or_mimic);
|
||||
}
|
||||
}
|
||||
return Plugin_Handled;
|
||||
@ -183,13 +246,15 @@ public void sql_create_table()
|
||||
if (database_connection == null)
|
||||
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
|
||||
//256 not enough
|
||||
char query_start[generic_length * 2];
|
||||
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` 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)");
|
||||
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)");
|
||||
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);
|
||||
Format(query_start, sizeof(query_start), "CREATE TABLE IF NOT EXISTS unloze_css_autism_bot.`chatting` (`chatmessage` text NOT NULL, `responsemessage` text NOT NULL)");
|
||||
mysql_exec_prepared_statement(database_connection, query_start);
|
||||
delete database_connection;
|
||||
}
|
||||
|
||||
@ -251,20 +316,39 @@ 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], float lowest_distance)
|
||||
public void mysql_send_input(char []keyinput, float clientangles[3], float xyz[3], float client_coord[3], bool hunt_or_mimicb)
|
||||
{
|
||||
//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);
|
||||
float flVel[3];
|
||||
GetEntPropVector(present, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
int stuckX = 0;
|
||||
int stuckY = 0;
|
||||
int stuckcap = 6;
|
||||
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;
|
||||
}
|
||||
}
|
||||
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);
|
||||
|
||||
//PrintToChatAll("flVel: %f %f %f", flVel[0], flVel[1], flVel[2]);
|
||||
//PrintToChatAll("query_start: %s", query_start);
|
||||
delete database_connection;
|
||||
}
|
||||
|
||||
public void mysql_exec_prepared_statement(Database database_connection, char []query_statement)
|
||||
|
Loading…
Reference in New Issue
Block a user