Raised This Month: $32 Target: $400
 8% 

Solved Pathfinding for clients (client follow a path)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
EfeDursun125
Senior Member
Join Date: Feb 2019
Location: Turkey
Old 09-01-2019 , 15:17   Pathfinding for clients (client follow a path)
Reply With Quote #1

Hello,
Sorry My English is Bad

I'm maked afk bot for tf2 (auto play bot for afk players) good working and unfinished but i maked waypoint system and not good. How to use module or make pathfinding system for client?

is there anything you can offer me for pathfinding???

afkbots need follow a path, please help me

Last edited by EfeDursun125; 09-02-2019 at 08:21.
EfeDursun125 is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 09-01-2019 , 15:42   Re: Pathfinding for clients (client follow a path)
Reply With Quote #2

https://github.com/Pelipoika/PathFollower Windows only tho

Test plugin:

Code:
#include <sdktools>
#include <sdkhooks>
#include <tf2>
#include <tf2_stocks>
#include <PathFollower>

#pragma newdecls required

int g_iPathLaserModelIndex = -1;

float g_flGoal[MAXPLAYERS + 1][3];

//What is this "Cursor" thing

public Plugin myinfo = 
{
	name = "[TF2] PathFollower extension testing",
	author = "Pelipoika",
	description = "",
	version = "1.0",
	url = "http://www.sourcemod.net/plugins.php?author=Pelipoika&search=1"
};

public void OnMapStart()
{
	g_iPathLaserModelIndex = PrecacheModel("materials/sprites/laserbeam.vmt");
}

public void OnPluginStart()
{
	RegAdminCmd("sm_pathgoal", Command_PathGoal,   ADMFLAG_ROOT);
	RegAdminCmd("sm_path",     Command_PathToggle, ADMFLAG_ROOT);
}

public Action Command_PathGoal(int client, int args)
{
	if(client > 0 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client))
	{
		GetClientAbsOrigin(client, g_flGoal[client]);
		PrintToChat(client, "Goal set to your absorigin");
	}
	
	return Plugin_Handled;
}

public Action Command_PathToggle(int client, int args)
{
	if(client > 0 && client <= MaxClients && IsClientInGame(client) && IsPlayerAlive(client))
	{
		if(!PF_Exists(client))
		{
			PrintToChat(client, "Pathing: ON");
		
			PF_Create(client, 18.0, 72.0, 1000.0, 0.6, MASK_PLAYERSOLID, 300.0, 0.5, 1.5, 1.0);
			PF_SetGoalVector(client, g_flGoal[client]);
			
			PF_EnableCallback(client, PFCB_Approach, PF_Approach);
			PF_EnableCallback(client, PFCB_ClimbUpToLedge, PF_ClibmUpToLedge);
			PF_EnableCallback(client, PFCB_IsEntityTraversable, PF_IsEntityTraversable);
			PF_EnableCallback(client, PFCB_PathFailed, PF_PathFailed);
			
			PF_StartPathing(client);
		}
		else if(PF_Exists(client))
		{
			PrintToChat(client, "Pathing: OFF");
		
			PF_StopPathing(client);
			PF_Destroy(client);
		}
	}
	
	return Plugin_Handled;
}

public void PF_Approach(int bot_entindex, float vecGoal[3])
{
	g_flGoal[bot_entindex][0] = vecGoal[0];
	g_flGoal[bot_entindex][1] = vecGoal[1];
	g_flGoal[bot_entindex][2] = vecGoal[2];
	
//	TE_ShowPole(g_flGoal[bot_entindex], {255, 0, 0, 255});
}

bool bJump;

public bool PF_ClibmUpToLedge(int bot_entidx, const float dst[3], const float dir[3])
{
	bJump = true;
	
	PrintCenterText(bot_entidx, "PF_ClibmUpToLedge");
}

public bool PF_IsEntityTraversable(int bot_entindex, int other_entidx, TraverseWhenType when)
{
	char strClass[64];
	GetEntityClassname(other_entidx, strClass, 64);
		
	PrintCenterText(bot_entindex, "PF_ClibmUpToLedge %s", strClass);
}

public void PF_PathFailed(int bot_entindex)
{
	PrintCenterText(bot_entindex, "PF_PathFailed");
}

public Action OnPlayerRunCmd(int client, int &iButtons, int &iImpulse, float fVel[3], float fAng[3], int &iWeapon)
{
	if(IsFakeClient(client) || !PF_Exists(client) || !IsPlayerAlive(client))
		return Plugin_Continue;
	
/*	for (int i = 0; i < 32; i++)
	{
		float flFromPos[3];
		float flToPos[3];
		
		if(PF_GetFutureSegment(client, i, flFromPos) && PF_GetFutureSegment(client, i + 1, flToPos))
		{
			TE_ShowPole(flFromPos, {0, 255, 255, 100});
			
			TE_SetupBeamPoints(flFromPos,
				flToPos,
				g_iPathLaserModelIndex,
				g_iPathLaserModelIndex,
				0,
				30,
				0.25,
				5.0,
				5.0,
				5, 
				0.0,
				{255, 255, 255, 100},
				30);
			
			TE_SendToClient(client);
		}
	}*/
	
	TF2_MoveTo(client, g_flGoal[client], fVel, fAng);
	
	if(bJump)
	{
		iButtons |= IN_JUMP;
		bJump = false;
		
		return Plugin_Changed;
	}

	return Plugin_Continue;
}

