Raised This Month: $ Target: $400
 0% 

how can i check if the player's head is touching the wall


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xwantcock
Junior Member
Join Date: Nov 2022
Old 12-10-2022 , 09:07   how can i check if the player's head is touching the wall
Reply With Quote #1

title
xwantcock is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 12-10-2022 , 13:49   Re: how can i check if the player's head is touching the wall
Reply With Quote #2

hi, you can check code by Destroman, it detects when player touch wall with head or by right-left side:
Code:
#include <amxmodx>
#include <amxmisc> 
#include <hamsandwich> 
#include <fakemeta> 
#include <engine>


#define PLUGIN	"Wall touch helper"
#define VERSION	"1.0"
#define AUTHOR	"Destroman"

new iconstatus;
new const FL_ONGROUND2 = (FL_ONGROUND | FL_PARTIALGROUND | FL_INWATER |  FL_CONVEYOR | FL_FLOAT);
#define is_on_ladder(%1) (pev(%1, pev_movetype) == MOVETYPE_FLY)

new Float:wall_time;
new bool:g_touch_wall[33];
new wall_count[33];
enum _:coord_t 
{ 
	Float:xx, 
	Float:yy, 
	Float:zz 
};

#define vector_side(%0,%1,%2,%3) (%3[xx] = %0[xx] + %1 * %2[xx], %3[yy] = %0[yy] + %1 * %2[yy], %3[zz] = %0[zz] + %1 * %2[zz])

public plugin_init()
{
	register_plugin( PLUGIN, VERSION , AUTHOR);

	RegisterHam(Ham_Touch, "player", "ham_touch", false); 
	register_forward(FM_PlayerPreThink, "player_pre_think", 0);
	iconstatus = get_user_msgid("StatusIcon");
	register_clcmd("say /wt", "walltouch");
	register_clcmd("say_team /wt", "walltouch");
	register_clcmd("say /walltouch", "walltouch");
	register_clcmd("say_team /walltouch", "walltouch");
}

public client_putinserver(id)
{
	if(!is_user_bot(id))
	{
		g_touch_wall[id] = true;
		wall_count[id] = 0;
	}
}

public ham_touch(id, ent) 
{
	if(is_user_alive(id) && !is_user_bot(id))
	{
		if(g_touch_wall[id])
		{
			if(!(pev(id, pev_flags) & FL_ONGROUND2) && !is_on_ladder(id) && !(pev(id, pev_flags) & FL_DUCKING))
			{
				new Float:origin[3];
				entity_get_vector(id, EV_VEC_origin, origin);
				new Float:temp_origin[3];
				
				for(new i = 0; i < 4; i++)
				{
					temp_origin = origin;
					temp_origin[i / 2] += ((i % 2) ? -1.0 : 1.0);
					temp_origin[2] += 22;
					if(trace_hull(temp_origin, HULL_HUMAN, id, 1) && get_gametime() - wall_time > 0.05)
					{
						wall_time = get_gametime();
						take_damage(id, origin);
						wall_count[id]++;
						break;
					}
				}
			}
		}
	}
}

public player_pre_think(id)
{
	if(is_user_alive(id) && !is_user_bot(id) && g_touch_wall[id])
	{
		if((pev(id, pev_flags) & FL_ONGROUND2) && !is_on_ladder(id) && !(pev(id, pev_flags) & FL_DUCKING))
		{
			new Float:origin[3];
			entity_get_vector(id, EV_VEC_origin, origin);
			origin[2] += 44.99;
			if(!is_hull_vacant(origin, HULL_HUMAN))				
			{
				draw_warning(id);
			}
			else
			{
				hide_warning(id);
			}
		}
		else
		{
			hide_warning(id);
		}
	}
	else if(!g_touch_wall[id])
	{
		hide_warning(id);
	}
	return FMRES_IGNORED;
}		


stock draw_warning(id)
{
	message_begin(MSG_ONE_UNRELIABLE, iconstatus, _, id);
	write_byte(1);
	write_string("flash_beam");
	write_byte(255);
	write_byte(0);
	write_byte(0);
	message_end();
	return PLUGIN_HANDLED;
}

stock hide_warning(id)
{
	message_begin(MSG_ONE_UNRELIABLE, iconstatus, _, id);
	write_byte(0);
	write_string("flash_beam");
	write_byte(0);
	write_byte(90);
	write_byte(255);
	message_end();
	return PLUGIN_HANDLED;
}

public walltouch(id)
{
    if(g_touch_wall[id])
    {
		g_touch_wall[id] = false;
		client_print(id, print_chat, "Wall touch helper disabled");
    }
    else
    {
		g_touch_wall[id] = true;
		client_print(id, print_chat, "Wall touch helper enabled");
    }
    return PLUGIN_HANDLED;
}

