CLEO Help Drawing a line without sampfuncs

CLEO related
Status
Not open for further replies.

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
270
Location
Pluto
I am trying to create a "player lines.cs" without SAMPFUNCS, it simply draw a line from your actor towards all other actors. I have read two threads that posted a snippet to be an alternative from opcode 0B68, this and this. But those two snippets seems to be inaccurate when trying to draw a point-to-point line:
Code:
// 2@ = any actor nearby
0889: store_actor 2@ center_of_body_position_to 3@ 4@ 5@
0AB1: @WorldXYZtoGameScreenXY 3 _from3Dcoord_XYZ 3@ 4@ 5@ _toscreencoord_XY 3@ 4@
0889: store_actor $PLAYER_ACTOR center_of_body_position_to 5@ 6@ 7@
0AB1: @WorldXYZtoGameScreenXY 3 _from3Dcoord_XYZ 5@ 6@ 7@ _toscreencoord_XY 5@ 6@
0AB1: @drawLine 9 _x1y1 5@ 6@ _x2y2 3@ 4@ _thickness 1.0 _Red 0 _Green 255 _Blue 0 _Alpha 255

:drawLine
//0AB1: call_scm_func drawLine 9 x1y1 0@ 1@ x2y2 2@ 3@ thickness 1.0 R 255 G 255 B 255 A 255
0509: 9@ = distance_between_XY 0@ 1@ and_XY 2@ 3@
0063: 2@ -= 0@
0063: 3@ -= 1@
0604: get_Z_angle_for_point 2@ 3@ store_to 10@
10@ += 90.0
0017: 2@ /= 2.0
0017: 3@ /= 2.0
005B: 0@ += 2@ 
005B: 1@ += 3@ 
074B: draw_texture 666 position 0@ 1@ scale 9@ 4@ angle 10@ color_RGBA 5@ 6@ 7@ 8@
0AB2: ret 0

:WorldXYZtoGameScreenXY
0AA5: call 0x70CE30 num_params 6 pop 6 bFarClip 0 bNearClip 0 pMultY 6@v pMultX 5@v pScreen 3@v pCoords 0@v // Convert WorldXYZ To WindowScreenXY

0A8D: 11@ = read_memory 0xC17044 size 4 virtual_protect 0 // full screen X
0093: 11@ = integer 11@ to_float
0A8D: 12@ = read_memory 0x859520 size 4 virtual_protect 0 // screen X scale
006B: 11@ *= 12@
0073: 3@ /= 11@

0A8D: 11@ = read_memory 0xC17048 size 4 virtual_protect 0 // full screen Y
0093: 11@ = integer 11@ to_float
0A8D: 12@ = read_memory 0x859524 size 4 virtual_protect 0 // screen Y scale
006B: 11@ *= 12@
0073: 4@ /= 11@

0AB2: ret 2 3@ 4@

That demo was part of "player lines.cs", can anybody help me fix the snippet right away? im having a hard time troubleshooting this drawline snippet.
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
I think you should try remake draw line snippet, i tested and it works perfectly only when you are
Close to ped
 

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
270
Location
Pluto
I think you should try remake draw line snippet

I did recreated the snippet, and I assured that his snippet does exactly like mine, I tested his snippet and my own version thus they create same result:
Code:
{$CLEO}
0000: test wallhack