stock void TF2_MoveTo(int client, float flGoal[3], float fVel[3], float fAng[3])
{
	float flPos[3];
	GetClientAbsOrigin(client, flPos);

	float newmove[3];
	SubtractVectors(flGoal, flPos, newmove);
	
	newmove[1] = -newmove[1];
	
	float sin = Sine(fAng[1] * FLOAT_PI / 180.0);
	float cos = Cosine(fAng[1] * FLOAT_PI / 180.0);						
	
	fVel[0] = cos * newmove[0] - sin * newmove[1];
	fVel[1] = sin * newmove[0] + cos * newmove[1];
	
	NormalizeVector(fVel, fVel);
	ScaleVector(fVel, 450.0);
}

stock bool TF2_IsNextToWall(int client)
{
	float flPos[3];
	GetClientAbsOrigin(client, flPos);
	
	float flMaxs[3], flMins[3];
	GetEntPropVector(client, Prop_Send, "m_vecMaxs", flMaxs);
	GetEntPropVector(client, Prop_Send, "m_vecMins", flMins);
	
	flMaxs[0] += 2.5;
	flMaxs[1] += 2.5;
	flMins[0] -= 2.5;
	flMins[1] -= 2.5;
	
	flPos[2] += 18.0;
	
	//Perform a wall check to see if we are near any obstacles we should try jump over
	Handle TraceRay = TR_TraceHullFilterEx(flPos, flPos, flMins, flMaxs, MASK_PLAYERSOLID, ExcludeFilter, client);
	
	bool bHit = TR_DidHit(TraceRay);	
	
	delete TraceRay;
	
	return bHit;
}

public bool ExcludeFilter(int entity, int contentsMask, any iExclude)
{
    return !(entity == iExclude);
}

stock void TE_ShowPole(float flPos[3], int Color[4])
{
	float flToPos[3];
	flToPos[0] = flPos[0];
	flToPos[1] = flPos[1];
	flToPos[2] = flPos[2];
	flToPos[2] += 60.0;
	
	//Show a giant vertical beam at our goal node
	TE_SetupBeamPoints(flPos, flToPos, g_iPathLaserModelIndex, g_iPathLaserModelIndex, 0, 30, 0.1, 5.0, 5.0, 5, 0.0, Color, 30);
	TE_SendToAll();
}
__________________

Last edited by Pelipoika; 11-27-2019 at 22:14.
Pelipoika is offline
EfeDursun125
Senior Member
Join Date: Feb 2019
Location: Turkey
Old 09-01-2019 , 15:57   Re: Pathfinding for clients (client follow a path)
Reply With Quote #3

Quote:
Originally Posted by Pelipoika View Post
https://github.com/Pelipoika/PathFollower Windows only tho

Test plugin:

Code:
#include <sourcemod>
#include <PathFollower>

public void OnPluginStart() 
{
    RegAdminCmd("sm_cg2m", CGTM, ADMFLAG_ROOT);
}

public Action CGTM(int client, int args) 
{
    char arg[MAX_NAME_LENGTH];
    GetCmdArg(1, arg, sizeof(arg));
    int x = FindTarget(client, arg);
    
    if (!PF_Exists(x)) 
    {
        PrintToChatAll("Does not exist, creating!");
        PF_Create(x, 18.0, 64.0, 1000.0, 0.6, MASK_PLAYERSOLID, 300.0, 2.0, 1.0);
    }
    
    PF_SetGoalEntity(x, client);
    
    PF_StartPathing(x);
    
    PF_EnableCallback(x, PFCB_Approach, Approach);
    
    return Plugin_Handled;
} 

float g_flGoal[MAXPLAYERS + 1][3];

public Action OnPlayerRunCmd(int client, int &iButtons, int &iImpulse, float fVel[3], float fAng[3], int &iWeapon)
{
    if(!IsPlayerAlive(client) || !PF_Exists(client))
        return Plugin_Continue;

    TF2_MoveTo(client, g_flGoal[client], fVel, fAng);

    return Plugin_Continue;
}

stock void TF2_MoveTo(int client, float flGoal[3], float fVel[3], float fAng[3])
{
    float flPos[3];
    GetClientAbsOrigin(client, flPos);

    float newmove[3];
    SubtractVectors(flGoal, flPos, newmove);
    
    newmove[1] = -newmove[1];
    
    float sin = Sine(fAng[1] * FLOAT_PI / 180.0);
    float cos = Cosine(fAng[1] * FLOAT_PI / 180.0);                        
    
    fVel[0] = cos * newmove[0] - sin * newmove[1];
    fVel[1] = sin * newmove[0] + cos * newmove[1];
    
    NormalizeVector(fVel, fVel);
    ScaleVector(fVel, 450.0);
}

public void Approach(int bot_entidx, const float dst[3])
{
    g_flGoal[bot_entidx][0] = dst[0];
    g_flGoal[bot_entidx][1] = dst[1];
    g_flGoal[bot_entidx][2] = dst[2];
}
thank you, and i getting a error

[SM] Plugin pathfollowertest.smx failed to load: Required extension "PathFollower" file("PathFollower.ext") not running.

i can't see a extension in github
EfeDursun125 is offline
Pelipoika
Veteran Member
Join Date: May 2012
Location: Inside
Old 09-01-2019 , 20:06   Re: Pathfinding for clients (client follow a path)
Reply With Quote #4

Quote:
Originally Posted by EfeDursun125 View Post
thank you, and i getting a error

[SM] Plugin pathfollowertest.smx failed to load: Required extension "PathFollower" file("PathFollower.ext") not running.

i can't see a extension in github
https://github.com/Pelipoika/PathFollower/releases ??
__________________
Pelipoika is offline
EfeDursun125
Senior Member
Join Date: Feb 2019
Location: Turkey
Old 09-02-2019 , 06:25   Re: Pathfinding for clients (client follow a path)
Reply With Quote #5

Quote:
Originally Posted by Pelipoika View Post
sorry i clicked to source code

EDIT : thank you

Last edited by EfeDursun125; 11-26-2021 at 08:34.
EfeDursun125 is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:22.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode