Quote:
Originally Posted by shanapu
|
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;
}