Raised This Month: $ Target: $400
 0% 

Return wall width


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
hebusletroll
Senior Member
Join Date: Apr 2006
Old 03-30-2012 , 14:38   Return wall width
Reply With Quote #1

Hello firend !

I'll try do get a wall widht where a player is looking.

Anybody as already made a similar function ?
__________________
Boring about playing same weapons ? PowerWeapons is available !
PowerWeapon v1.0 released !
Play up to 70 new weapons and create your own weapons !
Tested on Windows Server 2003, 2008/R2, 2012 and Linux Ubuntu 10.x and CentOs 6.x
hebusletroll is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 03-30-2012 , 16:20   Re: Return wall width
Reply With Quote #2

The way I see it, this one shouldn't be very easy to do, if possible at all.
hleV is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-30-2012 , 17:36   Re: Return wall width
Reply With Quote #3

This was fun. Try this:

Code:
Float:GetAimWallWidth(id) {     // player must be alive     if(!is_user_alive(id)) {         return 0.0;     }         // grab eyes position and convert to float     new Float:eyes[3], Float:direction[3];     pev(id, pev_origin, eyes);     pev(id, pev_view_ofs, direction);     xs_vec_add(eyes, direction, eyes);         // calculate aim vector     pev(id, pev_v_angle, direction);     engfunc(EngFunc_MakeVectors, direction);     global_get(glb_v_forward, direction);         // extend aim vector farther to get the wall trace     xs_vec_mul_scalar(direction, 9999.0, direction);         // calculate end of the direction from the eyes     new Float:end[3];     xs_vec_add(eyes, direction, end);         // trace from eyes towards aim to find where player is looking     engfunc(EngFunc_TraceLine, eyes, end, IGNORE_MONSTERS, id, 0);         // grab the fraction of the trace     new Float:fraction;     get_tr2(0, TR_flFraction, fraction);         // check if trace hit something     if(fraction == 1.0) {         // trace did not hit anything         return 0.0;     }         // grab the normal vector from the trace     new Float:normal[3];     get_tr2(0, TR_vecPlaneNormal, normal);         // move normal away from the wall a bit     xs_vec_mul_scalar(normal, 10.0, normal);         // turn normal to go along the wall     angle_vector(normal, ANGLEVECTOR_RIGHT, direction);         // keep track of where we stopped at     new Float:stop[3];     get_tr2(0, TR_vecEndPos, stop);     xs_vec_add(stop, normal, stop);         // increase length of normal so traces to the wall go into it     fraction = vector_length(normal);     xs_vec_mul_scalar(normal, (fraction + 1.0) / fraction, normal);         // start moving towards the right side of the wall     new Float:right[3];     xs_vec_add(stop, direction, right);         do {         // calculate position in the wall         xs_vec_sub(right, normal, end);                 // trace to the wall         engfunc(EngFunc_TraceLine, right, end, IGNORE_MONSTERS, id, 0);                 // grab the fraction         get_tr2(0, TR_flFraction, fraction);                 // continue the loop if we hit the wall     }     while(fraction != 1.0);         // right now holds the position outside the wall         // reverse direction to go left     xs_vec_mul_scalar(direction, -1.0, direction);         // start moving towards the left side of the wall     new Float:left[3], Float:last[3];     xs_vec_copy(stop, last);         do {         // keep track of last position         xs_vec_copy(left, last);                 // increase left direction         xs_vec_add(stop, direction, left);                 // calculate position in the wall         xs_vec_sub(left, normal, end);                 // trace to the wall         engfunc(EngFunc_TraceLine, right, end, IGNORE_MONSTERS, id, 0);                 // grab the fraction         get_tr2(0, TR_flFraction, fraction);                 // continue the loop if we hit the wall     }     while(fraction != 1.0);         // calculate the distance from the right to the last known left wall side     return vector_distance(right, last); }
Exolent[jNr] is offline
hebusletroll
Senior Member
Join Date: Apr 2006
Old 03-31-2012 , 04:35   Re: Return wall width
Reply With Quote #4

Thanks Exolent[jNr] !
But i've made a mistake in my explanation,

The width is not de length of the wall but the wall's thickness" (sorry my english is worst, in french we said "épaisseur du mur").

But your posted code is very interesting for another use )

So i need to know the wall's thickness where the player is looking.

