Raised This Month: $51 Target: $400
 12% 

Trace Ray Assistance (Yeah, from me, lol)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ferret
SourceMod Developer
Join Date: Dec 2004
Location: Atlanta, GA
Old 12-18-2007 , 10:55   Trace Ray Assistance (Yeah, from me, lol)
Reply With Quote #1

I haven't needed to use a trace ray before now, so anyone who can help me, please do so

I basicly want to find all players within x radius of a target player. The list of players found will be used to kill them as part of an "explosion", so it should exclude people behind walls, etc.

Thanks
__________________
I'm a blast from the past!
ferret is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 12-18-2007 , 11:36   Re: Trace Ray Assistance (Yeah, from me, lol)
Reply With Quote #2

I'm not sure if you really need a Trace Ray for that, couldn't you just loop trough all players and calculate their vector distance ?
Edit: Nvm, I didn't read the last part of your post. Well, I first would calculate the vector distances of all players and then do that Traceray thing.

That's a function of the Tracespray plugin, maybe it helps ;)

Quote:
stock GetPlayerEye(client, Float:pos[3]){
new Float:vAngles[3], Float:vOrigin[3];
GetClientEyePosition(client,vOrigin);
GetClientEyeAngles(client, vAngles);

new Handle:trace = TR_TraceRayFilterEx(vOrigin, vAngles, MASK_SHOT, RayType_Infinite, TraceEntityFilterPlayer);

if(TR_DidHit(trace)){
//This is the first function i ever sow that anything comes before the handle
TR_GetEndPosition(pos, trace);
if(GetVectorDistance(pos, vOrigin) <= 128.0)
return 2;
return 1;
}
return 0;
}

Last edited by berni; 12-18-2007 at 11:43.
berni is offline
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 12-18-2007 , 12:00   Re: Trace Ray Assistance (Yeah, from me, lol)
Reply With Quote #3

Helloes

DISCLAIMER: I have never done SourceMod scripting

What you are trying to accomplish might be something like this:
1) You have the origin of the target player, the center of the explosion

2) Loop through all players (skip the target player to avoid division by zero =P )

2.1) for each player: calculate the distance: get his origin, subtract the two vectors, compute VectorLength (either through a native or by using good old pythagoras)

2.2) if that distance is <= MAXRADIUS, the player is potentially in your explosion radius. If the distance is greater, skip this player as he is unaffected

2.3) Now the trace ray would be used - basically only in order to find out whether there is a wall between the explosion center point and the currently examined player. The start position of the trace ray would be the explosion center point, the direction vector would be (current loop player origin - explosion center point) (you might need to normalise this vector or you might not, I don't know). It can be an infinite trace because you're going to hit the player in that diretion anyway. With the mask flags you can decide what makes the trace stop and what is ignored. You might also need to set up a filter function and filter out the target player if the trace hits him. Then if TR_GetEntityIndex returns the index of the player's entity which is in the current loop, the trace didn't hit anything else in between, so there was no wall and you can safely let the player explode.

You could also make the damage done depend on the distance.
The easiest way would be a linear relation: damage = MAX_DAMAGE * (MAX_RADIUS - distance) / MAX_RADIUS

edit: pseudo code added:
Code:
new g_FilteredEntity = -1;

public bool:MyTraceFilter(ent, contentMask)
{
   return (ent == g_FilteredEntity) ? false : true;
}

// variable center_point: the target player's origin
g_FilteredEntity = target_player_id;  // player id == entity index!?

 for (loop through all players)
{
   // variable cur_player_id is the current eximaned player's id
   // variable cur_player_pos is his origin

  distance = GetVectorDistance(cur_player_pos, center_point);
  if (distance < MAX_RADIUS)
  {
    // he is in the radius - is there something between the explosion center and the player?

    new Float:trace_dir[3];

    SubtractVectors(cur_player_pos, center_point, trace_dir);
    TR_TraceRayFilter(center_point, trace_dir, RayType_Infinite, MASK_SOLID, MyFilterFunction);
    if (TR_GetEntityIndex() == cur_player_id)  // player id == entity index!?
    {
      // HE SHALL EXPLODE (nothing else was in between)
    }
  }
}
edit2: ohnoes my words said something different than the code. The filter function's purpose is to make sure that the trace doesn't hit the target player - the one where the trace begins, as it MIGHT hit his own hitbox and thus not go too far. I corrected the g_FilteredEntity variable now. Note that this is probably not needed for MASK_SOLID as player hitboxes are not included in that. See the sdktools_trace api reference.
__________________
hello, i am pm

Last edited by PM; 12-18-2007 at 12:21.
PM is offline
ferret
SourceMod Developer
Join Date: Dec 2004
Location: Atlanta, GA
Old 12-18-2007 , 12:02   Re: Trace Ray Assistance (Yeah, from me, lol)
Reply With Quote #4

I love when you get involved PM.
__________________
I'm a blast from the past!
ferret is offline
ferret
SourceMod Developer
Join Date: Dec 2004
Location: Atlanta, GA
Old 12-18-2007 , 12:25   Re: Trace Ray Assistance (Yeah, from me, lol)
Reply With Quote #5

I'm going to try the following, as I want a gaurenteed kill within "half radius"

Code:
     new damage = 100;
     radius = MAX_RADIUS / 2;
     if (distance > radius)
     {
      distance -= radius;
      damage = damage * (radius - distance) / radius;
     }
 
     SlapPlayer(target, damage, false);
__________________
I'm a blast from the past!
ferret 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 07:15.


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