CLEO Help Get position from front

CLEO related
Status
Not open for further replies.
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
Relative to what? Camera direction or the car?
You could use
C++:
0407: store_coords_to 120@ 130@ 140@ from_car 543@ with_offset -0.337 1.566 0.657
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
Relative to what? Camera direction or the car?
You could use
C++:
0407: store_coords_to 120@ 130@ 140@ from_car 543@ with_offset -0.337 1.566 0.657
I trying detect car in from and if it exist try avoid it - start auto drive around

I made this one , but working very weird , because he detect my actor and my car ...
PHP:
:CheckCarsInFront
03C0: 0@ = actor $PLAYER_ACTOR car                                                    
0407: store_coords_to 1@ 2@ 3@ from_car 0@ with_offset 0.0 0.0 0.0                                                                             
0174: 4@ = car 0@ Z_angle                                                                                             
06BE: 5@ = car 0@ y_angle                                                                                              
0AB1: @get3DXYZInFrontOf 6 XYZ 1@ 2@ 3@ Z_Angle 4@ Y_Angle 5@  Distance 9.5 Return_XYZ_To 6@ 7@ 8@
if
86BD:   is_obstacles_between 1@ 2@ 3@ and 6@ 7@ 8@ solid 1 car 1 actor 1 object 1 particle 0
then
    06D5: 29@ = create_racing_checkpoint_at 6@ 7@ 8@ point_to 6@ 7@ 8@ type 2 radius 1.0
    wait 500
    06D6: disable_racing_checkpoint 29@
end  
0AB2: ret 0

:get3DXYZInFrontOf
{ 
    Return:
        PosX-InFrontOf
        PosY-InFrontOf
        PosZ-InFrontOf
             
    Example: 0AB1: @get3DXYZInFrontOf 6 XYZ 1@ 2@ 3@ Z_Angle 4@ Y_Angle 5@ Distance 9.5 Return_XYZ_To 6@ 7@ 8@
}
3@ *= -1.0
02F6: 6@ = sine 3@
006B: 6@ *= 5@
005B: 0@ += 6@
02F7: 6@ = cosine 3@
006B: 6@ *= 5@
005B: 1@ += 6@
02F7: 6@ = cosine 4@
0073: 5@ /= 6@
02F6: 6@ = sine 4@
006B: 5@ *= 6@
005B: 2@ += 5@
0AB2: ret 3 0@ 1@ 2@
 
Last edited:
Joined
Feb 18, 2005
Messages
2,965
Reaction score
271
C++:
0407: store_coords_to 1@ 2@ 3@ from_car 0@ with_offset 0.0 0.0 0.0

You need to advance the offset, 0, 0, 0 would be the center of the car. Alternatively you could get the bumper component position.

This opcode also check my car and my actor ...
How to make ignore my actor and my car?

Try it like this;
C++:
0A97: 10@ = car 0@ struct
0A8C: write_mem 0xB7CD68 size 4 val 10@ vp 0
if
86BD:   is_obstacles_between 1@ 2@ 3@ and 6@ 7@ 8@ solid 1 car 1 actor 1 object 1 particle 0
then
      ...
end
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
So i made this code , but i don't understand couple things...
1. How to make drive around obstacles?
2. how calculate works ?
3. how i should calculate?

@Opcode.eXe
@monday
@springfield

PHP:
{$CLEO .cs}

0000: NOP

wait 8500

while true
wait 0

if
00DF:   actor $PLAYER_ACTOR driving
then                                                                                                              
    0AB1: @CheckObstaclesInFront 0 0@
    0AD1: "Obstacles Detection Status: %d" 1 0@
end

end

:CheckObstaclesInFront
30@ = 0 // Obstacles Detection Status
03C0: 0@ = actor $PLAYER_ACTOR car                                                    
0407: store_coords_to 1@ 2@ 3@ from_car 0@ with_offset 0.0 0.0 0.0                                                                             
0174: 4@ = car 0@ Z_angle                                                                                             
06BE: 5@ = car 0@ y_angle                                                                                              
0AB1: @get3DXYZInFrontOf 6 XYZ 1@ 2@ 3@ Z_Angle 4@ Y_Angle 5@  Distance 10.0 Return_XYZ_To 6@ 7@ 8@
0A97: 9@ = car 0@ struct
0A8C: write_mem 0xB7CD68 size 4 val 9@ vp 0 /// BLOCK DETECT MY CAR AND MY ACTOR 

