initial comit of surfing feature, probably might need some more updates for fixing things in practise
This commit is contained in:
		
							parent
							
								
									7a4ea9ad95
								
							
						
					
					
						commit
						92906a3f26
					
				
							
								
								
									
										293
									
								
								AutismBotIngame/scripting/bot_surfing.sp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										293
									
								
								AutismBotIngame/scripting/bot_surfing.sp
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,293 @@
 | 
			
		||||
#include <sourcemod>
 | 
			
		||||
#include <sdktools>
 | 
			
		||||
#include <sdkhooks>
 | 
			
		||||
#include <botmimic>
 | 
			
		||||
 | 
			
		||||
//for recording surfing properly with things such as trigger_pushes should sm_botmimic_snapshotinterval be set to 50
 | 
			
		||||
public Plugin myinfo = 
 | 
			
		||||
{
 | 
			
		||||
        name = "test surfing plugin",
 | 
			
		||||
        author = "jenzur",
 | 
			
		||||
        description = "hello ",
 | 
			
		||||
        version = "1.0",
 | 
			
		||||
        url = "www.unloze.com"
 | 
			
		||||
};
 | 
			
		||||
float bot_finished_surf_coords[MAXPLAYERS][3];
 | 
			
		||||
bool is_forward_called[MAXPLAYERS];
 | 
			
		||||
char map_coorindates[65][256];
 | 
			
		||||
char map_recordname[65][256];
 | 
			
		||||
Database g_dDatabase;
 | 
			
		||||
 | 
			
		||||
