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

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


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ketakevin
Junior Member
Join Date: Jul 2017
Location: Berlin, Germany
Old 07-18-2017 , 08:51   Announce Spray Height above the floor in Chat (vector tracing problem)
Reply With Quote #1

Hello nice people,
I'm currently setting up a jail server [CS:S] for some people and we need one plugin to work for our spray contests.
Sadly I couldn't find such plugin, any spraytracer I found doesn't offer this function.

The plugin should announce the spray height relative to the floor directly while/after the spray is placed on a wall in text chat. (cool would be announce of "touches the ground/ceiling" too)

Well, I found one plugin doing this but it is for amxx.
I tried to find equivalents to each function in the API database but no success, maybe someone can give me a hint how I could translate this to sourcepawn?
Here is the code of the amx plugin mentioned above:
Code:
#include < amxmodx >
#include < fakemeta >
#include < xs >

public plugin_init( )
{
	register_plugin( "Spray Distance to Floor", "0.0.1", "Exolent" );
	
	register_event( "23", "EventSpray", "a", "1=112" );
}

public EventSpray( )
{
	new iOrigin[ 3 ];
	iOrigin[ 0 ] = read_data( 3 );
	iOrigin[ 1 ] = read_data( 4 );
	iOrigin[ 2 ] = read_data( 5 );
	
	new Float:vecSprayOrigin[ 3 ];
	IVecFVec( iOrigin, vecSprayOrigin );
	
	new iPlayer = read_data( 2 );
	
	// get player's eyes origin
	new Float:vecPlayerOrigin[ 3 ];
	get_user_origin( iPlayer, iOrigin, 1 );
	IVecFVec( iOrigin, vecPlayerOrigin );
	
	// get direction player is aiming
	new Float:vecDirection[ 3 ];
	xs_vec_sub( vecSprayOrigin, vecPlayerOrigin, vecDirection );
	
	// set direction length to 10 units
	xs_vec_mul_scalar( vecDirection, 10.0 / vector_length( vecDirection ), vecDirection );
	
	// add the aim direction into the wall for a stop origin
	new Float:vecStop[ 3 ];
	xs_vec_add( vecSprayOrigin, vecDirection, vecStop );
	
	// reverse the direction to go away from wall
	xs_vec_mul_scalar( vecDirection, -1.0, vecDirection );
	
	// add the aim direction way from the wall for a start origin
	new Float:vecStart[ 3 ];
	xs_vec_add( vecSprayOrigin, vecDirection, vecStart );
	
	// trace from start to stop to get where the wall position is
	engfunc( EngFunc_TraceLine, vecStart, vecStop, IGNORE_MONSTERS, -1, 0 );
	
	// find the normal vector of the wall
	get_tr2( 0, TR_vecPlaneNormal, vecDirection );
	
	// remove and up/down direction from the normal vector
	vecDirection[ 2 ] = 0.0;
	
	// set direction length to 10 units
	xs_vec_mul_scalar( vecDirection, 5.0 / vector_length( vecDirection ), vecDirection );
	
	// add direction away from wall to spray origin for a safe area to trace to floor
	xs_vec_add( vecSprayOrigin, vecDirection, vecStart );
	
	// set the stop origin 9999.0 units below the start origin
	xs_vec_copy( vecStart, vecStop );
	vecStop[ 2 ] -= 9999.0;
	
	engfunc( EngFunc_TraceLine, vecStart, vecStop, IGNORE_MONSTERS, -1, 0 );
	
	get_tr2( 0, TR_vecEndPos, vecStop );
	
	new szName[ 32 ];
	get_user_name( iPlayer, szName, charsmax( szName ) );
	
	client_print( 0, print_chat, "%s sprayed %f units above the ground", szName, ( vecStart[ 2 ] - vecStop[ 2 ] ) );
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1033\\ f0\\ fs16 \n\\ par }
*/

