PDA

View Full Version : Wall trace


Alka
04-30-2008, 07:48
i want to make a trace through walls and detect if use is aiming at somehting. I know i can use default trace that engine use to make damage, but is fired when i'm in +attack and doesn't go through all walls.

Maybe someone know a way?

Styles
04-30-2008, 09:25
I sorta have an idea. lll save this place for later. I have to shower right now. ill explain it.

edit: K, I have time, heres a possible way you might be able to do it.
Do a traceline. If it hits a wall, then do a traceline and do another traceline ect.. Then once your not hitting a wall. Maybe you could get the old aim vecs of the person and compare them. If its a user at the same vecs then. They are aiming through a wall.

This might work. I'll think about it though more.

VEN
04-30-2008, 12:01
You have to do multiple traces via TraceLine, no ways to do it in one step.

Alka
05-06-2008, 11:44
@styles - Don't want to make it with vec compare.
@VEN - can you show an eg, or explain how to do it?

I really need this.

VEN
05-07-2008, 14:51
Traceline: vecSource -> vecDest
While TR_flFraction != 1.0
... Traceline: TR_vecEndPos -> vecDest

Alka
05-08-2008, 06:28
Thanks, but that will trace until finds an ent...if in direction of trace doesn't exists any ent will retrace at infinite.
I've done something but will work only through one wall.

Exolent[jNr]
05-08-2008, 07:26
new Float:vStart[3], Float:vEnd[3], Float:vReturn[3];
// set start and end
fm_trace_line(index, vStart, vEnd, vReturn);
while(get_tr2(0, TR_flFraction) != 1.0 && !xs_vec_nearlyequal(vStart, vReturn))
{
xs_vec_copy(vReturn, vStart);
fm_trace_line(index, vStart, vEnd, vReturn);
}

Try that

Alka
05-08-2008, 07:57
Nope, doesn't work. Not even debug msg, and is not a mistake.

This code works but only through one wall.


#include <amxmodx>
#include <fakemeta>
#include <xs>

#define PLUGIN "New Plugin"
#define VERSION "1.0"
#define AUTHOR "Alka"

#define V_DISTANCE 9999.0
#define V_WALL 100.0

public plugin_init() {

register_plugin(PLUGIN, VERSION, AUTHOR);

register_forward(FM_PlayerPreThink, "fwdPlayerPreThink_Pre", 0);
}

public fwdPlayerPreThink_Pre(id)
{
if(!is_user_alive(id))
return FMRES_IGNORED;

static iButton, iOldButton;
iButton = pev(id, pev_button);
iOldButton = pev(id, pev_oldbuttons);

if(!(iButton & IN_ATTACK) || (iOldButton & IN_ATTACK))
return FMRES_IGNORED;

static Float:vStart[3], Float:vView_ofs[3];
pev(id, pev_origin, vStart);
pev(id, pev_view_ofs, vView_ofs);
xs_vec_add(vStart, vView_ofs, vStart);

static Float:vDest[3];
pev(id, pev_v_angle, vDest);
engfunc(EngFunc_MakeVectors, vDest);

static Float:vFwd[3];
global_get(glb_v_forward, vFwd);
xs_vec_mul_scalar(vFwd, V_DISTANCE, vDest);
xs_vec_add(vStart, vDest, vDest);

static Float:vEnd[3];
fm_trace_line(id, vStart, vDest, vEnd);

if(!xs_vec_equal(vDest, vEnd))
{
new Float:vNewstart[3], Float:vReturn[3], iHit;
xs_vec_mul_scalar(vFwd, V_WALL, vNewstart);
xs_vec_add(vEnd, vNewstart, vNewstart);

iHit = fm_trace_line(id, vNewstart, vDest, vReturn);

client_print(id, print_chat, "Hit Wall! Retrace...Found ent with index: %d", iHit);
}
return FMRES_IGNORED;
}

stock fm_trace_line(ignoreent, const Float:start[3], const Float:end[3], Float:ret[3])
{
engfunc(EngFunc_TraceLine, start, end, ignoreent == -1 ? 1 : 0, ignoreent, 0);

new ent = get_tr2(0, TR_pHit);
get_tr2(0, TR_vecEndPos, ret);

return pev_valid(ent) ? ent : 0;
}

VEN
05-08-2008, 11:10
The same thing here:#include <amxmodx>
#include <fakemeta>
#include <xs>

#define PLUGIN "New Plugin"
#define VERSION "1.0X1"
#define AUTHOR "Alka"

#define V_DISTANCE 9999.0
#define V_WALL 1.0

new Float:g_vWallSteep[3]

public plugin_init() {
register_plugin(PLUGIN, VERSION, AUTHOR);
register_forward(FM_PlayerPreThink, "fwdPlayerPreThink_Pre", 0);
}

public fwdPlayerPreThink_Pre(id)
{
if(!is_user_alive(id))
return FMRES_IGNORED;

static iButton, iOldButton;
iButton = pev(id, pev_button);
iOldButton = pev(id, pev_oldbuttons);

if(!(iButton & IN_ATTACK) || (iOldButton & IN_ATTACK))
return FMRES_IGNORED;

static Float:vStart[3], Float:vDest[3];
pev(id, pev_origin, vStart);
pev(id, pev_view_ofs, vDest);
xs_vec_add(vStart, vDest, vStart);

pev(id, pev_v_angle, vDest);
engfunc(EngFunc_MakeVectors, vDest);

global_get(glb_v_forward, vDest);
xs_vec_mul_scalar(vDest, V_WALL, g_vWallSteep);
xs_vec_mul_scalar(vDest, V_DISTANCE, vDest);
xs_vec_add(vStart, vDest, vDest);

server_print("")

new i;
while (!trace(id, vStart, vDest)) {
server_print("STEP: %d", ++i)
}

return FMRES_IGNORED;
}

bool:trace(Ent, Float:vStart[3], const Float:vDest[3]) {
engfunc(EngFunc_TraceLine, vStart, vDest, DONT_IGNORE_MONSTERS, Ent, 0);

static iHit;
if ((iHit = get_tr2(0, TR_pHit)) > 0 && pev_valid(iHit)) {
server_print("ENT: %d", iHit)
return true
}

static Float:flFraction;
get_tr2(0, TR_flFraction, flFraction);
if (flFraction == 1.0)
return true

get_tr2(0, TR_vecEndPos, vStart);
xs_vec_add(vStart, g_vWallSteep, vStart);

return false
}
Though logically this should work well. Needs a deep debug.

Alka
05-08-2008, 13:12
What can i say VEN ?! Works like a charm...but seems to work only through thin walls, and boxes...when i aim at a part of map in a direction of an ent it only make 1 step.
Thanks.

Styles
05-09-2008, 03:17
who ever game me +karma thx, leave your name. Also, yes the shower was good.