public void OnPluginStart()
 | 
			
		||||
{
 | 
			
		||||
	for (int i = 1; i <= MaxClients; i++)
 | 
			
		||||
                if (IsValidClient(i))
 | 
			
		||||
                {
 | 
			
		||||
			reset_client(i);
 | 
			
		||||
		}
 | 
			
		||||
	OnMapStart();
 | 
			
		||||
	HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
 | 
			
		||||
{
 | 
			
		||||
        for (int i = 1; i <= MaxClients; i++)
 | 
			
		||||
                if (IsValidClient(i) && !IsFakeClient(i))
 | 
			
		||||
                {
 | 
			
		||||
			reset_client(i);
 | 
			
		||||
                }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
stock bool IsValidClient(int client)
 | 
			
		||||
{
 | 
			
		||||
        if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
 | 
			
		||||
                return true;
 | 
			
		||||
        return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void OnClientPostAdminCheck(int client)
 | 
			
		||||
{
 | 
			
		||||
	is_forward_called[client] = false;
 | 
			
		||||
	reset_client(client);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void OnClientDisconnect(int client)
 | 
			
		||||
{
 | 
			
		||||
	is_forward_called[client] = false;
 | 
			
		||||
	reset_client(client);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void reset_client(int client)
 | 
			
		||||
{
 | 
			
		||||
	bot_finished_surf_coords[client][0] = 0.0;
 | 
			
		||||
        bot_finished_surf_coords[client][1] = 0.0;
 | 
			
		||||
        bot_finished_surf_coords[client][2] = 0.0;
 | 
			
		||||
	is_forward_called[client] = false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public int BotMimic_OnPlayerStopsMimicing(int client, char[] name, char[] category, char[] path)
 | 
			
		||||
{
 | 
			
		||||
	//its only an admin if debug is true
 | 
			
		||||
	if (CheckCommandAccess(client, "sm_kick", ADMFLAG_KICK))
 | 
			
		||||
	{
 | 
			
		||||
		reset_client(client);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
//unknown delay before forward is called.
 | 
			
		||||
//BotMimic_IsPlayerMimicing() is true in update_mimic_coords before the BotMimic_OnPlayerMimicLoops forward is called
 | 
			
		||||
public int BotMimic_OnPlayerMimicLoops(int client)
 | 
			
		||||
{
 | 
			
		||||
	//PrintToChatAll("BotMimic_OnPlayerMimicLoops bot_finished_surf_coords[client][0]: %f", bot_finished_surf_coords[client][0]);
 | 
			
		||||
	if (bot_finished_surf_coords[client][0] != 0.0)
 | 
			
		||||
	{
 | 
			
		||||
		BotMimic_StopPlayerMimic(client);
 | 
			
		||||
		//on ze2 they were teleported to end of world or maybe 0.0 0.0 0.0
 | 
			
		||||
		TeleportEntity(client, bot_finished_surf_coords[client], NULL_VECTOR, NULL_VECTOR);
 | 
			
		||||
		reset_client(client);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		is_forward_called[client] = true;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public Action update_mimic_coords(Handle timer, any data)
 | 
			
		||||
{
 | 
			
		||||
	for (int i = 1; i <= MaxClients; i++)
 | 
			
		||||
                if (IsValidClient(i) && is_bot_player(i))
 | 
			
		||||
		{
 | 
			
		||||
			if (BotMimic_IsPlayerMimicing(i) && is_forward_called[i])
 | 
			
		||||
			{
 | 
			
		||||
				GetEntPropVector(i, Prop_Send, "m_vecOrigin", bot_finished_surf_coords[i]);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	Handle records_list = BotMimic_GetLoadedRecordList();
 | 
			
		||||
	for (int i = 0; i < sizeof(map_coorindates); i++)
 | 
			
		||||
	{
 | 
			
		||||
		char char_coord[3][256];
 | 
			
		||||
		if (strlen(map_coorindates[i]) > 0)
 | 
			
		||||
		{
 | 
			
		||||
			ExplodeString(map_coorindates[i], " ", char_coord, sizeof(char_coord[]), sizeof(char_coord[]));
 | 
			
		||||
			float coords[3];
 | 
			
		||||
			coords[0] = StringToFloat(char_coord[0]);
 | 
			
		||||
			coords[1] = StringToFloat(char_coord[1]);
 | 
			
		||||
			coords[2] = StringToFloat(char_coord[2]);
 | 
			
		||||
			for (int j = 1; j <= MaxClients; j++)
 | 
			
		||||
			if (IsValidClient(j) && !IsFakeClient(j) && bot_finished_surf_coords[j][0] == 0.0 && is_bot_player(j))
 | 
			
		||||
			{
 | 
			
		||||
				float distance = get_power_distance(j, coords);
 | 
			
		||||
				//PrintToChatAll("distance %f client %N", distance, j);
 | 
			
		||||
				if (distance < 225.0)
 | 
			
		||||
				{
 | 
			
		||||
					char path[256];
 | 
			
		||||
					for (int f = 0; f < GetArraySize(records_list); f++)
 | 
			
		||||
					{
 | 
			
		||||
						if (f != i) continue;
 | 
			
		||||
						GetArrayString(records_list, f, path, sizeof(path));
 | 
			
		||||
						for (int h = 0; h < sizeof(map_recordname); h++)
 | 
			
		||||
						{
 | 
			
		||||
							//i != h assures coordinates match the right iterated name
 | 
			
		||||
							if (strlen(map_recordname[h]) == 0 || i != h)
 | 
			
		||||
							{
 | 
			
		||||
								continue;
 | 
			
		||||
							}
 | 
			
		||||
							if (StrEqual(path, map_recordname[h], false))
 | 
			
		||||
							{
 | 
			
		||||
								BotMimic_PlayRecordFromFile(j, path);
 | 
			
		||||
							}
 | 
			
		||||
						}
 | 
			
		||||
					}
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public float get_power_distance(int target_player, float [3]pos)
 | 
			
		||||
{
 | 
			
		||||
        float vec[3];
 | 
			
		||||
        GetClientAbsOrigin(target_player, vec);
 | 
			
		||||
        return GetVectorDistance(vec, pos);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public int BotMimic_OnRecordSaved(int client, char[] name, char[] category, char[] subdir, char[] file)
 | 
			
		||||
{
 | 
			
		||||
	//file =  The actual path to the saved .rec file.
 | 
			
		||||
	char sQuery[256];
 | 
			
		||||
	Format(sQuery, sizeof(sQuery), "UPDATE `maps_coordinates` SET `recordname` = '%s' WHERE `recordname` = 'unknown'", file);
 | 
			
		||||
	g_dDatabase.Query(SQL_insertQuery_record_saved, sQuery, _, DBPrio_High);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public Action BotMimic_OnStartRecording(int client, char[] name, char[] category, char[] subdir, char[] path)
 | 
			
		||||
{
 | 
			
		||||
	float bot_start_coords[3];
 | 
			
		||||
        GetEntPropVector(client, Prop_Send, "m_vecOrigin", bot_start_coords);
 | 
			
		||||
        char map_name[256];
 | 
			
		||||
        GetCurrentMap(map_name, sizeof(map_name));
 | 
			
		||||
        char sQuery[256];
 | 
			
		||||
	char coords[3][256];
 | 
			
		||||
	FloatToString(bot_start_coords[0], coords[0], sizeof(coords[]));
 | 
			
		||||
	FloatToString(bot_start_coords[1], coords[1], sizeof(coords[]));
 | 
			
		||||
	FloatToString(bot_start_coords[2], coords[2], sizeof(coords[]));
 | 
			
		||||
        Format(sQuery, sizeof(sQuery), "insert into `maps_coordinates` (`mapname`, `recordname`, `coordinate`) VALUES ('%s', 'unknown', '%s %s %s')", map_name, coords[0], coords[1], coords[2]);
 | 
			
		||||
        g_dDatabase.Query(SQL_insertQuery, sQuery, _, DBPrio_High);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void select_map_related_surfs()
 | 
			
		||||
{
 | 
			
		||||
	char map_name[256];
 | 
			
		||||
        GetCurrentMap(map_name, sizeof(map_name));
 | 
			
		||||
	char sQuery[256];
 | 
			
		||||
        Format(sQuery, sizeof(sQuery), "select recordname, coordinate from `maps_coordinates` where mapname = '%s'", map_name);
 | 
			
		||||
        g_dDatabase.Query(SQL_OnQueryCompleted, sQuery, _, DBPrio_High);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void SQL_OnQueryCompleted(Database db, DBResultSet results, const char[] error, DataPack data)
 | 
			
		||||
{
 | 
			
		||||
        if (!db || strlen(error))
 | 
			
		||||
        {       
 | 
			
		||||
                LogError("Query error: %s", error);
 | 
			
		||||
                return;
 | 
			
		||||
        }
 | 
			
		||||
	int iterator = 0;
 | 
			
		||||
	for (int i = 0; i < sizeof(map_coorindates); i++)
 | 
			
		||||
	{
 | 
			
		||||
		Format(map_coorindates[i], sizeof(map_coorindates[]), "");
 | 
			
		||||
		Format(map_recordname[i], sizeof(map_recordname[]), "");
 | 
			
		||||
	}
 | 
			
		||||
	while (results.RowCount > 0 && results.FetchRow())
 | 
			
		||||
	{
 | 
			
		||||
		results.FetchString(0, map_recordname[iterator], sizeof(map_recordname[]));
 | 
			
		||||
                results.FetchString(1, map_coorindates[iterator], sizeof(map_coorindates[]));
 | 
			
		||||
		iterator++;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public void OnMapStart()
 | 
			
		||||
{
 | 
			
		||||
	if (!g_dDatabase)
 | 
			
		||||
                Database.Connect(SQL_OnDatabaseConnect, "bot_surfing");
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		select_map_related_surfs();
 | 
			
		||||
		CreateTimer(0.30, update_mimic_coords, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void SQL_OnDatabaseConnect(Database db, const char[] error, any data)
 | 
			
		||||
{
 | 
			
		||||
        if(!db || strlen(error))
 | 
			
		||||
        {
 | 
			
		||||
                LogError("Database error: %s", error);
 | 
			
		||||
                return;
 | 
			
		||||
        }
 | 
			
		||||
        g_dDatabase = db;
 | 
			
		||||
        char sQuery[256];
 | 
			
		||||
        Format(sQuery, sizeof(sQuery), "CREATE TABLE IF NOT EXISTS `maps_coordinates` (`mapname` VARCHAR(254) NOT NULL, `coordinate` VARCHAR(254) NOT NULL, `recordname` VARCHAR(254) NOT NULL, PRIMARY KEY (`mapname`, `recordname`, `coordinate`))");
 | 
			
		||||
        g_dDatabase.Query(SQL_FinishedQuery_creating_tables, sQuery, _, DBPrio_High);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void SQL_insertQuery_record_saved(Database db, DBResultSet results, const char[] error, DataPack data)
 | 
			
		||||
{
 | 
			
		||||
        if (!db || strlen(error))
 | 
			
		||||
        {
 | 
			
		||||
                LogError("Query error: %s", error);
 | 
			
		||||
        }
 | 
			
		||||
	select_map_related_surfs();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void SQL_insertQuery(Database db, DBResultSet results, const char[] error, DataPack data)
 | 
			
		||||
{
 | 
			
		||||
        if (!db || strlen(error))
 | 
			
		||||
        {
 | 
			
		||||
                LogError("Query error: %s", error);
 | 
			
		||||
        }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public void SQL_FinishedQuery_creating_tables(Database db, DBResultSet results, const char[] error, DataPack data)
 | 
			
		||||
{
 | 
			
		||||
        if (!db || strlen(error))
 | 
			
		||||
        {
 | 
			
		||||
                LogError("Query error: %s", error);
 | 
			
		||||
        }
 | 
			
		||||
	select_map_related_surfs();
 | 
			
		||||
        CreateTimer(0.30, update_mimic_coords, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public bool is_bot_player(int client)
 | 
			
		||||
{
 | 
			
		||||
        return is_autism_bot1(client) || is_autism_bot2(client) || is_autism_bot3(client) || is_autism_bot4(client) || false; //change to true for debugging on dev
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public bool is_autism_bot1(int client)
 | 
			
		||||
{
 | 
			
		||||
        char auth[50];
 | 
			
		||||
        GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
 | 
			
		||||
        return StrEqual("[U:1:120378081]", auth, false) || StrEqual("STEAM_0:1:60189040", auth, false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public bool is_autism_bot2(int client)
 | 
			
		||||
{
 | 
			
		||||
        char auth[50];
 | 
			
		||||
        GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
 | 
			
		||||
        return StrEqual("[U:1:1036189204]", auth, false) || StrEqual("STEAM_0:0:518094602", auth, false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public bool is_autism_bot3(int client)
 | 
			
		||||
{
 | 
			
		||||
        char auth[50];
 | 
			
		||||
        GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
 | 
			
		||||
        return StrEqual("[U:1:408797742]", auth, false) || StrEqual("STEAM_0:0:204398871", auth, false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public bool is_autism_bot4(int client)
 | 
			
		||||
{
 | 
			
		||||
        char auth[50];
 | 
			
		||||
        GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
 | 
			
		||||
        return StrEqual("[U:1:1221121532]", auth, false) || StrEqual("STEAM_0:0:610560766", auth, false);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user