2020-01-23 23:15:26 +01:00
|
|
|
#pragma semicolon 1
|
|
|
|
|
|
|
|
#define DEBUG
|
|
|
|
|
|
|
|
#define PLUGIN_AUTHOR "jenz"
|
2020-06-26 00:11:22 +02:00
|
|
|
#define PLUGIN_VERSION "1.3"
|
2020-04-22 00:17:28 +02:00
|
|
|
#define generic_length 256
|
2020-01-23 23:15:26 +01:00
|
|
|
|
|
|
|
#include <sourcemod>
|
|
|
|
#include <sdktools>
|
2020-06-26 00:11:22 +02:00
|
|
|
#include <socket>
|
2020-01-23 23:15:26 +01:00
|
|
|
|
2020-06-26 00:11:22 +02:00
|
|
|
//#pragma newdecls required
|
2020-01-23 23:15:26 +01:00
|
|
|
|
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
|
|
|
|
2020-07-15 02:14:00 +02:00
|
|
|
//admins & vips
|
|
|
|
int admins[MAXPLAYERS + 1];
|
|
|
|
int vips[MAXPLAYERS + 1];
|
|
|
|
|
2020-06-26 00:11:22 +02:00
|
|
|
//socket for bot input
|
|
|
|
Handle global_socket;
|
|
|
|
|
2020-06-09 23:34:49 +02:00
|
|
|
|
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 OnPluginStart()
|
2020-01-23 23:15:26 +01:00
|
|
|
{
|
2020-05-05 23:52:01 +02:00
|
|
|
//talking
|
|
|
|
RegConsoleCmd("sm_autism", cmd_talk, "talking to the bot through java application");
|
|
|
|
|
2020-02-28 22:00:22 +01:00
|
|
|
//hooks
|
|
|
|
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
|
2020-04-22 00:17:28 +02:00
|
|
|
|
2020-06-26 00:11:22 +02:00
|
|
|
//socket otherwise declare in public OnConfigsExecuted(){}
|
|
|
|
Handle socket = SocketCreate(SOCKET_UDP, OnSocketError);
|
|
|
|
SocketSetOption(socket, SocketReuseAddr, 1);
|
2020-07-03 22:50:21 +02:00
|
|
|
SocketBind(socket, "127.0.0.1", 48475);
|
2020-06-26 00:11:22 +02:00
|
|
|
connect(socket);
|
|
|
|
global_socket = socket;
|
2020-01-23 23:15:26 +01:00
|
|
|
}
|
|
|
|
|
2020-05-05 23:52:01 +02:00
|
|
|
public Action cmd_talk(int client, int args)
|
|
|
|
{
|
2020-06-26 00:11:22 +02:00
|
|
|
char msg[generic_length];
|
2020-05-05 23:52:01 +02:00
|
|
|
char info[generic_length];
|
|
|
|
GetCmdArgString(info, sizeof(info));
|
2020-05-06 01:24:15 +02:00
|
|
|
if (strlen(info) == 0)
|
|
|
|
{
|
2020-06-09 23:34:49 +02:00
|
|
|
PrintToChat(client, "Add a message to the command if autism bot is ingame and running on discord");
|
2020-05-06 01:24:15 +02:00
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
2020-06-26 00:11:22 +02:00
|
|
|
Format(msg, sizeof(msg), "clientmessage: %s", info);
|
|
|
|
send_socket_msg(msg, strlen(msg));
|
2020-05-05 23:52:01 +02:00
|
|
|
return Plugin_Handled;
|
|
|
|
}
|
|
|
|
|
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-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-07-17 01:44:18 +02:00
|
|
|
CreateTimer(0.1, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
2020-06-26 00:11:22 +02:00
|
|
|
CreateTimer(10.0, bot_check_connect, 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-06-26 00:11:22 +02:00
|
|
|
public void send_socket_msg(char[] query_msg, int len)
|
2020-06-09 23:34:49 +02:00
|
|
|
{
|
2020-06-26 00:11:22 +02:00
|
|
|
if (global_socket != INVALID_HANDLE && SocketIsConnected(global_socket))
|
|
|
|
SocketSendTo(global_socket, query_msg, len, "127.0.0.1", 48477); //udp
|
|
|
|
}
|
|
|
|
|
|
|
|
public Action bot_check_connect(Handle timer, any data)
|
|
|
|
{
|
|
|
|
if (!IsValidClient(present) && GetClientCount(false) < 63)
|
|
|
|
{
|
|
|
|
char msg[generic_length];
|
|
|
|
//PrintToChatAll("sending UDP message...");
|
|
|
|
Format(msg, sizeof(msg), "connect to ze");
|
|
|
|
send_socket_msg(msg, strlen(msg));
|
|
|
|
}
|
|
|
|
return Plugin_Continue;
|
|
|
|
}
|
|
|
|
|
2020-07-15 02:14:00 +02:00
|
|
|
public Action recursive_pressing(Handle timer, any data)
|
2020-06-26 00:11:22 +02:00
|
|
|
{
|
|
|
|
if (IsValidClient(present) && IsPlayerAlive(present))
|
|
|
|
{
|
|
|
|
float flVel[3];
|
2020-07-15 02:14:00 +02:00
|
|
|
char message[generic_length * 7];
|
2020-05-05 23:52:01 +02:00
|
|
|
float present_bot_coords[3];
|
|
|
|
GetClientAbsOrigin(present, present_bot_coords);
|
2020-05-21 00:19:49 +02:00
|
|
|
int targeteam = 0;
|
|
|
|
if (GetClientTeam(present) != 3)
|
|
|
|
{
|
2020-06-09 23:34:49 +02:00
|
|
|
//2 = autismo is zm and should follow closest moving zm
|
2020-05-21 00:19:49 +02:00
|
|
|
targeteam = 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 23:34:49 +02:00
|
|
|
//3 = autismo is human and should follow closest moving ct
|
2020-05-21 00:19:49 +02:00
|
|
|
targeteam = 3;
|
|
|
|
}
|
2020-07-15 02:14:00 +02:00
|
|
|
bool find_closest_match = true;
|
2020-07-17 01:44:18 +02:00
|
|
|
float distance_limit = 100.0;
|
2020-07-15 02:14:00 +02:00
|
|
|
if (IsValidClient(targethuman) && GetClientTeam(targethuman) == targeteam && IsPlayerAlive(targethuman))
|
|
|
|
{
|
|
|
|
float pos[3];
|
|
|
|
GetClientAbsOrigin(targethuman, 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]);
|
2020-07-17 01:44:18 +02:00
|
|
|
float dist_target = SquareRoot(dx*dx + dy*dy + dz*dz);
|
2020-07-15 02:14:00 +02:00
|
|
|
GetEntPropVector(targethuman, Prop_Data, "m_vecAbsVelocity", flVel);
|
2020-07-17 01:44:18 +02:00
|
|
|
if (admins[targethuman])
|
|
|
|
distance_limit = distance_limit * 5;
|
|
|
|
else if (vips[targethuman])
|
|
|
|
distance_limit = distance_limit * 2.5;
|
|
|
|
if (flVel[0] < 100.0 && flVel[1] < 100.0)
|
|
|
|
find_closest_match = false;
|
|
|
|
if (dist_target < distance_limit)
|
2020-07-15 02:14:00 +02:00
|
|
|
find_closest_match = false;
|
|
|
|
}
|
|
|
|
if (find_closest_match)
|
2020-05-05 23:52:01 +02:00
|
|
|
{
|
|
|
|
float lowest_distance = 1000000.0;
|
2020-07-15 02:14:00 +02:00
|
|
|
bool adminpresent = false;
|
|
|
|
bool vippresent = false;
|
2020-07-17 01:44:18 +02:00
|
|
|
float dist_target = 0.0;
|
2020-05-05 23:52:01 +02:00
|
|
|
for (int i = 1; i <= MaxClients; i++)
|
2020-05-21 00:19:49 +02:00
|
|
|
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
|
2020-02-14 23:27:57 +01:00
|
|
|
{
|
2020-05-05 23:52:01 +02:00
|
|
|
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]);
|
2020-07-15 02:14:00 +02:00
|
|
|
dist_target = SquareRoot(dx*dx + dy*dy + dz*dz);
|
|
|
|
|
2020-07-17 01:44:18 +02:00
|
|
|
if (admins[i] == 1 && dist_target < distance_limit * 5)
|
2020-07-15 02:14:00 +02:00
|
|
|
{
|
|
|
|
adminpresent = true;
|
|
|
|
vippresent = false;
|
|
|
|
}
|
2020-07-17 01:44:18 +02:00
|
|
|
else if (vips[i] == 1 && !adminpresent && dist_target < distance_limit * 2.5)
|
2020-07-15 02:14:00 +02:00
|
|
|
{
|
|
|
|
vippresent = true;
|
|
|
|
}
|
|
|
|
if (adminpresent)
|
|
|
|
{
|
|
|
|
if (admins[i] == 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (vippresent)
|
|
|
|
{
|
|
|
|
if (vips[i] == 0)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
GetEntPropVector(i, Prop_Data, "m_vecAbsVelocity", flVel);
|
2020-07-17 01:44:18 +02:00
|
|
|
if (flVel[0] < 100.0 && flVel[1] < 100.0)
|
2020-07-15 02:14:00 +02:00
|
|
|
continue;
|
|
|
|
if (dist_target < lowest_distance)
|
2020-05-05 23:52:01 +02:00
|
|
|
{
|
2020-07-15 02:14:00 +02:00
|
|
|
lowest_distance = dist_target;
|
2020-05-05 23:52:01 +02:00
|
|
|
targethuman = i;
|
|
|
|
}
|
2020-02-14 23:27:57 +01:00
|
|
|
}
|
2020-05-05 23:52:01 +02:00
|
|
|
}
|
2020-02-28 22:00:22 +01:00
|
|
|
if (IsValidClient(targethuman))
|
2020-01-23 23:15:26 +01:00
|
|
|
{
|
2020-07-15 02:14:00 +02:00
|
|
|
float dx = 0.0;
|
|
|
|
float dy = 0.0;
|
|
|
|
float dz = 0.0;
|
2020-07-17 01:44:18 +02:00
|
|
|
float dist_target = 0.0;
|
2020-07-15 02:14:00 +02:00
|
|
|
float target_human_original_coord[3];
|
|
|
|
GetClientAbsOrigin(targethuman, target_human_original_coord);
|
|
|
|
dx = present_bot_coords[0] - target_human_original_coord[0];
|
|
|
|
dy = present_bot_coords[1] - target_human_original_coord[1];
|
|
|
|
dz = FloatAbs(present_bot_coords[2] - target_human_original_coord[2]);
|
|
|
|
dist_target = SquareRoot(dx*dx + dy*dy + dz*dz);
|
|
|
|
int keys = GetClientButtons(targethuman);
|
|
|
|
char keyinput[generic_length * 2];
|
|
|
|
int counter = 0;
|
|
|
|
int countercap = 5;
|
2020-07-17 01:44:18 +02:00
|
|
|
//check ladder = 0, water = 1, in air(surfing) = 2
|
2020-07-15 02:14:00 +02:00
|
|
|
int bot_on_type = -1;
|
2020-07-17 01:44:18 +02:00
|
|
|
if (GetEntityMoveType(present) == MOVETYPE_LADDER)
|
2020-07-15 02:14:00 +02:00
|
|
|
bot_on_type = 0;
|
|
|
|
int ilevel = GetEntProp(present, Prop_Data, "m_nWaterLevel");
|
|
|
|
if (ilevel >= 2)
|
|
|
|
bot_on_type = 1;
|
|
|
|
while (!strlen(keyinput) && counter < countercap)
|
2020-02-28 22:00:22 +01:00
|
|
|
{
|
2020-07-15 02:14:00 +02:00
|
|
|
if (keys & IN_FORWARD)
|
|
|
|
Format(keyinput, sizeof(keyinput), "-back; wait 5; +forward; wait 5; ");
|
|
|
|
else if (keys & IN_BACK)
|
|
|
|
Format(keyinput, sizeof(keyinput), "-forward; wait 5; +back; wait 5; ");
|
|
|
|
if (keys & IN_MOVELEFT)
|
|
|
|
Format(keyinput, sizeof(keyinput), "%s -moveright; wait 5; +moveleft; wait 5; ", keyinput);
|
|
|
|
else if (keys & IN_MOVERIGHT)
|
|
|
|
Format(keyinput, sizeof(keyinput), "%s -moveleft; wait 5; +moveright; wait 5; ", keyinput);
|
|
|
|
if (keys & IN_JUMP)
|
|
|
|
Format(keyinput, sizeof(keyinput), "%s +jump; wait 5; ", keyinput);
|
|
|
|
if (keys & IN_DUCK)
|
|
|
|
Format(keyinput, sizeof(keyinput), "%s +duck; wait 5; ", keyinput);
|
|
|
|
counter++;
|
2020-02-28 22:00:22 +01:00
|
|
|
}
|
2020-07-15 02:14:00 +02:00
|
|
|
float clientangles[3];
|
|
|
|
GetClientAbsAngles(targethuman, clientangles);
|
2020-05-05 23:52:01 +02:00
|
|
|
//PrintToChatAll("targethuman: %N", targethuman);
|
2020-07-17 01:44:18 +02:00
|
|
|
Format(message, sizeof(message), "keyinput: %s clientangles: %f %f %f xyz: %f %f %f dist_target: %f targethuman: %N bot_on_type: %i", keyinput, clientangles[0], clientangles[1], clientangles[2], dx, dy, dz, dist_target, targethuman, bot_on_type);
|
2020-07-15 02:14:00 +02:00
|
|
|
send_socket_msg(message, strlen(message));
|
2020-01-23 23:15:26 +01:00
|
|
|
}
|
|
|
|
}
|
2020-06-26 00:11:22 +02:00
|
|
|
return Plugin_Continue;
|
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
|
|
|
{
|
2020-02-28 22:00:22 +01:00
|
|
|
present = client;
|
2020-06-26 00:11:22 +02:00
|
|
|
bot_send_connected_msg();
|
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
|
|
|
{
|
2020-02-28 22:00:22 +01:00
|
|
|
present = client;
|
2020-06-26 00:11:22 +02:00
|
|
|
bot_send_connected_msg();
|
2020-04-22 00:17:28 +02:00
|
|
|
}
|
2020-07-15 02:14:00 +02:00
|
|
|
if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
|
|
|
|
admins[client] = 1;
|
|
|
|
else if (CheckCommandAccess(client, "sm_reserved", ADMFLAG_RESERVATION))
|
|
|
|
vips[client] = 1;
|
2020-04-22 00:17:28 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 00:11:22 +02:00
|
|
|
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
|
2020-04-22 00:17:28 +02:00
|
|
|
{
|
2020-06-26 00:11:22 +02:00
|
|
|
LogError("[MR] Socket error: %d (errno %d)", errorType, errorNum);
|
|
|
|
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
|
2020-04-22 00:17:28 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 00:11:22 +02:00
|
|
|
stock void connect(Handle socket)
|
2020-04-22 00:17:28 +02:00
|
|
|
{
|
2020-06-26 00:11:22 +02:00
|
|
|
if (!SocketIsConnected(socket))
|
2020-07-03 22:50:21 +02:00
|
|
|
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "127.0.0.1", 48475);
|
2020-04-22 00:17:28 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 00:11:22 +02:00
|
|
|
public void OnClientDisconnect(int client)
|
2020-04-22 00:17:28 +02:00
|
|
|
{
|
2020-06-26 00:11:22 +02:00
|
|
|
if (present == client)
|
|
|
|
{
|
|
|
|
present = 0;
|
|
|
|
}
|
2020-07-15 02:14:00 +02:00
|
|
|
admins[client] = 0;
|
|
|
|
vips[client] = 0;
|
2020-04-22 00:17:28 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 00:11:22 +02:00
|
|
|
public void bot_send_connected_msg()
|
2020-04-22 00:17:28 +02:00
|
|
|
{
|
2020-06-26 00:11:22 +02:00
|
|
|
char msg[generic_length];
|
|
|
|
Format(msg, sizeof(msg), "autismo connected");
|
|
|
|
send_socket_msg(msg, strlen(msg));
|
2020-04-22 00:17:28 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 00:11:22 +02:00
|
|
|
//Socket callback
|
|
|
|
public OnSocketConnected(Handle socket, any arg)
|
2020-04-22 00:17:28 +02:00
|
|
|
{
|
2020-06-26 00:11:22 +02:00
|
|
|
|
2020-04-22 00:17:28 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 00:11:22 +02:00
|
|
|
//manage message
|
|
|
|
public OnSocketReceive(Handle socket, char[] receiveData, const dataSize, any hFile)
|
2020-04-22 00:17:28 +02:00
|
|
|
{
|
2020-06-26 00:11:22 +02:00
|
|
|
//PrintToChatAll("receiveData: %s", receiveData);
|
|
|
|
}
|
|
|
|
|
|
|
|
public OnSocketDisconnected(Handle socket, any arg)
|
|
|
|
{
|
|
|
|
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
|
2020-06-09 23:34:49 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 00:11:22 +02:00
|
|
|
public Action TimerConnect(Handle timer, any arg)
|
2020-06-09 23:34:49 +02:00
|
|
|
{
|
2020-06-26 00:11:22 +02:00
|
|
|
connect(arg);
|
|
|
|
return Plugin_Handled;
|
2020-01-23 23:15:26 +01:00
|
|
|
}
|