get coordinates of the players shoot at postition

Have questions about CoD4 mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

get coordinates of the players shoot at postition

Post by pcbouncer » June 26th, 2013, 10:03 am

i know there is bullettrace, but i am a bit confused on how it works. Some enlightenment would be great :)

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: get coordinates of the players shoot at postition

Post by F |Madness| U » June 26th, 2013, 11:16 am

Bullettrace doesn't actually trace players bullets. It is used to `simulate` a bullet going from one point to another.

BulletTrace( <start>, <end>, <hit characters>, <ignore entity> )

Where you choose the start and end point, and decide if you want to trace what it hits etc. It is normally used for seeing if there is any obstacles in a straight line between points A and B.

As for your problem, do you need the co-ordinates of where a player is shooting from, or the co-ordinates of where the player's bullet hits? Either way you'll need to know when a person is firing, I think the only accurate way to do this is to use menu files. Again, I can't really help with this but it's not too hard to pick up on. Once you've monitored when they're attacking (shooting), you can either get their player.origin, or, if it's the latter, you will need to call the BulletTrace on that player at this time.

It would be a bit tricky but as they fire their shot you would want to get their player.angles (to see which way they're looking) and their eyePos (since bullets come out of players heads viewpoint, not the gun - I believe there is a function for this), and then something like this:

trace = BulletTrace( eyePos, eyePos + (player.angles*100000), true, undefined );

and then use trace["position"] to return the origin of where the bullet hit.

More info on BulletTrace http://wiki.modsrepository.com/index.ph ... ulletTrace. Hope this helps.
-

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: get coordinates of the players shoot at postition

Post by megazor » June 26th, 2013, 1:18 pm

trace = BulletTrace( eyePos, eyePos + (player.angles*100000), true, undefined );
You actually need to convert angles to vector firstly with a stock function anglesToForward(angles)

pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

Re: get coordinates of the players shoot at postition

Post by pcbouncer » June 26th, 2013, 5:02 pm

what exactly does angletoforward() return?

pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

Re: get coordinates of the players shoot at postition

Post by pcbouncer » June 26th, 2013, 5:04 pm

and couldnt i just getplayerattackbuttonpressed() and attacb a trigger to the gun?

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: get coordinates of the players shoot at postition

Post by F |Madness| U » June 26th, 2013, 5:20 pm

pcbouncer wrote:and couldnt i just getplayerattackbuttonpressed() and attacb a trigger to the gun?
You could, but it would mean running an infinite loop on the player, with a delay time of 0.01 or something to be accurate. If this is on every player it may cause some server stress. It would probably still be okay, just using menu files to monitor the keys is much less stress on the server.

And yeah megazor is right, player.angles is just 3 numbers. If you use anglestoforward(player.angles) it converts these angles into a vector which runs in the direction of the player angles. This vector you would want to multiply by something like 10000 and add onto eyePos to get the end point of the bullettrace.
-

pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

Re: get coordinates of the players shoot at postition

Post by pcbouncer » June 26th, 2013, 5:23 pm

but what is exactly anglestoforward??

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: get coordinates of the players shoot at postition

Post by F |Madness| U » June 26th, 2013, 5:40 pm

pcbouncer wrote:but what is exactly anglestoforward??
A function, that returns a vector value in the direction of some given angles.
-

pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

Re: get coordinates of the players shoot at postition

Post by pcbouncer » June 26th, 2013, 5:52 pm

oh like the distances in front of you???

F |Madness| U
CJ G0D!
CJ G0D!
Posts: 1575
Joined: June 3rd, 2009, 9:02 pm
Location: Cardiff University, UK

Re: get coordinates of the players shoot at postition

Post by F |Madness| U » June 26th, 2013, 6:16 pm

Imagine you're looking exactly straight forward. (I.e. in a 3-Dimensional axis you are looking along the Z-axis, since you're not looking up/down at all nor left/right).

AnglesToForward in this case would return the vector (0,0,1). Multiply this by 10000 and you have the vector (0,0,10000). Therefore eyePos + (0,0,10000) would be the same as starting at your eyePos, and following a straight line for 10000 units along the Z axis. Resulting in the object that you are looking at, 10000 units away from you.
-

pcbouncer
CJ Fan
CJ Fan
Posts: 114
Joined: November 27th, 2012, 10:49 pm

Re: get coordinates of the players shoot at postition

Post by pcbouncer » June 26th, 2013, 6:23 pm

but you said it would return the pos where you hit

megazor
CJ Worshipper
CJ Worshipper
Posts: 414
Joined: July 22nd, 2009, 3:02 am
Location: Russia, Vladivostok

Re: get coordinates of the players shoot at postition

Post by megazor » June 27th, 2013, 1:27 am

You cannot get the hit position by modding means. You cannot get the exact moment of shooting, neither can you get the exact direction of a bullet (it will spread, you know).

With bulletTrace(), you can only get the position you're looking at. Usually, when hitting a target, you're looking at it. Also, the bullet spread angle is usually small, being about 1 degree. So, the main problem is to catch the moment of shooting.

There is a function attackButtonPressed(), however a) bullet coming out of your weapon and b) you holding your attack button are two different events. When clicking the attack button, its not necessary that your gun fires. It can be reloading, it can be out of ammo, it can be nonautomatic, like pistols (so you would have to release the button and press it again in order to fire).

As you can see, it's not enough to use this function. You will want to deal with weapon ammo count, clip ammo... Or look for another way, if it exists.

Post Reply

Who is online

Users browsing this forum: No registered users and 36 guests