[SNIPPET] DrawBar - for everything

Well, whenever you want to make a HP bar or anything else, if you want to modify its position, size or even the thickness of that black line, you must rewrite the whole script...So I made this function...The only thing you must know is that the "value" must always be 100.0 when it's max. So if you have, for exemple, a car's HP that is 750.0 (at 250.0 it ignites), you must divide it by 7.5 to become 100.0.

To call the function:

Code:
0AB1: call_scm_func @drawBar 6 coords_X 3@ coords_Y 4@ value 5@ size X 40.0 Y 4.0 thickness 2.0 // The value must be 100.0 (eg. max_HP = 750.0 ==> max_HP /= 7.5)

The function:

Code:
:drawBar
13@ = 100.0
0073: 13@ /= 3@ // (float)
0073: 2@ /= 13@ // (float)
0087: 11@ = 3@ // (float)
0087: 12@ = 4@ // (float)
005B: 11@ += 5@  // (float)
005B: 12@ += 5@  // (float)    
038E: draw_box_position 0@ 1@ size 11@ 12@ RGBA 0 0 0 255
038E: draw_box_position 0@ 1@ size 3@ 4@ RGBA 100 0 0 255
0087: 10@ = 2@ // (float)
0017: 10@ /= 2.0
0017: 3@ /= 2.0
005B: 0@ += 10@  // (float)
0063: 0@ -= 3@  // (float)
038E: draw_box_position 0@ 1@ size 2@ 4@ RGBA 255 0 0 255
0AB2: ret 0

Photo
 
Last edited:

Opcode.eXe

Expert
Joined
Feb 18, 2013
Messages
1,488
Reaction score
231
Location
( ͡° ͜ʖ ͡°)
Re: DrawBar - for everything

Finnaly better healthbars than mine which go inside  :not_bad:
cff34da5e67b908621ca88ecf9d2215a.png
 

m1zg4rd_PL

Well-known member
Joined
Jul 19, 2013
Messages
222
Reaction score
0
Re: DrawBar - for everything

How to remove that box?
 

Hidend

Expert
Joined
Mar 4, 2013
Messages
653
Reaction score
49
Re: DrawBar - for everything

Knight_Rider link said:
[quote author=Opcode.eXe link=topic=5761.msg32671#msg32671 date=1393883247]
Finnaly better healthbars than mine which go inside  :not_bad:
cff34da5e67b908621ca88ecf9d2215a.png
download link?
[/quote]
 

Kovwal

Active member
Joined
Sep 8, 2013
Messages
74
Reaction score
1
Re: DrawBar - for everything

Yeah those health bars are just some nice thing ! :D
 

chainnade

Active member
Joined
Dec 7, 2013
Messages
62
Reaction score
0
Re: DrawBar - for everything

Opcode.eXe link said:
Finnaly better healthbars than mine which go inside  :not_bad:
cff34da5e67b908621ca88ecf9d2215a.png
download link plz ? Thanks
 

J16D

Member
Joined
Jul 27, 2014
Messages
6
Reaction score
0
Re: DrawBar - for everything

really nice... ;)

I'm not sure if this will work in multiplayer, but test it;

Code:
   /*
   J16D
   */
   {$CLEO}
   0000:

   :main
   wait 0
   03F0: enable_text_draw 0
   gosub @get_Model
   gosub @get_actor
   if  03CA: object 15@ exists
   then  0108: destroy_object 15@
   end 
   jump @main
   
   //////////////sub///////////////////
   :get_Model
   if  8248:  not model 1582 available
   then
       0247: load_model 1582
       038B: load_requested_models
       while 8248:   not model 1582 available 
           wait 0
       end
   end
   0107: 15@ = create_object 1582 at 0.0 0.0 0.0
   09CA: set_object 15@ immunities BP 1 FP 1 EP 1 CP 1 MP 1
   0750: set_object 15@ visibility 0
   068E: get_camera_target_point_to 2@ 3@ 4@
   068D: get_camera_position_to 5@ 6@ 7@
   0063: 2@ -= 5@ // (float) 
   0063: 3@ -= 6@ // (float) 
   0063: 4@ -= 7@ // (float) 
   0087: 28@ = 2@ // (float) 
   0087: 29@ = 3@ // (float)
   gosub @atan 
   0509: 28@ = distance_between_XY 2@ 3@ and_XY 0.0 0.0
   0087: 29@ = 4@ // (float)
   0087: 4@ = 27@ // (float) 
   gosub @atan 
   0087: 2@ = 27@ // (float) 
   000B: 2@ += -270.0
   0013: 2@ *= -1.0
   0453: set_object 15@ XY_rotation 2@ 4@ angle 0.0
   return
   
   :atan
   0509: 27@ = distance_between_XY 28@ 29@ and_XY 0.0 0.0
   0073: 28@ /= 27@ // (float) 
   0073: 29@ /= 27@ // (float) 
   0509: 27@ = distance_between_XY 28@ 29@ and_XY 0.0 1.0
   for 16@ = 0 to 11
      0017: 27@ /= 2.0 
      006B: 27@ *= 27@ // (float) 
      0087: 29@ = 27@ // (float)                     
      0013: 27@ *= -1.0 
      000B: 27@ += 1.0
      01FB: 27@ = square_root 27@ 
      0013: 27@ *= -1.0 
      000B: 27@ += 1.0
      006B: 27@ *= 27@ // (float) 
      005B: 27@ += 29@ // (float) 
      01FB: 27@ = square_root 27@ 
   end                                                      
   0013: 27@ *= 4096.0 
   0017: 27@ /= 3.141592 
   0013: 27@ *= 180.0 
   if  0021:   28@ > 0.0 
   then
      0013: 27@ *= -1.0 
      000B: 27@ += 360.0
   end
   return
   
   :get_actor
   0A8D: 27@ = read_memory 0xB74490 size 4 virtual_protect 0
   000A: 27@ += 0x4
   0A8D: 27@ = read_memory 27@ size 4 virtual_protect 0
   for 28@ = 0 to 35584 step 0x100
       0A8D: 26@ = read_memory 27@ size 1 virtual_protect 0
       000A: 27@ += 0x1
       if and
       0029:   26@ >= 0x00 
       001B:   0x80 > 26@
       then 
           005A: 26@ += 28@ // (int)
           0889: store_actor $PLAYER_ACTOR enter_of_body_position_to 5@ 6@ 7@
           0889: store_actor 26@ enter_of_body_position_to 2@ 3@ 4@
           050A: 0@ = distance_between_XYZ 5@ 6@ 7@ and_XYZ 2@ 3@ 4@
           068D: get_camera_position_to 5@ 6@ 7@      
           if and
           255.0 > 0@
           8118:  not actor 26@ dead
           06BD:  no_obstacles_between 5@ 6@ 7@ and 2@ 3@ 4@ solid 1 car 0 actor 0 object 0 particle 0
           803C:   not  $PLAYER_ACTOR == 26@ // (int)
           then
               4@ += 1.0
               gosub @getGamen
   //----------------size------------------------
               0087: 2@ = 0@ // (float)
               0@ = 10.0
               0073: 0@ /= 2@ // (float)
               0087: 2@ = 0@ // (float)            
               2@ *= 0.5
               if
               0@ > 2.0
               then
                   0@ = 2.0
                   2@ = 1.0
               end
               if
               0.5 > 0@
               then
                   0@ = 0.5
                   2@ = 0.25
               end
   //-----------------color--------------------
               gosub @ped_health
           end
       end 
   end
   return
   
   :getGamen
   068D: get_camera_position_to 5@ 6@ 7@
   0063: 5@ -= 2@ // (float) 
   0063: 6@ -= 3@ // (float) 
   0063: 7@ -= 4@ // (float)
   0013: 5@ *= -1.0
   0013: 6@ *= -1.0
   0400: store_coords_to 5@ 6@ 7@ from_object 15@ with_offset 5@ 7@ 6@
   0073: 5@ /= 7@ // (float) 
   0073: 6@ /= 7@ // (float) 
   0801: get_camera_zoom_factor_to 4@ // float 
   0017: 4@ /= 2.0 
   02F7: 2@ = sine 4@ // (float) 
   02F6: 3@ = cosine 4@ // (float) 
   0073: 2@ /= 3@ // (float) 
   006B: 5@ *= 2@ // (float) 
   006B: 6@ *= 2@ // (float) 
   0013: 5@ *= 324.0
   0013: 6@ *= 304.0
   if  0023: 0.0 > 7@ 
   then
       0007: 5@ = 640.0 
       0007: 6@ = 480.0 
   end
   000B: 5@ += 320.0 
   000B: 6@ += 223.0
   return
   
   :ped_health
   03F0: enable_text_draw 1
   0A96: 12@ = actor 26@ struct
   000A: 12@ += 0x540
   0A8D: 13@ = read_memory 12@ size 4 virtual_protect 0 //now_health
   000A: 12@ += 0x4
   0A8D: 14@ = read_memory 12@ size 4 virtual_protect 0 //max_health
   0073: 13@ /= 14@ // (float)
   0@ *= 20.0
   2@ *= 5.0
   038E: draw_box position 5@ 6@ size 0@ 2@ RGBA 255 255 255 40 
   
   0087: 1@ = 0@ // (float)
   006B: 1@ *= 13@ // (float)
   0063: 0@ -= 1@ // (float)
   0@ *= 0.5
   0063: 5@ -= 0@ // (float)
   038E: draw_box position 5@ 6@ size 1@ 2@ RGBA 255 0 0 120 
   return

