Raised This Month: $ Target: $400
 0% 

Target player closes to crosshair


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KCE
Senior Member
Join Date: Jan 2005
Location: Los Angeles, CA
Old 03-28-2005 , 20:16   Target player closes to crosshair
Reply With Quote #1

How would I get the player closes to your crosshair? i.e. in the following picture it would be the guy on the right. I need it for a rocket launcher plugin I'm making.

__________________

My 3D Art: http://k-c-e.deviantart.com/

[img]http://img213.**************/img213/7132/userbar152416mp2.gif[/img]
[img]http://img65.**************/img65/5606/userbar152433ie5.gif[/img]
[img]http://img223.**************/img223/7576/userbar152440yk6.gif[/img]
KCE is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 03-28-2005 , 22:11  
Reply With Quote #2

One method, although probably not quite what you want, is you could use get_origin with the parameter that gets the bullet hit point (I can't remember the number) and store it. Then loop through all players and get their origins. Then use some kind of bubble sort method to figure out which one is closest. However, this would get player closest to what the crosshair is aiming at (ie: the wall at the end of the map) as opposed to the position of the crosshair on the user's screen.

I don't know if it will work, I'm not sure what you plan to do.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-29-2005 , 09:50  
Reply With Quote #3

Float: get_user_aiming ( index, &id, &body, [ distance ] )

This gets what the player is aiming at. If they are aiming at an entity or a player, it returns the id of the ent into "id".

so, for example:
Code:
new tid,body; get_user_aiming(id,tid,body) if( is_user_alive(tid) { code } return;

Sorry there are no indents. Anyway, you just have to check to see if the entity thats returned is a living player, and then you have the player inside id's crosshairs ^^
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
KCE
Senior Member
Join Date: Jan 2005
Location: Los Angeles, CA
Old 03-29-2005 , 12:57  
Reply With Quote #4

Actually I figured something like this:

Get the distance of all the players in my view to me, however only the x,y coordinates
__________________

My 3D Art: http://k-c-e.deviantart.com/

[img]http://img213.**************/img213/7132/userbar152416mp2.gif[/img]
[img]http://img65.**************/img65/5606/userbar152433ie5.gif[/img]
[img]http://img223.**************/img223/7576/userbar152440yk6.gif[/img]
KCE is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-29-2005 , 14:06  
Reply With Quote #5

Thats a little excessive. get_user_aiming will get whomeever your directly looking at. I suppose you could get the angles and find out who is in your view point, but thats REALLY excessive.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 03-29-2005 , 18:35  
Reply With Quote #6

Suzuka, read the question over again. He wants to find the player closest to his crosshair, not the player directly in his crosshair.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
KCE
Senior Member
Join Date: Jan 2005
Location: Los Angeles, CA
Old 03-29-2005 , 22:36  
Reply With Quote #7

Edit: NM this code anymore.
__________________

My 3D Art: http://k-c-e.deviantart.com/

[img]http://img213.**************/img213/7132/userbar152416mp2.gif[/img]
[img]http://img65.**************/img65/5606/userbar152433ie5.gif[/img]
[img]http://img223.**************/img223/7576/userbar152440yk6.gif[/img]
KCE is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-29-2005 , 23:00  
Reply With Quote #8

Code:
    new vec[3]     new aimvec[3]     new raineffvec[3]     new length     new speed = random_num(50,300)     // Get their origin.     get_user_origin(id,vec)     // Get the origin in front of them (I think)     get_user_origin(id,aimvec,get_cvar_num("sv_weather_aim") )     raineffvec[0]=aimvec[0]-vec[0] + random_num(-500,500)     raineffvec[1]=aimvec[1]-vec[1] + random_num(-500,500)     raineffvec[2]=aimvec[2]-vec[2] + random_num(-100,100)     length=sqrt(raineffvec[0]*raineffvec[0]+raineffvec[1]*raineffvec[1]+raineffvec[2]*raineffvec[2])     raineffvec[0]=raineffvec[0]*speed/length     raineffvec[1]=raineffvec[1]*speed/length     raineffvec[2]=raineffvec[2]*speed/length

gets the origins in front of you. But I dont know how to use this to get people.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
KCE
Senior Member
Join Date: Jan 2005
Location: Los Angeles, CA
Old 03-29-2005 , 23:13  
Reply With Quote #9

I changed "get_user_origin(id,aimvec,3)" to "get_user_origin(id,aimvec,1)".

Code:
public find(id) {     new aimvec[3]     get_user_origin(id,aimvec,1)     new players[32], inum     get_players(players,inum,"a")     for(new i = 1 ;i <= inum ;i++)     {         if (is_user_connected(players[i]))         {             new Float:p_origin[3]             pev(players[i],pev_origin,p_origin)             new Float:dist             dist = floatsqroot(floatpower(float(aimvec[0]) - p_origin[0],2.0) + floatpower(float(aimvec[1]) - p_origin[1],2.0))             //calculate distance using the distance formula                         new name[32]             get_user_name(players[i],name,31)             client_print(id,print_chat,"%s - %f",name,dist)         }     } }
__________________

My 3D Art: http://k-c-e.deviantart.com/

[img]http://img213.**************/img213/7132/userbar152416mp2.gif[/img]
[img]http://img65.**************/img65/5606/userbar152433ie5.gif[/img]
[img]http://img223.**************/img223/7576/userbar152440yk6.gif[/img]
KCE is offline
Silverice146
Member
Join Date: Mar 2005
Location: In a box
Old 03-29-2005 , 23:45  
Reply With Quote #10

gj id hope to learn something from you...


still a n00b scripter with dreams bigger than my current skills allow
__________________
Silverice146 is offline
Send a message via AIM to Silverice146
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 09:58.


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