while true
    wait 0
    03F0: enable_text_draw 1
    0A8D: 0@ = read_memory 0xB74490 size 4 virtual_protect 0
    0@ += 4
    0A8D: 0@ = read_memory 0@ size 4 virtual_protect 0
    for 1@ = 0x0 to 0x8B00 step 0x100
        0A8D: 2@ = read_memory 0@ size 1 virtual_protect 0
        0@++
        if and
            2@ >= 0x00
            2@ < 0x80
        then
            005A: 2@ += 1@ // got the ped
            if or
                856D: NOT actor 2@ defined // REMOTE ACTOR IS NOT DEFINED
                003C: $PLAYER_ACTOR == 2@ // OUR ACTOR == REMOTE ACTOR
            then continue
            end
            if 82CB: not actor 2@ bounding_sphere_visible
            then continue
            end

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Actor Line
            0889: store_actor 2@ center_of_body_position_to 3@ 4@ 5@
            0889: store_actor $PLAYER_ACTOR center_of_body_position_to 6@ 7@ 8@

            0B55: convert_3D_coords 3@ 4@ 5@ to_screen 9@ 10@
            0B55: convert_3D_coords 6@ 7@ 8@ to_screen 11@ 12@
            0B68: render draw_line_point1 9@ 10@ point2 11@ 12@ width 1 color 0xFF00FFFF

            0AB1: @WorldXYZtoGameScreenXY 3 _from3Dcoord_XYZ 3@ 4@ 5@ _toscreencoord_XY 9@ 10@
            0AB1: @WorldXYZtoGameScreenXY 3 _from3Dcoord_XYZ 6@ 7@ 8@ _toscreencoord_XY 11@ 12@
            0AB1: @drawLine 9 _x1y1 9@ 10@ _x2y2 11@ 12@ _thickness 1.0 _Red 0 _Green 255 _Blue 0 _Alpha 255
        end
    end
end

:drawLine // 0AB1: @drawLine 9 _x1y1 9@ 10@ _x2y2 11@ 12@ _thickness 1.0 _Red 0 _Green 255 _Blue 0 _Alpha 255
// mean vector x
0087: 31@ = 2@
005B: 31@ += 0@
31@ /= 2.0

// mean vector y
0087: 30@ = 3@
005B: 30@ += 1@
30@ /= 2.0

0509: 29@ = distance_between_XY 0@ 1@ and_XY 2@ 3@ // line length

// tilt angle
0063: 2@ -= 0@
0063: 3@ -= 1@
0604: get_Z_angle_for_point 2@ 3@ store_to 28@
28@ += 90.0

074B: draw_texture 666 position 31@ 30@ scale 29@ 4@ angle 28@ color_RGBA 5@ 6@ 7@ 8@
0AB2: ret 0

As you can see on the pictures, the Teal Color is the renderdraw from sampfuncs, while the green color is the snippet. The teal color is the right plotting of lines which and the green proves to have bugs because of the snippet. Any ideas what is missing on the snippet?



i tested and it works perfectly only when you are Close to ped
Does it works perfectly when its far away?
 

Attachments

  • bug2.png
    bug2.png
    787.9 KB · Views: 35
  • bug1.png
    bug1.png
    620.4 KB · Views: 35

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
270
Location
Pluto
After so many testing, I realized that Game Screen Coordinate system does not fit best when it comes to plotting lines, because the higher the resolution I have, the more pixels are compressed into one game coordinate causing the line to twirl a bit.


I decided to use Window(Pixel) Screen Coordinate System to plot a line. No more further discussion, thanks for the help.
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
After so many testing, I realized that Game Screen Coordinate system does not fit best when it comes to plotting lines, because the higher the resolution I have, the more pixels are compressed into one game coordinate causing the line to twirl a bit.


I decided to use Window(Pixel) Screen Coordinate System to plot a line. No more further discussion, thanks for the help.
I think about same since SF developers used windows coords.
@ajom

So i did test and this is what i Made:
PHP:
{$CLEO}
0000: test wallhack