Thanks again for your help !
__________________
Boring about playing same weapons ? PowerWeapons is available !
PowerWeapon v1.0 released !
Play up to 70 new weapons and create your own weapons !
Tested on Windows Server 2003, 2008/R2, 2012 and Linux Ubuntu 10.x and CentOs 6.x
hebusletroll is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 03-31-2012 , 05:35   Re: Return wall width
Reply With Quote #5

LOL.
hleV is offline
hebusletroll
Senior Member
Join Date: Apr 2006
Old 03-31-2012 , 06:14   Re: Return wall width
Reply With Quote #6

Quote:
Originally Posted by hleV View Post
LOL.
Why "LOL" ?
__________________
Boring about playing same weapons ? PowerWeapons is available !
PowerWeapon v1.0 released !
Play up to 70 new weapons and create your own weapons !
Tested on Windows Server 2003, 2008/R2, 2012 and Linux Ubuntu 10.x and CentOs 6.x
hebusletroll is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 03-31-2012 , 08:49   Re: Return wall width
Reply With Quote #7

Because he just wrote a f*cking long code for you and you said you don't need it.
Backstabnoob is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-31-2012 , 09:40   Re: Return wall width
Reply With Quote #8

Don't know if there is a better way but you need 3 trace lines.

Code:
Float:getWallThickness( const player ) {     /* TRACELINE #1 : Player's eyes to wall. */     new Float:source[3], Float:direction[3], Float:end[3], Float:endOrig[3];     new Float:fraction;     // Get eyes position     pev( player, pev_origin, source );     pev( player, pev_view_ofs, direction );     xs_vec_add( source, direction, source );     // Get eyes direction     pev( player, pev_v_angle, direction );     engfunc( EngFunc_MakeVectors, direction );     global_get( glb_v_forward, direction );     // Get the end direction from eyes     xs_vec_mul_scalar( direction, 9999.0, direction );     xs_vec_add( source, direction, end );     engfunc( EngFunc_TraceLine, source, end, IGNORE_MONSTERS | IGNORE_GLASS, player, 0 );     // Get the fraction of the trace     get_tr2( 0, TR_flFraction, fraction );     // No hit     if( fraction == 1.0 )     {         return 0.0;     }     /* TRACELINE #2 : Inside wall to behind wall to check if there is some free space*/     // Get the end position the trace hits.     get_tr2( 0, TR_vecEndPos, end );     get_tr2( 0, TR_vecPlaneNormal, direction );     // Save this position so we can calculate the thickness later.     endOrig = end;     // Get new start position by moving inside the wall a bit.     xs_vec_mul_scalar( direction, 2.0, direction );     xs_vec_sub( end, direction, source );     // Get the end position from inside the wall to far behind.     xs_vec_mul_scalar( direction, 9999.0, direction );     xs_vec_sub( source, direction, end );     engfunc( EngFunc_TraceLine, source, end, IGNORE_MONSTERS | IGNORE_GLASS, player, 0 );     // Get the fraction of the trace     get_tr2( 0, TR_flFraction, fraction );     // No hit or no free space     if( fraction == 1.0 || get_tr2( 0, TR_AllSolid ) )     {         return 0.0;     }     /* TRACELINE #3 : From behind the wall to back inside the wall to know where the wall ends */     // The end position of the next trace is the start position of the previous trace.     // Get the end position the trace hits which is the start position of next trace.     end = source;     get_tr2( 0, TR_vecEndPos, source );     engfunc( EngFunc_TraceLine, source, end, IGNORE_MONSTERS | IGNORE_GLASS, player, 0 );     // Get the end position just behind the wall.     get_tr2( 0, TR_vecEndPos, end );     // Get the thickness of the wall.     return vector_distance( end, endOrig ); }


And here a test plugin with drawing beams :

Spoiler
__________________

Last edited by Arkshine; 03-31-2012 at 09:43.
Arkshine is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 03-31-2012 , 13:25   Re: Return wall width
Reply With Quote #9

It's unable to precache in plugin_init.

-- Edited --

Thanks for these informations, Arkshine.

Last edited by claudiuhks; 03-31-2012 at 14:22.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 03-31-2012 , 13:51   Re: Return wall width
Reply With Quote #10

You can precache in plugin_init/plugin_cfg, though you can't use precache_* natives since there is a check inside to be used only in plugin_precache forward. There is no checks in engfunc(). I would not have posted something which doesn't work and anyway, at this time, the server is just fully activated but still called before all things related to client.
__________________

Last edited by Arkshine; 03-31-2012 at 13:57. Reason: al
Arkshine 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 20:39.


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