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

Announce Spray Height above the floor in Chat (vector tracing problem)


Post New Thread Reply   
 
Thread Tools Display Modes
ketakevin
Junior Member
Join Date: Jul 2017
Location: Berlin, Germany
Old 05-16-2018 , 09:45   Re: Announce Spray Height above the floor in Chat (vector tracing problem)
Reply With Quote #11

Quote:
Originally Posted by shanapu View Post
tyvm, I could've used that hint some days ago lol

My tool works now without any more bugs. Also detects touching ceiling/floor.
/thread

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

public Plugin myinfo =
{
	name = "Mass",
	author = "ketakevin",
	description = "sourcemod port of the spray_distance_to_floor amx plugin by exolent",
	version = "1.0",
	url = "177 views"
};

/**
 * Called when the plugin is fully initialized and all known external references 
 * are resolved. This is only called once in the lifetime of the plugin, and is 
 * paired with OnPluginEnd().
 *
 * If any run-time error is thrown during this callback, the plugin will be marked 
 * as failed.
 *
 * It is not necessary to close any handles or remove hooks in this function.  
 * SourceMod guarantees that plugin shutdown automatically and correctly releases 
 * all resources.
 *
 * @noreturn
 */
public OnPluginStart() 
{
    AddTempEntHook("Player Decal", PlayerSpray);
}

public Action:PlayerSpray(const String:szTempEntName[], const arrClients[], iClientCount, Float:flDelay) 
{
    new client = TE_ReadNum("m_nPlayer");
    if(IsValidClient(client)) {
		decl Float:start[3], Float:angle[3], Float:end[3], Float:normal[3];
		decl Float:vecPos[3], Float:height;
		new String: cname[30];
		
		//Getting clients eyes position
		GetClientEyePosition(client, start);
		//Getting clients aim direction
		GetClientEyeAngles(client, angle);
		
		//Tracing the players aim...
		TR_TraceRayFilter(start, angle, MASK_SHOT_PORTAL, RayType_Infinite, TraceEntityFilterPlayer, client);
		//...until it hits a wall and saving the end point to end vector
		if (TR_DidHit(INVALID_HANDLE)) {
			TR_GetEndPosition(end, INVALID_HANDLE);
		}

		//adding one unit in player direction
		if(start[0]>end[0]) {
			end[0] = end[0] + 1;
		}
		if(start[0]<end[0]){
			end[0] = end[0] - 1;
		}
		if(start[1]>end[1]){
			end[1] = end[1] + 1;
		}
		if(start[1]<end[1]){
			end[1] = end[1] - 1;
		}
		
		//Tracing from the end point (spray location)
		TR_TraceRayFilter(end, {90.0, 0.0, 0.0}, MASK_SHOT_PORTAL, RayType_Infinite, TraceEntityFilterPlayer, client); 
		//...down to the floor and saving the new end point to vecPos
		if(TR_DidHit(INVALID_HANDLE)) { 
			TR_GetEndPosition(vecPos, INVALID_HANDLE); 
		}
		
		//Calculating the spray height relative to the floor
		height = end[2] - vecPos[2];
		
		//Getting the players name
		GetClientName(client, cname, 30)
		
		//If spray touches the ground
		if(height < 24.0){
			CPrintToChatAll("{lightgreen}[{green}Mass{lightgreen}] %s{green}s Spray beruehrt den Boden!",cname,height);
			return;
		}
		
		//Tracing from end point (spray location)
		TR_TraceRayFilter(end, {-90.0, 0.0, 0.0}, MASK_SHOT_PORTAL, RayType_Infinite, TraceEntityFilterPlayer, client); 
		//up to the heaven until it hits the roof
		if(TR_DidHit(INVALID_HANDLE)) { 
			TR_GetEndPosition(vecPos, INVALID_HANDLE); 
		} 
		
		//comparing height of the spray with height of the roof, exit function if spray touches the roof
		if(end[2] > vecPos[2]-24.0) {
			CPrintToChatAll("{lightgreen}[{green}Mass{lightgreen}] %s{green}s Spray beruehrt die Decke!",cname,height);
			return;
		}
		
		//Output players name + spray height in the chat
		CPrintToChatAll("{lightgreen}[{green}Mass{lightgreen}] %s {green}hat in einer Hoehe von{lightgreen} %.2f {green}gesprueht.",cname,height);
        //TODO: calculate spray height above the floor from three given vectors
    }
}

public bool:IsValidClient(client) 
{
    if(client <= 0)
        return false;
    if(client > MaxClients)
        return false;

    return IsClientInGame(client);
} 

public bool:TraceEntityFilterPlayer(entity, contentsMask, any:data) 
{
	return entity > MaxClients;
}
Attached Files
File Type: smx mass.smx (11.5 KB, 32 views)

Last edited by ketakevin; 05-16-2018 at 09:49.
ketakevin 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 17:56.


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