Last edited by ketakevin; 05-12-2018 at 06:31.
ketakevin is offline
ketakevin
Junior Member
Join Date: Jul 2017
Location: Berlin, Germany
Old 05-12-2018 , 06:30   Re: Announce Spray Height in Chat [converting a simple amx plugin to sourcepawn]
Reply With Quote #2

Hello again, here you can see my progress.
As you may notice the third debug message doesn't output anything, I guess it is because I fucked up the second vector trace OR the second vector trace fails instantly because the 'aim location' is in a wall (is there a possibility to filter only floor/ceiling and no walls?)

I really appreciate any help with this, thank you very much in advance.

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 = ""
};

/**
 * 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]; 
		//Tracing from the end point...
		new Handle:trace = TR_TraceRay(end, {-90.0, 0.0, 0.0}, MASK_SHOT_HULL, RayType_Infinite); 
		//...down to the floor and saving the new end point
		if(TR_DidHit(trace)) { 
			TR_GetEndPosition(vecPos, trace); 
		} 
		
		PrintToServer("vector values x: %.1f, y: %.1f, z: %.1f", vecPos[0],vecPos[1],vecPos[2]);
		
        //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;
}
Also see the compiler log
Code:
SourcePawn Compiler 1.7.1
Copyright (c) 1997-2006 ITB CompuPhase
Copyright (c) 2004-2014 AlliedModders LLC

/home/groups/sourcemod/upload_tmp/php0hbFds.sp(57) : warning 213: tag mismatch
/home/groups/sourcemod/upload_tmp/php0hbFds.sp(57) : warning 213: tag mismatch
/home/groups/sourcemod/upload_tmp/php0hbFds.sp(37) : warning 203: symbol is never used: "normal"
Code size:             3788 bytes
Data size:             2548 bytes
Stack/heap size:      16384 bytes
Total requirements:   22720 bytes

3 Warnings.
Example output
Code:
player position x: -938.6, y: -1567.9, z: 128.0
aim location x: -938.4, y: -1583.9, z: 127.3
//same wall, some steps left
player position x: -802.6, y: -1565.8, z: 128.0
aim location x: -802.3, y: -1583.9, z: 127.3
//same wall, some more steps right
player position x: -1259.9, y: -1567.9, z: 128.0
aim location x: -1259.7, y: -1583.9, z: 127.3
//other wall, same viewangle
player position x: -330.0, y: -47.9, z: 128.0
aim location x: -329.7, y: -63.9, z: 127.3
//other wall, other viewangle
player position x: 510.4, y: 115.7, z: 128.0
aim location x: 575.9, y: 116.4, z: 133.5
ketakevin is offline
ketakevin
Junior Member
Join Date: Jul 2017
Location: Berlin, Germany
Old 05-12-2018 , 09:31   Re: Announce Spray Height above the floor in Chat (vector tracing problem)
Reply With Quote #3

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;
}
ketakevin is offline
eyal282
Veteran Member
Join Date: Aug 2011
Old 05-12-2018 , 10:03   Re: Announce Spray Height above the floor in Chat (vector tracing problem)
Reply With Quote #4

Quote:
Originally Posted by ketakevin View Post
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;
}
If spray is created the moment you look at the wall ( which I think not happening in CS:GO ), just make the height by the aim origin. Also cheating is very easy by using a ladder, surfing and trampolines.
__________________
I am available to make plugins for pay.

Discord: Eyal282#1334
eyal282 is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-12-2018 , 10:11   Re: Announce Spray Height in Chat [converting a simple amx plugin to sourcepawn]
Reply With Quote #5

Quote:
Originally Posted by ketakevin View Post
Hello again, here you can see my progress.
As you may notice the third debug message doesn't output anything
This is because you have a runtime error, as your server console would tell you. TR_TraceRay does not return anything and you meant to use TR_TraceRayEx. (Alternatively, if you tried to address the compiler warnings, you might have noticed it as well.)
Fyren is offline
ketakevin
Junior Member
Join Date: Jul 2017
Location: Berlin, Germany
Old 05-12-2018 , 10:27   Re: Announce Spray Height in Chat [converting a simple amx plugin to sourcepawn]
Reply With Quote #6

Thank you for the replies, let me answer them:

Quote:
Originally Posted by Fyren View Post
This is because you have a runtime error, as your server console would tell you. TR_TraceRay does not return anything and you meant to use TR_TraceRayEx. (Alternatively, if you tried to address the compiler warnings, you might have noticed it as well.)
Yeah, I solved that by removing the 'new handle:' part and did it the same way like the first trace.

Quote:
Originally Posted by eyal282 View Post
If spray is created the moment you look at the wall ( which I think not happening in CS:GO ), just make the height by the aim origin. Also cheating is very easy by using a ladder, surfing and trampolines.
I'm developing this plugin for cs source. Cheating, if not allowed, must be prevented by the CTs, also cheating with surfing, ladder and trampolines is part of the game if you play spray high extreme for example.

Right now I just take the z coord of the aim vector and the z coord of the ground vector (where x,y is the same) and substract them to get the height relative to the floor. The plugin however seems to get the wrong height for the ground vector if you stand against the wall.

Aside from that I need to code a third trace to determine if the spray touches the ceiling (ground is easy tho because the height is 0+0,5*spraysize then)

If you want to test out my plugin feel free to visit my server at 95.216.17.188:27015 (only this plugin + sm base is running)

Last edited by ketakevin; 05-12-2018 at 10:30.
ketakevin is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-12-2018 , 10:53   Re: Announce Spray Height above the floor in Chat (vector tracing problem)
Reply With Quote #7

When you say you get the wrong height, where is your second vector hitting? It might be useful to use tempent beams to visualize your traces. If it's hitting the same wall you're starting the trace from, you could try moving the start point of your second trace slightly backwards along the line of the first trace, but it'll take a little math on your part.
Fyren is offline
ketakevin
Junior Member
Join Date: Jul 2017
Location: Berlin, Germany
Old 05-12-2018 , 11:10   Re: Announce Spray Height above the floor in Chat (vector tracing problem)
Reply With Quote #8

Quote:
Originally Posted by Fyren View Post
When you say you get the wrong height, where is your second vector hitting? It might be useful to use tempent beams to visualize your traces. If it's hitting the same wall you're starting the trace from, you could try moving the start point of your second trace slightly backwards along the line of the first trace, but it'll take a little math on your part.
+1 on that, if its working right the beam stops on the ground z=64 if I am too close to the wall its z=128 (or 120, something like that)

The idea of moving the origin is fine, maybe I should just take the x,y coords from the player to take the math easy.

Edit:
Code:
		//adding one unit in player direction to prevent the -64 units bug
		if(start[0]>end[0]) {
			end[0] = end[0] + 10;
		}else if(start[0]<end[0]){
			end[0] = end[0] - 10;
		}else if(start[1]>end[1]){
			end[1] = end[1] + 10;
		}else if(start[1]<end[1]){
			end[1] = end[1] - 10;
		}
doesnt solve it, may test some more units.

Last edited by ketakevin; 05-12-2018 at 18:01.
ketakevin is offline
ketakevin
Junior Member
Join Date: Jul 2017
Location: Berlin, Germany
Old 05-14-2018 , 14:42   Re: Announce Spray Height above the floor in Chat (vector tracing problem)
Reply With Quote #9

Some updates:

The plug-in works now, the -64 units bug persists. Also the calculation of unit height isn't linear / dependent on the viewangle. So my next question is: is there another option to get the spray position apart from tracing the aim vector?
ketakevin is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 05-14-2018 , 15:03   Re: Announce Spray Height above the floor in Chat (vector tracing problem)
Reply With Quote #10

maybe take a look here:

https://github.com/Bara/Hosties3/blo...pray_height.sp
__________________
coding & free software
shanapu 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 14:51.


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