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

How to detect a client looking/aiming at the ground?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LiveAndLetDie
Junior Member
Join Date: Sep 2019
Location: Finland
Old 07-17-2022 , 13:21   How to detect a client looking/aiming at the ground?
Reply With Quote #1

I would need a little nifty function to detect whenever a player is looking/aiming at the ground but couldn't figure it out. I guess it could be done with vectors or tracerays. Any help?
LiveAndLetDie is offline
LiveAndLetDie
Junior Member
Join Date: Sep 2019
Location: Finland
Old 07-18-2022 , 20:33   Re: How to detect a client looking/aiming at the ground?
Reply With Quote #2

Quote:
Originally Posted by 000 View Post
Hi.
What do you want to do?
I want clients to be able to spawn props on ground or floor only.
LiveAndLetDie is offline
LiveAndLetDie
Junior Member
Join Date: Sep 2019
Location: Finland
Old 07-19-2022 , 05:42   Re: How to detect a client looking/aiming at the ground?
Reply With Quote #3

I know this plugin and how it works but unfortunately it doesn't help me to solve my problem.
LiveAndLetDie is offline
backwards
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 07-21-2022 , 17:51   Re: How to detect a client looking/aiming at the ground?
Reply With Quote #4

This should work how you wanted by checking the normals of the end point from the traceray and the players viewangles.x direction.

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

public void OnPluginStart()
{
    
RegConsoleCmd("place"Command_Place);
}

public 
Action Command_Place(int clientint args)
{
    
TryPlaceObject(client);
    return 
Plugin_Handled;
}

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

void TryPlaceObject(int client)
{
    
float EyePos[3], ViewAngles[3], Normals[3];
    
    
GetClientEyePosition(clientEyePos);
    
GetClientEyeAngles(clientViewAngles);

    
//simple exit early if not looking downward based on viewangles
    
if(ViewAngles[0] < 0.0)
        return;

    
TR_TraceRayFilter(EyePosViewAnglesMASK_PLAYERSOLIDRayType_InfiniteFilter_LocalPlayerclient);

    
//Traceray hit nothing
    
if(!TR_DidHit(INVALID_HANDLE))
        return;
    
    
TR_GetPlaneNormal(INVALID_HANDLENormals);
    
    
//check angle of the surface hit by raytrace to prevent spawning on slanted edges/walls
    //can be inverted depending on map (I think?)
    
if(Normals[2] < 0.9 && Normals[2] > -0.9)
        return;
    
    
//Find the raytrace end point location
    
float HitEndPoint[3];
    
TR_GetEndPosition(HitEndPoint);
    
    
//Create item and teleport it to HitEndPos
    
int ent CreateEntityByName("weapon_ak47");
    
DispatchSpawn(ent);
    
    
TeleportEntity(entHitEndPointNULL_VECTORNULL_VECTOR);
    
    
PrintToChat(client"Spawned Item at (%.2f, %.2f, %.2f)"HitEndPoint[0], HitEndPoint[1], HitEndPoint[2]);

backwards is offline
Reply



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 07:50.


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