Got it running now. However if you're standing directly in front of a wall it doesnt work as expected, maybe one of you guys knows a solution for this?
If someone cares about the working plugin look at this
Code:
#include <sdktools>
#include <sourcemod>
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];
//Getting clients eyes position
GetClientEyePosition(client, start);
//Getting clients aim direction
GetClientEyeAngles(client, angle);
//PrintToServer("player position x: %.1f, y: %.1f, z: %.1f", start[0],start[1],start[2]);
//Tracing the players aim...
TR_TraceRayFilter(start, angle, MASK_SOLID, RayType_Infinite, TraceEntityFilterPlayer, client);
//...until it hits a wall and saving the end point
if (TR_DidHit(INVALID_HANDLE))
{
TR_GetEndPosition(end, INVALID_HANDLE);
}
//PrintToServer("aim location x: %.1f, y: %.1f, z: %.1f", end[0],end[1],end[2]);
decl Float:vecPos[3], Float:height;
new String: cname[30];
//Tracing from the end point...
TR_TraceRay(end, {90.0, 0.0, 0.0}, MASK_PLAYERSOLID_BRUSHONLY, RayType_Infinite);
//...down to the floor and saving the new end point
if(TR_DidHit(INVALID_HANDLE)) {
TR_GetEndPosition(vecPos, INVALID_HANDLE);
}
//PrintToServer("vector values x: %.1f, y: %.1f, z: %.1f", vecPos[0],vecPos[1],vecPos[2]);
//Calculating the spray height relative to the floor
height = end[2] - vecPos[2];
//Getting the players name
GetClientName(client, cname, 30)
//Output players name + spray height in the chat
PrintToChatAll("[Mass] %s hat in einer Hoehe von %.2f 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;
}