study the code ;)
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
Re: DrawBar - for everything

Hi, can someone help me to understand how to use this snippet properly? I'm having problems with it and after 1 or 2 hours i'm like
i-have-no-idea-what-im-doing-dog.jpg


I tried to use the code below to display my HP but the bar partially appears flashing on the top left of my screen and doesn't change when my HP decrease.

Code:
{$CLEO .cs}

0000: NOP

:Main
wait 0
if
0256:   player $PLAYER_ACTOR defined
jf @Main
0226: 5@ = actor $PLAYER_ACTOR health
00A0: store_actor $PLAYER_ACTOR position_to 21@ 22@ 23@
0B55: convert_3D_coords 21@ Y 22@ Z 23@ to_screen 3@ 4@
03F0: enable_text_draw 1
0AB1: call_scm_func @drawBar 6 coords_X 3@ coords_Y 4@ value 5@ size X 40.0 Y 4.0 thickness 2.0 // The value must be 100.0 (eg. max_HP = 750.0 ==> max_HP /= 7.5) 
jump @Main

:drawBar
wait 0
13@ = 100.0
0073: 13@ /= 3@ // (float)
0073: 2@ /= 13@ // (float)
0087: 11@ = 3@ // (float)
0087: 12@ = 4@ // (float) 
005B: 11@ += 5@  // (float)
005B: 12@ += 5@  // (float)     
038E: draw_box_position 0@ 1@ size 11@ 12@ RGBA 0 0 0 255
038E: draw_box_position 0@ 1@ size 3@ 4@ RGBA 100 0 0 255
0087: 10@ = 2@ // (float)
0017: 10@ /= 2.0
0017: 3@ /= 2.0
005B: 0@ += 10@  // (float)
0063: 0@ -= 3@  // (float)
038E: draw_box_position 0@ 1@ size 2@ 5.0 RGBA 255 0 0 255
0AB2: ret 0
 

PopandaulX

Active member
Joined
Jul 15, 2013
Messages
189
Reaction score
1
Re: DrawBar - for everything

monday link said:
Hi, can someone help me to understand how to use this snippet properly? I'm having problems with it and after 1 or 2 hours i'm like
i-have-no-idea-what-im-doing-dog.jpg


I tried to use the code below to display my HP but the bar partially appears flashing on the top left of my screen and doesn't change when my HP decrease.

Code:
{$CLEO .cs}

0000: NOP