stock take_damage(id, Float:player_origin[3])
{
	const Float:LENGTH = 64.0;
	const Float:CHECK_LENGTH = 1.0;
	
	new Float:temp_roof[3], Float:temp_forward[3], Float:temp_right[3], Float:temp_left[3];

	new Float:roof_side[3], Float:forward_side[3], Float:right_side[3], Float:left_side[3];
	
	new Float:shot_side[3];
	new Float:view_angles[3];
	
	temp_roof = player_origin;
	pev(id, pev_angles, view_angles);
	engfunc(EngFunc_MakeVectors, view_angles);
	global_get(glb_v_forward, shot_side);
	vector_side(temp_roof, LENGTH, shot_side, temp_roof);
	roof_side = player_origin;
	roof_side[2] = player_origin[2] +1.0;
	forward_side = player_origin;
	temp_forward = player_origin;
	global_get(glb_v_forward, shot_side);
	vector_side(forward_side, CHECK_LENGTH, shot_side, forward_side);
	vector_side(temp_forward, LENGTH, shot_side, temp_forward);
	right_side = player_origin;
	temp_right = player_origin;
	global_get(glb_v_right, shot_side);
	vector_side(right_side, CHECK_LENGTH, shot_side, right_side);
	vector_side(temp_right, LENGTH, shot_side, temp_right);
	left_side = player_origin;
	temp_left = player_origin;
	global_get(glb_v_right, shot_side);
	vector_side(left_side, -CHECK_LENGTH, shot_side, left_side);
	vector_side(temp_left, -LENGTH, shot_side, temp_left);
	
	if(!is_hull_vacant(roof_side, HULL_HUMAN))					
	{
		temp_roof[2] = player_origin[2] + 1.0;
		draw_damage(id, temp_roof);
	}
	else if(!is_hull_vacant(right_side, HULL_HUMAN))						
	{
		temp_right[2] = player_origin[2] + 1.0;
		draw_damage(id, temp_right);
	}
	else if(!is_hull_vacant(left_side, HULL_HUMAN))					
	{
		temp_left[2] = player_origin[2] + 1.0;		
		draw_damage(id, temp_left);
	}
	else if(!is_hull_vacant(forward_side, HULL_HUMAN))				
	{
		temp_forward[2] = player_origin[2] + 1.0;
		draw_damage(id, temp_forward);
	}
}

stock draw_damage(id, Float:origin[3])
{
	new send_origin[3];
	send_origin[0] = floatround(origin[0]);
	send_origin[1] = floatround(origin[1]);
	send_origin[2] = floatround(origin[2]);

	message_begin(MSG_ONE, get_user_msgid("Damage"), _, id);
	write_byte(1); // damage save
	write_byte(1); // damage take
	write_long(DMG_GENERIC); // example dmg - DMG_POISON
	write_coord(send_origin[0]); // x
	write_coord(send_origin[1]); // y
	write_coord(send_origin[2]); // z //must be upper
	message_end();
	if(wall_count[id] == 10 || wall_count[id] == 100 || wall_count[id] == 1000)
	{
		client_print(id, print_chat, "To disable wall touch alert type /wt or /walltouch in chat");
	}
}

stock bool:is_hull_vacant(const Float:origin[3], hull)
{
    engfunc(EngFunc_TraceHull, origin, origin, IGNORE_MONSTERS, hull, 0, 0);
    if (!get_tr2(0, TR_StartSolid) && !get_tr2(0, TR_AllSolid) && get_tr2(0, TR_InOpen))
	{
		return true;
	}
    return false;
}
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
xwantcock
Junior Member
Join Date: Nov 2022
Old 12-11-2022 , 03:46   Re: how can i check if the player's head is touching the wall
Reply With Quote #3

its worked but Is there a better method?
xwantcock is offline
JocAnis
Veteran Member
Join Date: Jun 2010
Old 12-11-2022 , 14:18   Re: how can i check if the player's head is touching the wall
Reply With Quote #4

better method in what way? its not heavy for performance at all if you mean that
__________________
KZ Public Autocup - PrimeKZ

My blog: http://primekz.xyz (in progress...) - not active (dec 2022)
JocAnis is offline
xwantcock
Junior Member
Join Date: Nov 2022
Old 12-12-2022 , 07:48   Re: how can i check if the player's head is touching the wall
Reply With Quote #5

1. Is there any code similar to the code above?

2. I don't understand exactly what the code below does

Code:
temp_origin[i / 2] += ((i % 2) ? -1.0 : 1.0);
xwantcock is offline
administratora
Member
Join Date: Mar 2015
Old 12-18-2022 , 11:03   Re: how can i check if the player's head is touching the wall
Reply With Quote #6

PHP Code:
#include <amxmodx>

public plugin_init() {
    
// Register a client command
    
register_clcmd("say /checkwall""cmdCheckWall");
}

public 
cmdCheckWall(id) {
    
// Get the player's origin and angles
    
new Float:origin[3];
    new 
Float:angles[3];
    
get_user_origin(idorigin);
    
get_user_angles(idangles);

    
// Calculate the direction the player is looking in
    
new Float:forward[3];
    
angles_to_forward(anglesforward);

    
// Trace a line from the player's head to a point in front of them
    
new result trace_line(idorigin[0], origin[1], origin[2] + 16origin[0] + forward[0] * 32origin[1] + forward[1] * 32origin[2] + forward[2] * 321id);
    if (
result) {
        
// The trace hit a solid surface
        
client_print(idprint_center"Your head is touching a wall!");
    } else {
        
// The trace did not hit a solid surface
        
client_print(idprint_center"Your head is not touching a wall.");
    }

This registers a client command /checkwall that allows the player to check if their head is touching a wall. When the command is executed, the plugin traces a line from the player's head to a point in front of them and checks if the trace hits a solid surface. If the trace hits a solid surface, it prints a message to the player indicating that their head is touching a wall. If the trace doesn't hit a solid surface, it prints a message indicating that their head is not touching a wall.
administratora 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 01:01.


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