while true
    wait 0
    03F0: enable_text_draw 1
    0A8D: 0@ = read_memory 0xB74490 size 4 virtual_protect 0
    0@ += 4
    0A8D: 0@ = read_memory 0@ size 4 virtual_protect 0
    for 1@ = 0x0 to 0x8B00 step 0x100
        0A8D: 2@ = read_memory 0@ size 1 virtual_protect 0
        0@++
        if and
            2@ >= 0x00
            2@ < 0x80
        then
            005A: 2@ += 1@ // got the ped
            if or
                856D: NOT actor 2@ defined // REMOTE ACTOR IS NOT DEFINED
                003C: $PLAYER_ACTOR == 2@ // OUR ACTOR == REMOTE ACTOR
            then continue
            end
            if 82CB: not actor 2@ bounding_sphere_visible
            then continue
            end

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Actor Line
            0889: store_actor 2@ center_of_body_position_to 3@ 4@ 5@
            0889: store_actor $PLAYER_ACTOR center_of_body_position_to 6@ 7@ 8@

            0B55: convert_3D_coords 3@ 4@ 5@ to_screen 9@ 10@
            0B55: convert_3D_coords 6@ 7@ 8@ to_screen 11@ 12@
            0B68: render draw_line_point1 9@ 10@ point2 11@ 12@ width 1 color 0xFF00FFFF

            0AB1: @WorldXYZtoWindowScreenXY 3 _from3Dcoord_XYZ 3@ 4@ 5@ _toscreencoord_XY 9@ 10@
            0AB1: @WorldXYZtoWindowScreenXY 3 _from3Dcoord_XYZ 6@ 7@ 8@ _toscreencoord_XY 11@ 12@
            0AB1: @drawLine 9 _x1y1 9@ 10@ _x2y2 11@ 12@ _thickness 1.0 _Red 0 _Green 255 _Blue 0 _Alpha 255
        end
    end
end

:drawLine // 0AB1: @drawLine 9 _x1y1 9@ 10@ _x2y2 11@ 12@ _thickness 1.0 _Red 0 _Green 255 _Blue 0 _Alpha 255
// mean vector x
0087: 31@ = 2@
005B: 31@ += 0@
31@ /= 4.0

// mean vector y
0087: 30@ = 3@
005B: 30@ += 1@
30@ /= 3.218

0509: 29@ = distance_between_XY 0@ 1@ and_XY 2@ 3@ // line length
29@ /= 2.0

// tilt angle
0063: 2@ -= 0@
0063: 3@ -= 1@
0604: get_Z_angle_for_point 2@ 3@ store_to 28@
28@ += 90.0

074B: draw_texture 666 position 31@ 30@ scale 29@ 4@ angle 28@ color_RGBA 5@ 6@ 7@ 8@
0AB2: ret 0

:WorldXYZtoWindowScreenXY
{
    Parameters: 0AB1: @WorldXYZtoWindowScreenXY 3 _From3Dcoord_XYZ 0@ 1@ 2@ _ToWindowScreenCoord_XY 3@ 4@
        Passed:     0@ - Position X     1@ - Position Y     2@ - Position Z
        Result:     3@ - WindowXcreen X     4@ - Windowscreen Y
    Example:   0AB1: @WorldXYZtoWindowScreenXY 3 _From3Dcoord_XYZ 2488.562 -1666.865 12.8757 _ToWindowScreenCoord_XY 3@ 4@
}
0AA5: call 0x70CE30 num_params 6 pop 6 bFarClip 0 bNearClip 0 pMultY 6@v pMultX 5@v pScreen 3@v pCoords 0@v // Convert GlobalXYZ To WindowScreenXY
0AB2: ret 2 3@ 4@
 
Last edited:

ajom

Well-known member
Joined
Apr 14, 2020
Messages
389
Solutions
2
Reaction score
270
Location
Pluto
@ajom
What you think about Y Vector?
It should 30@ /= 3.220 or maybe more?

You used your currently preffered "X Pixels per GameCoord" and "Y Pixels per GameCoord". So your Modified Snippet does not draw properly on my screen, this is what I have done so far:
Code:
{$CLEO}
0000: Player Lines