:Main
wait 0
if
0256:   player $PLAYER_ACTOR defined
jf @Main
0226: 5@ = actor $PLAYER_ACTOR health
00A0: store_actor $PLAYER_ACTOR position_to 21@ 22@ 23@
0B55: convert_3D_coords 21@ Y 22@ Z 23@ to_screen 3@ 4@
03F0: enable_text_draw 1
0AB1: call_scm_func @drawBar 6 coords_X 3@ coords_Y 4@ value 5@ size X 40.0 Y 4.0 thickness 2.0 // The value must be 100.0 (eg. max_HP = 750.0 ==> max_HP /= 7.5) 
jump @Main

:drawBar
wait 0
13@ = 100.0
0073: 13@ /= 3@ // (float)
0073: 2@ /= 13@ // (float)
0087: 11@ = 3@ // (float)
0087: 12@ = 4@ // (float) 
005B: 11@ += 5@  // (float)
005B: 12@ += 5@  // (float)     
038E: draw_box_position 0@ 1@ size 11@ 12@ RGBA 0 0 0 255
038E: draw_box_position 0@ 1@ size 3@ 4@ RGBA 100 0 0 255
0087: 10@ = 2@ // (float)
0017: 10@ /= 2.0
0017: 3@ /= 2.0
005B: 0@ += 10@  // (float)
0063: 0@ -= 3@  // (float)
038E: draw_box_position 0@ 1@ size 2@ 5.0 RGBA 255 0 0 255
0AB2: ret 0
Hmm....Try 0093: 5@ = integer 5@ to_float before using the function.

EDIT: Yep, that's your problem.
Tested:
Code:
{$CLEO .cs}
0000: NOP
0662: "PopandauL"

wait 0
03F0: enable_text_draw 1

while true
wait 0
    if
    0256:   player $PLAYER_ACTOR defined
    then
        if and
        8118:   actor $PLAYER_ACTOR dead
        02CB:   actor $PLAYER_ACTOR bounding_sphere_visible
        then
        00A0: store_actor $PLAYER_ACTOR position_to 0@ 1@ 2@
        0AB1: call_scm_func @getScreenXYFrom3DCoords 3 3D_coords_X 0@ Y 1@ Z 2@ store_screen_X_to 3@ Y_to 4@
        5@ = Actor.Health($PLAYER_ACTOR)
        0093: 5@ = integer 5@ to_float
        0AB1: call_scm_func @drawBar 6 coords_X 3@ coords_Y 4@ value 5@ size X 40.0 Y 4.0 thickness 2.0
        end
    end
end

:getScreenXYFrom3DCoords
0AC7: 14@ = var 0@ offset
0AC7: 15@ = var 3@ offset
0AC7: 16@ = var 6@ offset
0AC7: 17@ = var 9@ offset
0AA5: call 0x70CE30 num_params 6 pop 6 {18@ 18@} 0 0 17@ 16@ 15@ 14@
0007: 12@ = 640.0
0007: 13@ = 448.0
0A8D: 14@ = read_memory 0xC17044 size 4 virtual_protect 0
0A8D: 15@ = read_memory 0xC17048 size 4 virtual_protect 0
0093: 14@ = integer 14@ to_float
0093: 15@ = integer 15@ to_float
0073: 12@ /= 14@
0073: 13@ /= 15@
006B: 3@ *= 12@
006B: 4@ *= 13@
0AB2: ret 2 3@ 4@

:drawBar
13@ = 100.0
0073: 13@ /= 3@ // (float)
0073: 2@ /= 13@ // (float)
0087: 11@ = 3@ // (float)
0087: 12@ = 4@ // (float) 
005B: 11@ += 5@  // (float)
005B: 12@ += 5@  // (float)     
038E: draw_box_position 0@ 1@ size 11@ 12@ RGBA 0 0 0 255
038E: draw_box_position 0@ 1@ size 3@ 4@ RGBA 100 0 0 255
0087: 10@ = 2@ // (float)
0017: 10@ /= 2.0
0017: 3@ /= 2.0
005B: 0@ += 10@  // (float)
0063: 0@ -= 3@  // (float)
038E: draw_box_position 0@ 1@ size 2@ 4@ RGBA 255 0 0 255
0AB2: ret 0

Image:
aQaIqHV.png
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
Re: DrawBar - for everything

Thank you it works:)
 
Top