Raised This Month: $12 Target: $400
 3% 

Solved [CSGO] how to warp players without getting stuck in walls?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Austin
Senior Member
Join Date: Oct 2005
Old 07-21-2022 , 01:49   [CSGO] how to warp players without getting stuck in walls?
Reply With Quote #1

I have the following code that warps the farthest bot to where I am pointing.
It works perfectly when pointing at the floor but
when pointing to a wall or other things it places the bots into them and they get stuck.

Is there a way to do the trace to keep them from being placed into things and being stuck?
tx


PHP Code:
public Action Command_warpFarBot(int clientint args)
{
    
float clientPos[3];
    
GetEntPropVector(clientProp_Data"m_vecOrigin"clientPos);

    
int farthestBotIndex getFarthestBot(client);

    new 
Float:g_Origin[3];
    new 
Float:g_Angle[3];
    new 
Float:normal[3];
    
    
GetClientEyePosition(clientg_Origin);
    
GetClientEyeAngles(clientg_Angle);
    
TR_TraceRayFilter(g_Origing_AngleMASK_SOLIDRayType_InfiniteTraceRayDontHitSelfclient);
    
//TR_TraceRayFilter(g_Origin, g_Angle, MASK_OPAQUE, RayType_Infinite, TraceRayDontHitSelf, client);
    
if(TR_DidHit(INVALID_HANDLE))
    {
        
//TR_GetSurfaceName(INVALID_HANDLE,tmp, 255);
        //PrintToChat(client, "[Surface]= %s", tmp);
        
        
TR_GetEndPosition(g_Origin);
        
TR_GetPlaneNormal(INVALID_HANDLEnormal); 
        
GetVectorAngles(normalnormal); 
        
normal[0] += 90.0
        
TeleportEntity(farthestBotIndexg_OriginnormalNULL_VECTOR);    
        
//TeleportEntity(farthestBotIndex, g_Origin, g_Angle, NULL_VECTOR);
        //TeleportEntity(ent, end, normal, NULL_VECTOR); 
        
PrintToChat(client"[SM] Teleported %N to you."farthestBotIndex);
    } 

Last edited by Austin; 07-21-2022 at 16:03.
Austin is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 07-21-2022 , 08:51   Re: [CSGO] how to warp players without getting stuck in walls?
Reply With Quote #2

You want to use a trace hull to scan a rectangular prism area for intersecting entitys before teleporting the player.
The trace hull size would be the max size of the player entity.
If something is intersecting the end point then you would want to move the endpoint away from the wall/ent you just hit by a fixed value in the inverse direction of the tracerays view angle.
Then you run the tracehull scan again until it is cleared or a max threshold of scans are reached.
If the area is then clear we would teleport the player entity or else deny it.


PHP Code:
#include <sourcemod>
#include <sdktools>

int beammdl = -1;

public 
void OnPluginStart()
{
    
beammdl PrecacheModel("materials/sprites/laserbeam.vmt"true);
    
RegConsoleCmd("warpfarbot"Command_WarpFarBot);
}

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

bool IsAreaClear(int clientfloat position[3])
{
    
//This is the players collision rectangular prism size defined by two 3D Points farthest away from each other
    
static float vecMins[3] = {-16.0, -16.00.0};
    static 
float vecMaxs[3] = {16.016.072.0};
    
    
TR_TraceHullFilter(positionpositionvecMinsvecMaxsMASK_PLAYERSOLIDFilter_LocalPlayerclient);
    
    if(!
TR_DidHit())
        return 
true;
    
    return 
false;
}

public 
bool Filter_LocalPlayer(int entityint contentsMaskany client)
{
    return !(
entity == client)
}

public 
bool Filter_ExcludePlayers(int entityint contentsMaskany data)
{
    return !((
entity 0) && (entity <= MaxClients));
}  

int GetFarthestBot(int client)
{
    
float playerPos[3];
    
GetClientEyePosition(clientplayerPos);

    
float farthestDistance 0.0;
    
int farthestBot = -1;
    
    for(
int bot 1;bot<MaxClients+1;bot++)
    {
        if(
IsValidClient(bot) && IsFakeClient(bot) && IsPlayerAlive(bot))
        {
            
float botPos[3];
            
GetClientEyePosition(botbotPos);
    
            
float dist GetVectorDistance(playerPosbotPos);
            if(
dist farthestDistance)
            {
                
farthestDistance dist;
                
farthestBot bot;
            }
        }
    }
    
    return 
farthestBot;
}

public 
Action Command_WarpFarBot(int clientint args)
{
    
int farthestBotIndex GetFarthestBot(client);

    if(
farthestBotIndex == -1)
    {
        
PrintToChat(client"no active bots!");
        return 
Plugin_Handled;
    }

    
float g_Origin[3], g_Angle[3], HitEndPoint[3];
    
    
GetClientEyePosition(clientg_Origin);
    
GetClientEyeAngles(clientg_Angle);
    
TR_TraceRayFilter(g_Origing_AngleMASK_SHOTRayType_InfiniteFilter_LocalPlayerclient);
    
    if(!
TR_DidHit(INVALID_HANDLE))
    {
        
PrintToChat(client"\x01\x02 \x02Trace ray did not hit anything!");
        return 
Plugin_Handled;
    }
    
    
TR_GetEndPosition(HitEndPoint);
    
    
//We can get the ground underneath the player by shooting another raytrace directly down
    //This prevents players from spawning on the wall really high and causing fall damage
    
float down[3] = {90.00.00.0};
        
    
TR_TraceRayFilter(HitEndPointdownMASK_SHOTRayType_InfiniteFilter_ExcludePlayers);
    if(!
TR_DidHit(INVALID_HANDLE))
    {
        
PrintToChat(client"\x01\x02 \x02Could not find ground!");
        return 
Plugin_Handled;
    }
    
    
TR_GetEndPosition(HitEndPoint);
    
    
//Elevate off the ground
    
HitEndPoint[2] += 10.0;
    
    
float fForwards[3];
    
GetAngleVectors(g_AnglefForwardsNULL_VECTORNULL_VECTOR);
    
    
//Invert forwards angle to change direction to face from hitpos to client running the cmd
    
for(int i 0;3i++)
        
fForwards[i] *= -1;
    
    
//Move 32 units from hit point on the wall
    
for(int i 0;3i++)
        
HitEndPoint[i] = HitEndPoint[i] + (fForwards[i] * 32.0);
    
    
int iterationCount 0;
    
    
//Check if point is clear
    
while(!IsAreaClear(clientHitEndPoint))
    {
        
float HitEndPointDebug[3];
        
        
//Just create offset point for debug draw line secondary point
        
for(int i 0;3i++)
            
HitEndPointDebug[i] = HitEndPoint[i] + 5.0;
        
        
//debug visuals
        
TE_SetupBeamPoints(HitEndPointHitEndPointDebugbeammdl00010.01.01.010.0, {25500255}, 1);
        
TE_SendToAll();
                    
        
iterationCount++;
        if(
iterationCount 10)
        {
            
PrintToChat(client"\x01\x02 \x02Area is not Clear!");
            return 
Plugin_Handled;
        }
        
        
//Iterate point 32 units towards the player camera for next trace hull check
        
for(int i 0;3i++)
            
HitEndPoint[i] = HitEndPoint[i] + (fForwards[i] * 32.0);
    }
    
    
//debug message for iteration loop count
    //PrintToChat(client, "\x01\x02 \x10Exit loop after %i iterations", iterationCount);
    
    
TeleportEntity(farthestBotIndexHitEndPointNULL_VECTORNULL_VECTOR);      
    
PrintToChat(client"\x01\x10 \x06Teleported %N"farthestBotIndex);
    
    return 
Plugin_Handled;
}

bool IsValidClient(int client

    if (!(
<= client <= MaxClients) || !IsClientConnected(client) || !IsClientInGame(client) || IsClientSourceTV(client) || IsClientReplay(client)) 
        return 
false
         
    return 
true

Video of above plugin code


Last edited by backwards; 07-21-2022 at 08:52.
backwards is offline
Franc1sco
Veteran Member
Join Date: Oct 2010
Location: Spain (Madrid)
Old 07-21-2022 , 11:11   Re: [CSGO] how to warp players without getting stuck in walls?
Reply With Quote #3

Quote:
Originally Posted by backwards View Post
You want to use a trace hull to scan a rectangular prism area for intersecting entitys before teleporting the player.
The trace hull size would be the max size of the player entity.
If something is intersecting the end point then you would want to move the endpoint away from the wall/ent you just hit by a fixed value in the inverse direction of the tracerays view angle.
Then you run the tracehull scan again until it is cleared or a max threshold of scans are reached.
If the area is then clear we would teleport the player entity or else deny it.


PHP Code:
#include <sourcemod>
#include <sdktools>

int beammdl = -1;

public 
void OnPluginStart()
{
    
beammdl PrecacheModel("materials/sprites/laserbeam.vmt"true);
    
RegConsoleCmd("warpfarbot"Command_WarpFarBot);
}

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

bool IsAreaClear(int clientfloat position[3])
{
    
//This is the players collision rectangular prism size defined by two 3D Points farthest away from each other
    
static float vecMins[3] = {-16.0, -16.00.0};
    static 
float vecMaxs[3] = {16.016.072.0};
    
    
TR_TraceHullFilter(positionpositionvecMinsvecMaxsMASK_PLAYERSOLIDFilter_LocalPlayerclient);
    
    if(!
TR_DidHit())
        return 
true;
    
    return 
false;
}

public 
bool Filter_LocalPlayer(int entityint contentsMaskany client)
{
    return !(
entity == client)
}

public 
bool Filter_ExcludePlayers(int entityint contentsMaskany data)
{
    return !((
entity 0) && (entity <= MaxClients));
}  

int GetFarthestBot(int client)
{
    
float playerPos[3];
    
GetClientEyePosition(clientplayerPos);

    
float farthestDistance 0.0;
    
int farthestBot = -1;
    
    for(
int bot 1;bot<MaxClients+1;bot++)
    {
        if(
IsValidClient(bot) && IsFakeClient(bot) && IsPlayerAlive(bot))
        {
            
float botPos[3];
            
GetClientEyePosition(botbotPos);
    
            
float dist GetVectorDistance(playerPosbotPos);
            if(
dist farthestDistance)
            {
                
farthestDistance dist;
                
farthestBot bot;
            }
        }
    }
    
    return 
farthestBot;
}

public 
Action Command_WarpFarBot(int clientint args)
{
    
int farthestBotIndex GetFarthestBot(client);

    if(
farthestBotIndex == -1)
    {
        
PrintToChat(client"no active bots!");
        return 
Plugin_Handled;
    }

    
float g_Origin[3], g_Angle[3], HitEndPoint[3];
    
    
GetClientEyePosition(clientg_Origin);
    
GetClientEyeAngles(clientg_Angle);
    
TR_TraceRayFilter(g_Origing_AngleMASK_SHOTRayType_InfiniteFilter_LocalPlayerclient);
    
    if(!
TR_DidHit(INVALID_HANDLE))
    {
        
PrintToChat(client"\x01\x02 \x02Trace ray did not hit anything!");
        return 
Plugin_Handled;
    }
    
    
TR_GetEndPosition(HitEndPoint);
    
    
//We can get the ground underneath the player by shooting another raytrace directly down
    //This prevents players from spawning on the wall really high and causing fall damage
    
float down[3] = {90.00.00.0};
        
    
TR_TraceRayFilter(HitEndPointdownMASK_SHOTRayType_InfiniteFilter_ExcludePlayers);
    if(!
TR_DidHit(INVALID_HANDLE))
    {
        
PrintToChat(client"\x01\x02 \x02Could not find ground!");
        return 
Plugin_Handled;
    }
    
    
TR_GetEndPosition(HitEndPoint);
    
    
//Elevate off the ground
    
HitEndPoint[2] += 10.0;
    
    
float fForwards[3];
    
GetAngleVectors(g_AnglefForwardsNULL_VECTORNULL_VECTOR);
    
    
//Invert forwards angle to change direction to face from hitpos to client running the cmd
    
for(int i 0;3i++)
        
fForwards[i] *= -1;
    
    
//Move 32 units from hit point on the wall
    
for(int i 0;3i++)
        
HitEndPoint[i] = HitEndPoint[i] + (fForwards[i] * 32.0);
    
    
int iterationCount 0;
    
    
//Check if point is clear
    
while(!IsAreaClear(clientHitEndPoint))
    {
        
float HitEndPointDebug[3];
        
        
//Just create offset point for debug draw line secondary point
        
for(int i 0;3i++)
            
HitEndPointDebug[i] = HitEndPoint[i] + 5.0;
        
        
//debug visuals
        
TE_SetupBeamPoints(HitEndPointHitEndPointDebugbeammdl00010.01.01.010.0, {25500255}, 1);
        
TE_SendToAll();
                    
        
iterationCount++;
        if(
iterationCount 10)
        {
            
PrintToChat(client"\x01\x02 \x02Area is not Clear!");
            return 
Plugin_Handled;
        }
        
        
//Iterate point 32 units towards the player camera for next trace hull check
        
for(int i 0;3i++)
            
HitEndPoint[i] = HitEndPoint[i] + (fForwards[i] * 32.0);
    }
    
    
//debug message for iteration loop count
    //PrintToChat(client, "\x01\x02 \x10Exit loop after %i iterations", iterationCount);
    
    
TeleportEntity(farthestBotIndexHitEndPointNULL_VECTORNULL_VECTOR);      
    
PrintToChat(client"\x01\x10 \x06Teleported %N"farthestBotIndex);
    
    return 
Plugin_Handled;
}

bool IsValidClient(int client

    if (!(
<= client <= MaxClients) || !IsClientConnected(client) || !IsClientInGame(client) || IsClientSourceTV(client) || IsClientReplay(client)) 
        return 
false
         
    return 
true

Video of above plugin code

Oh nice! I will consider integrate this to my Bot Spawner plugin.
__________________
Veteran Coder -> Activity channel
Coding on CS2 and taking paid and free jobs.

Contact: Steam, Telegram or discord ( franug ).

You like my work? +Rep in my steam profile comments or donate.

Franc1sco is offline
Send a message via MSN to Franc1sco
Austin
Senior Member
Join Date: Oct 2005
Old 07-21-2022 , 15:56   Re: [CSGO] how to warp players without getting stuck in walls?
Reply With Quote #4

Quote:
Originally Posted by backwards View Post
You want to use a trace hull to scan a rectangular prism area for intersecting entitys before teleporting the player....
WOW!
THANK YOU Franc1sco!

And also thanks to backwards.

Even though you "relied heavly" on Franc1sco' work
-you did all of the modifications-
to HAND me a WORKING
plugin working exactly how I needed it to work.
As well as describing exactly how it works...
There is major credit in that....

"relying heavly" on others work is how this community thrives...
Only thing is giving credit where deserved...

I have been here 20 years! (almost)
Going for another 20?!

I hope alliedmods.net and this great community never goes away.

Last edited by Austin; 07-21-2022 at 16:08.
Austin is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 07-21-2022 , 16:29   Re: [CSGO] how to warp players without getting stuck in walls?
Reply With Quote #5

Quote:
Originally Posted by Austin View Post
Even though you "relied heavly" on Franc1sco' work

"relying heavly" on others work is how this community thrives...
Only thing is giving credit where deserved...


I don't know where you got the idea that I used any of his code or references?
I wrote all the code myself, starting only from the snippet of code you posted above.




This is similar to things I already made in older projects like this:


Last edited by backwards; 07-21-2022 at 16:35.
backwards is offline
Austin
Senior Member
Join Date: Oct 2005
Old 07-22-2022 , 00:57   Re: [CSGO] how to warp players without getting stuck in walls?
Reply With Quote #6

Quote:
Originally Posted by backwards View Post

I don't know where you got the idea that I used any of his code or references?
I wrote all the code myself, starting only from the snippet of code you posted above.


This is similar to things I already made in older projects like this:
I misread Franc1sco post as sarcasm.

Very sorry about that!
VERY.

You obviously know SM coding
forwards and backwards.....

My apologies and hopefully I didn't offend you.

Many many thanks agian.

Last edited by Austin; 07-22-2022 at 16:59.
Austin is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 07-31-2022 , 23:17   Re: [CSGO] how to warp players without getting stuck in walls?
Reply With Quote #7

Mine is a foulproof function that will teleport you across the your angle. Even teleport behind you if needed / if you are staring directly below yourself.

It will teleport you to the aim position, then for every time you are stuck, teleport you backwards across the angle of aim ( so you can teleport someone behind you if you're looking at a wall... )

If all else fails, block the teleport.

https://github.com/eyal282/Useful-Co...mands.sp#L5763
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
rsdtt
Senior Member
Join Date: Oct 2009
Old 10-21-2022 , 06:32   Re: [CSGO] how to warp players without getting stuck in walls?
Reply With Quote #8

Quote:
Originally Posted by backwards View Post


I don't know where you got the idea that I used any of his code or references?
I wrote all the code myself, starting only from the snippet of code you posted above.




This is similar to things I already made in older projects like this:

How to draw the beam like your video? Thanks.
__________________
I am learning sm now
rsdtt 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 00:46.


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