while true
    wait 0

    03F0: enable_text_draw 1
    0A8D: 0@ = read_memory 0xB74490 size 4 virtual_protect 0
    0@ += 4
    0A8D: 0@ = read_memory 0@ size 4 virtual_protect 0
    for 1@ = 0x0 to 0x8B00 step 0x100
        0A8D: 2@ = read_memory 0@ size 1 virtual_protect 0
        0@++
        if and
            2@ >= 0x00
            2@ < 0x80
        then
            005A: 2@ += 1@ // got the ped
            if or
                856D: NOT actor 2@ defined // REMOTE ACTOR IS NOT DEFINED
                003C: $PLAYER_ACTOR == 2@ // OUR ACTOR == REMOTE ACTOR
            then continue
            end
            if 82CB: not actor 2@ bounding_sphere_visible
            then continue
            end

            // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Actor Line
            0889: store_actor 2@ center_of_body_position_to 3@ 4@ 5@
            0889: store_actor $PLAYER_ACTOR center_of_body_position_to 6@ 7@ 8@
            0AB1: @DrawLinein3DWorld 11 _FromXYZ 3@ 4@ 5@ _ToXYZ 6@ 7@ 8@ _Thickness 1.0 _Red 0 _Green 255 _Blue 0 _Alpha 255

            0B55: convert_3D_coords 3@ 4@ 5@ to_screen 9@ 10@
            0B55: convert_3D_coords 6@ 7@ 8@ to_screen 11@ 12@
            0B68: render draw_line_point1 9@ 10@ point2 11@ 12@ width 1 color 0xFF00FFFF
        end
    end
end

:DrawLinein3DWorld // 0AB1: @DrawLinein3DWorld 11 _FromXYZ 0@ 1@ 2@ _ToXYZ 3@ 4@ 5@ _Thickness 6@ _Red 7@ _Green 8@ _Blue 9@ _Alpha 10@

0AA5: call 0x70CE30 num_params 6 pop 6 bFarClip 0 bNearClip 0 pMultY 14@v pMultX 13@v pScreen 28@v pCoords 0@v // Convert GlobalXYZ To WindowScreenXY
0AA5: call 0x70CE30 num_params 6 pop 6 bFarClip 0 bNearClip 0 pMultY 18@v pMultX 17@v pScreen 30@v pCoords 3@v // Convert GlobalXYZ To WindowScreenXY
// tilt angle = atan2((y2-y1)/(x1-x2))
0087: 25@ = 30@
0063: 25@ -= 28@
0087: 24@ = 31@
0063: 24@ -= 29@
0604: get_Z_angle_for_point 25@ 24@ store_to 24@
24@ += 90.0

0AB1: @WorldXYZtoGameScreenXY 3 _from3Dcoord_XYZ 0@ 1@ 2@ _toscreencoord_XY 28@ 29@
0AB1: @WorldXYZtoGameScreenXY 3 _from3Dcoord_XYZ 3@ 4@ 5@ _toscreencoord_XY 30@ 31@

// mean vector x
0087: 27@ = 30@
005B: 27@ += 28@
27@ /= 2.0

// mean vector y
0087: 26@ = 31@
005B: 26@ += 29@
26@ /= 2.0

0509: 25@ = distance_between_XY 30@ 31@ and_XY 28@ 29@ // line length

074B: draw_texture 666 position 27@ 26@ scale 25@ 6@ angle 24@ color_RGBA 7@ 8@ 9@ 10@
0AB2: ret 0

:WorldXYZtoGameScreenXY
0AA5: call 0x70CE30 num_params 6 pop 6 bFarClip 0 bNearClip 0 pMultY 6@v pMultX 5@v pScreen 3@v pCoords 0@v // Convert WorldXYZ To WindowScreenXY

0A8D: 11@ = read_memory 0xC17044 size 4 virtual_protect 0 // full screen X
0093: 11@ = integer 11@ to_float
0A8D: 12@ = read_memory 0x859520 size 4 virtual_protect 0 // screen X scale
006B: 11@ *= 12@
0073: 3@ /= 11@

0A8D: 11@ = read_memory 0xC17048 size 4 virtual_protect 0 // full screen Y
0093: 11@ = integer 11@ to_float
0A8D: 12@ = read_memory 0x859524 size 4 virtual_protect 0 // screen Y scale
006B: 11@ *= 12@
0073: 4@ /= 11@

0AB2: ret 2 3@ 4@

The Code above will not cause incompatibilities between any screen resolutions. There is only one problem remain which is the length of the line.
 

Attachments

  • Untitled.png
    Untitled.png
    747.6 KB · Views: 39
Status
Not open for further replies.
Top