if // Detect Vehicle
86BD:   is_obstacles_between 1@ 2@ 3@ and 6@ 7@ 8@ solid 1 car 1 actor 0 object 0 particle 0
then
    30@ = 1 // Obstacles Detection Status
    if
    0AB1: @GetClosestVehicle 1 InRadius 10.0 _Return: VehicleHandle 11@
    then
        0407: store_coords_to 16@ 17@ 18@ from_car 11@ with_offset 0.0 0.0 0.0  
        06D5: 29@ = create_racing_checkpoint_at 16@ 17@ 18@ point_to 16@ 17@ 18@ type 2 radius 1.0
        wait 100
        06D6: disable_racing_checkpoint 29@
    end
end 

if // Detect Object
86BD:   is_obstacles_between 1@ 2@ 3@ and 6@ 7@ 8@ solid 1 car 0 actor 0 object 1 particle 0
then
    30@ = 1 // Obstacles Detection Status
    0AB1: @GetClosestObject 1 InRadius 10.0 _Return: XYZ 12@ 13@ 14@ Model 15@
    06D5: 29@ = create_racing_checkpoint_at 12@ 13@ 14@ point_to 12@ 13@ 14@ type 2 radius 1.0
    wait 100
    06D6: disable_racing_checkpoint 29@
end    
0AB2: ret 1 30@

:get3DXYZInFrontOf
{ 
    Return:
        PosX-InFrontOf
        PosY-InFrontOf
        PosZ-InFrontOf
             
    Example: 0AB1: @get3DXYZInFrontOf 6 XYZ 1@ 2@ 3@ Z_Angle 4@ Y_Angle 5@ Distance 9.5 Return_XYZ_To 6@ 7@ 8@
}
3@ *= -1.0
02F6: 6@ = sine 3@
006B: 6@ *= 5@
005B: 0@ += 6@
02F7: 6@ = cosine 3@
006B: 6@ *= 5@
005B: 1@ += 6@
02F7: 6@ = cosine 4@
0073: 5@ /= 6@
02F6: 6@ = sine 4@
006B: 5@ *= 6@
005B: 2@ += 5@
0AB2: ret 3 0@ 1@ 2@

:GetClosestVehicle
0087: 20@ = 0@ // (float)
0A8D: 29@ = read_memory 0xB74494 size 4 virtual_protect 0
29@ += 0x4
0A8D: 29@ = read_memory 29@ size 4 virtual_protect 0
for 30@ = 0 to 27904 step 0x100
    0A8D: 31@ = read_memory 29@ size 1 virtual_protect 0
    000A: 29@ += 0x1
    if and
        0029: 31@ >= 0x00
        001B: 0x80 > 31@                       
    then
        005A: 31@ += 30@
        if
        00DF:   actor $PLAYER_ACTOR driving
        then
            03C0: 1@ = actor $PLAYER_ACTOR car
        else
            1@ = -1
        end
        if and
        056E:   car 31@ defined
        803B:   31@ == 1@ // not my car
        then
            if
            00DF:   actor $PLAYER_ACTOR driving
            then
                0407: store_coords_to 4@ 5@ 6@ from_car 1@ with_offset 0.0 0.0 0.0
            else
                04C4: store_coords_to 4@ 5@ 6@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
            end
            0407: store_coords_to 7@ 8@ 9@ from_car 31@ with_offset 0.0 0.0 0.0
            0509: 10@ = distance_between_XY 4@ 5@ and_XY 7@ 8@
            if
            0025:   20@ > 10@  // (float)
            then
                0087: 20@ = 10@ // (float)
                8085: 2@ = 31@ // (int)
            end
        end
    end
end
if
056E:   car 2@ defined
then
    0485:  return_true
else
    059A:  return_false
end
0AB2: ret 1 2@

