AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Target player closes to crosshair (https://forums.alliedmods.net/showthread.php?t=11804)

KCE 03-28-2005 20:16

Target player closes to crosshair
 
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.

http://img.kult-mag.com/photos/00/00...00011560_2.jpg

XxAvalanchexX 03-28-2005 22:11

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.

Twilight Suzuka 03-29-2005 09:50

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 ^^

KCE 03-29-2005 12:57

Actually I figured something like this:

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

Twilight Suzuka 03-29-2005 14:06

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.

XxAvalanchexX 03-29-2005 18:35

Suzuka, read the question over again. He wants to find the player closest to his crosshair, not the player directly in his crosshair.

KCE 03-29-2005 22:36

Edit: NM this code anymore.

Twilight Suzuka 03-29-2005 23:00

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.

KCE 03-29-2005 23:13

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)         }     } }

Silverice146 03-29-2005 23:45

gj id hope to learn something from you...


still a n00b scripter with dreams bigger than my current skills allow :)


All times are GMT -4. The time now is 09:58.

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