[SNIPPET] Perfect crosshair pos

Originally posted\made by this sweetie -> @0x688 http://ugbase.eu/Thread-Perfect-crosshair-pos?pid=98743
Output parameters are float
Usage : call @crosshair_coords 0 x_out 0@ y_out 1@

[shcode=cpp]
:crosshair_coords
0A8D: 23@ = read_memory 0xC9C040 size 4 virtual_protect 0 //x screen
0A8D: 24@ = read_memory 0xC9C044 size 4 virtual_protect 0 //y screen
0A8D: 25@ = read_memory 0xB6EC14 size 4 virtual_protect 0 
0A8D: 26@ = read_memory 0xB6EC10 size 4 virtual_protect 0 
0093: 22@ = integer 23@ to_float@
006F: 22@ *= 25@
0093: 29@ = integer 23@ to_float
29@ *= 0.0015625
29@ *= 64.0
29@ *= 0.2                            
29@ *= 0.1
0063: 22@ -= 29@  // (float)
///////
0093: 10@ = integer 24@ to_float
006F: 10@ *= 26@
0093: 11@ = integer 24@ to_float
11@ *= 0.002232143
11@ *= 64.0
11@ *= 0.2                            
11@ *= 0.1
0063: 10@ -= 11@  // (float)
ret 2 22@ 10@
[/shcode]
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
This should work too, but less code and gets right position for sniper also. I don't know why but the one you posted doesn't work for me using a simple script.

[shcode=cpp]
:get_xhair_pos
0A8D: 0@ = readMem 0xC9C040 sz 4 vp 0 //x screen
0A8D: 1@ = readMem 0xC9C044 sz 4 vp 0 //y screen
if 02D8: actor $PLAYER_ACTOR current_weapon == 34
then 0@ *= 0.5
   1@ *= 0.5
else 0@ *= 0.53
   1@ *= 0.4
end
ret 2 0@ 1@
[/shcode]

Script that doesn't work with first function.
[shcode=cpp]
while true
   wait 0
   call @crosshair_coords 0 0@ 1@
   0B69: render draw_box_pos 0@ 1@ size 5 5 color 0xFFC0FF01
end
[/shcode]
 
Joined
Dec 31, 2015
Messages
712
Reaction score
27
springfield said:
Script that doesn't work with first function.
[shcode=cpp]
while true
   wait 0
   call @crosshair_coords 0 0@ 1@
   0B69: render draw_box_pos 0@ 1@ size 5 5 color 0xFFC0FF01
end
[/shcode]

Guess it is because 0B69's input parameters are Integer, while this snippet returns float
So there's actually no benefits in calculating it with float to get better accuracy? To draw your txd crosshair for example
If not, then delete this thread please, thought it might be useful if someone asked to convert it
 
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
supahdupahnubah said:
Guess it is because 0B69's input parameters are Integer, while this snippet returns float

Yep, works fine when converting to int. Add that to the main post, i would've never though of that.
 

0x32789

Expert
Joined
May 26, 2014
Messages
849
Reaction score
51
Location
LongForgotten <-> 0x32789
so, convertScreenXYto3DCoords will work with this? I mean if I use it for example, convert the screen XY to 3D Game coordinates, and check if the position is the position of a player, will it trigger?
it seems very useful
 

WaTTi

Well-known member
Joined
Jan 4, 2015
Messages
260
Reaction score
8
don't working.
hQ324Ne.png
 

Zin

Expert
Joined
Aug 1, 2013
Messages
1,697
Reaction score
105
springfield said:
This should work too, but less code and gets right position for sniper also. I don't know why but the one you posted doesn't work for me using a simple script.

[shcode=cpp]
:get_xhair_pos
0A8D: 0@ = readMem 0xC9C040 sz 4 vp 0 //x screen
0A8D: 1@ = readMem 0xC9C044 sz 4 vp 0 //y screen
if 02D8: actor $PLAYER_ACTOR current_weapon == 34
then 0@ *= 0.5
   1@ *= 0.5
else 0@ *= 0.53
   1@ *= 0.4
end
ret 2 0@ 1@
[/shcode]

Script that doesn't work with first function.
[shcode=cpp]
while true
   wait 0
   call @crosshair_coords 0 0@ 1@
   0B69: render draw_box_pos 0@ 1@ size 5 5 color 0xFFC0FF01
end
[/shcode]
I used it to draw a texture but the the texture just appears in the corner of the screen and not where the crosshair usually is.
 
Top