:GetClosestObject
0087: 20@ = 0@ // (float)
0A8D: 29@ = read_memory 0xB7449C size 4 virtual_protect 0
000A: 29@ += 0x4
0A8D: 29@ = read_memory 29@ size 4 virtual_protect 0
for 30@ = 0 to 89344 step 0x100
    0A8D: 31@ = read_memory 29@ size 1 virtual_protect 0
    000A: 29@ += 0x1
    if and
        0029:  31@ >= 0x00 
        001B:  0x80 > 31@
    then 
        005A: 31@ += 30@     
        if and
        03CA:   object 31@ exists
        02CC:   object 31@ bounding_sphere_visible
        then     
            0400: store_coords_to 7@ 8@ 9@ from_object 31@ with_offset 0.0 0.0 0.0
            if
            00DF:   actor $PLAYER_ACTOR driving
            then
                03C0: 1@ = actor $PLAYER_ACTOR car
                0407: store_coords_to 4@ 5@ 6@ from_car 1@ with_offset 0.0 0.0 0.0
            else
                04C4: store_coords_to 4@ 5@ 6@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
            end
            0509: 10@ = distance_between_XY 4@ 5@ and_XY 7@ 8@
            if
            0025:   20@ > 10@  // (float)
            then
                0087: 20@ = 10@ // (float)
                0984: 18@ = object 31@ model
                0400: store_coords_to 12@ 13@ 14@ from_object 31@ with_offset 0.0 0.0 0.0
                0087: 15@ = 12@ // (float)
                0087: 16@ = 13@ // (float)
                0087: 17@ = 14@ // (float)
                0085: 19@ = 18@ // (int)
            end
        end
    end 
end  
0AB2: ret 4 15@ 16@ 17@ 19@
 

monday

Expert
Joined
Jun 23, 2014
Messages
1,127
Solutions
1
Reaction score
158
I don't know the right way to do this, I think it's a diffucult task considering how unpredictable it gets when you play with other human players. I did it like this:
http://ugbase.eu/index.php?threads/automowing-cs.10816/
http://pastebin.com/MabNPbNp

Btw I didn't know how to set the angle of wheels at the time so I emulated keyboard input, the vehicle data structure in sobeit doesn't specify the address for the wheels angle (it's a part of "unknown" region), but you could take a look at:
- m_fSteerAngle here: https://github.com/saml1er/gta-reversed/blob/master/source/game_sa/Entity/Vehicle/CVehicle.h
- fSteerAngle1 in the leaked samp source (_VEHICLE_TYPE inside Client/game/common.h) where you can see the offset for it (1172)

This could be useful but probably the wheel angle is changed gradually, so it may be better to just emulate keyboard input anyway...
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
Possible in this snippet add radius ?
@Opcode.eXe
@monday
etc..

PHP:
:get3DXYZInFrontOf
{   
    Return:
        PosX-InFrontOf
        PosY-InFrontOf
        PosZ-InFrontOf
               
    Example: 0AB1: @get3DXYZInFrontOf 6 XYZ 1@ 2@ 3@ Z_Angle 4@ Y_Angle 5@ Distance 9.5 Return_XYZ_To 6@ 7@ 8@
}
3@ *= -1.0
02F6: 6@ = sine 3@
006B: 6@ *= 5@
005B: 0@ += 6@
02F7: 6@ = cosine 3@
006B: 6@ *= 5@
005B: 1@ += 6@
02F7: 6@ = cosine 4@
0073: 5@ /= 6@
02F6: 6@ = sine 4@
006B: 5@ *= 6@
005B: 2@ += 5@
0AB2: ret 3 0@ 1@ 2@
 

0x_

Wtf I'm not new....
Staff member
Administrator
Joined
Feb 18, 2013
Messages
1,123
Reaction score
174
Possible in this snippet add radius ?
@Opcode.eXe
@monday
etc..

PHP:
:get3DXYZInFrontOf
{  
    Return:
        PosX-InFrontOf
        PosY-InFrontOf
        PosZ-InFrontOf
              
    Example: 0AB1: @get3DXYZInFrontOf 6 XYZ 1@ 2@ 3@ Z_Angle 4@ Y_Angle 5@ Distance 9.5 Return_XYZ_To 6@ 7@ 8@
}
3@ *= -1.0
02F6: 6@ = sine 3@
006B: 6@ *= 5@
005B: 0@ += 6@
02F7: 6@ = cosine 3@
006B: 6@ *= 5@
005B: 1@ += 6@
02F7: 6@ = cosine 4@
0073: 5@ /= 6@
02F6: 6@ = sine 4@
006B: 5@ *= 6@
005B: 2@ += 5@
0AB2: ret 3 0@ 1@ 2@
Radius? You just increase the "distance" to go more forward or decrease to get closer (- will invert it and basically puts you to the back)
 

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
I mean when i turn away from car code stop detect in from and i can't get angle Between Obstacles and my car.
Edit.:
I think i can solve it.
 
Last edited:

Parazitas

God
Staff member
Joined
Jan 2, 2017
Messages
3,315
Solutions
7
Reaction score
935
Location
Lithuania
@monday
Can explain about your snippet, how it works?
PHP:
{$CLEO .cs}

0000: NOP

wait 8500

while true
wait 0

if
00DF:   actor $PLAYER_ACTOR driving
then   
    03C0: 0@ = actor $PLAYER_ACTOR car                                                    
    0407: store_coords_to 1@ 2@ 3@ from_car 0@ with_offset 0.0 0.0 0.0                                                                                                           
    if
    0AB1: @GetClosestVehicle 1 InRadius 20.0 _Return: VehicleHandle 4@
    then
        0407: store_coords_to 5@ 6@ 7@ from_car 4@ with_offset 0.0 0.0 0.0  
        0AB1: @turning_mechanism 4 XY 1@ 2@ XY 5@ 6@ _returnedAngle 8@
        0AD1: "Angle: %f" 1337 8@
    end
end

end

:GetClosestVehicle
0087: 20@ = 0@ // (float)
0A8D: 29@ = read_memory 0xB74494 size 4 virtual_protect 0
29@ += 0x4
0A8D: 29@ = read_memory 29@ size 4 virtual_protect 0
for 30@ = 0 to 27904 step 0x100
    0A8D: 31@ = read_memory 29@ size 1 virtual_protect 0
    000A: 29@ += 0x1
    if and
        0029: 31@ >= 0x00
        001B: 0x80 > 31@                       
    then
        005A: 31@ += 30@
        if
        00DF:   actor $PLAYER_ACTOR driving
        then
            03C0: 1@ = actor $PLAYER_ACTOR car
        else
            1@ = -1
        end
        if and
        056E:   car 31@ defined
        803B:   31@ == 1@ // not my car
        02CA:   car 31@ bounding_sphere_visible
        then
            if
            00DF:   actor $PLAYER_ACTOR driving
            then
                0407: store_coords_to 4@ 5@ 6@ from_car 1@ with_offset 0.0 0.0 0.0
            else
                04C4: store_coords_to 4@ 5@ 6@ from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
            end
            0407: store_coords_to 7@ 8@ 9@ from_car 31@ with_offset 0.0 0.0 0.0
            0509: 10@ = distance_between_XY 4@ 5@ and_XY 7@ 8@
            if
            0025:   20@ > 10@  // (float)
            then
                0087: 20@ = 10@ // (float)
                8085: 2@ = 31@ // (int)
            end
        end
    end
end
if
056E:   car 2@ defined
then
    0485:  return_true
else
    059A:  return_false
end
0AB2: ret 1 2@

//0AB1: call_scm_func @turning_mechanism 4 XY XY _returnedAngle 1@
:turning_mechanism
0AB1: @getZAngleBetweenPoints 4 from_XY 0@ 1@ and_XY 2@ 3@ store_to 31@        
0172: 30@ = actor $PLAYER_ACTOR Z_angle
30@ -= 360.0
0097: make 30@ absolute_float
005B: 31@ += 30@
02F6: 30@ = sine 31@
02F7: 31@ = cosine 31@
0604: get_Z_angle_for_point 30@ 31@ store_to 31@
    if and
    0021:   31@ > 180.0
    //0023:   355.0 > 31@
    0023:   200.0 > 31@
    then //press left
    0B56: set_game_key 0 state -255 
    //0B56: set_game_key 16 state 255
        /*if
        0023:   200.0 > 31@
        then
        0B56: set_game_key 6 state 255 
        else
        0B56: set_game_key 6 state 0
        end */                          
    else
        if and
        0021:   31@ > 5.0
        //0033:   180.0 >= 31@ //lower or equal  
        0033:   155.0 >= 31@ //lower or equal
        then //press right  
        0B56: set_game_key 0 state 255
        //0B56: set_game_key 16 state 255
            /*if
            0021:   31@ > 160.0
            then
            0B56: set_game_key 6 state 255 
            else
            0B56: set_game_key 6 state 0
            end */
        else
        0B56: set_game_key 0 state 0
        //0B56: set_game_key 6 state 0
        //0B56: set_game_key 16 state 255
        end
    end 
0AB2: ret 1 31@

:getZAngleBetweenPoints
0063: 0@ -= 2@
0063: 1@ -= 3@
0604: get_Z_angle_for_point 0@ 1@ store_to 4@
0AB2: 1 4@
 
Status
Not open for further replies.
Top