CLEO HELP Get position from front

OP
OP
Parazitas

Parazitas

Well-Known Member
Joined
Jan 2, 2017
Messages
1,409
Likes
153
Points
78
Location
Lithuania
Website
ugbase.eu
15
#3
Relative to what? Camera direction or the car?
You could use
C++:
0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] 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: [email protected] = actor $PLAYER_ACTOR car                                                    
0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 0.0 0.0                                                                             
0174: [email protected] = car [email protected] Z_angle                                                                                             
06BE: [email protected] = car [email protected] y_angle                                                                                              
0AB1: @get3DXYZInFrontOf 6 XYZ [email protected] [email protected] [email protected] Z_Angle [email protected] Y_Angle [email protected]  Distance 9.5 Return_XYZ_To [email protected] [email protected] [email protected]
if
86BD:   is_obstacles_between [email protected] [email protected] [email protected] and [email protected] [email protected] [email protected] solid 1 car 1 actor 1 object 1 particle 0
then
    06D5: [email protected] = create_racing_checkpoint_at [email protected] [email protected] [email protected] point_to [email protected] [email protected] [email protected] type 2 radius 1.0
    wait 500
    06D6: disable_racing_checkpoint [email protected]
end  
0AB2: ret 0

:get3DXYZInFrontOf
{ 
    Return:
        PosX-InFrontOf
        PosY-InFrontOf
        PosZ-InFrontOf
             
    Example: 0AB1: @get3DXYZInFrontOf 6 XYZ [email protected] [email protected] [email protected] Z_Angle [email protected] Y_Angle [email protected] Distance 9.5 Return_XYZ_To [email protected] [email protected] [email protected]
}
[email protected] *= -1.0
02F6: [email protected] = sine [email protected]
006B: [email protected] *= [email protected]
005B: [email protected] += [email protected]
02F7: [email protected] = cosine [email protected]
006B: [email protected] *= [email protected]
005B: [email protected] += [email protected]
02F7: [email protected] = cosine [email protected]
0073: [email protected] /= [email protected]
02F6: [email protected] = sine [email protected]
006B: [email protected] *= [email protected]
005B: [email protected] += [email protected]
0AB2: ret 3 [email protected] [email protected] [email protected]
 
Last edited:

springfield

Well-Known Member
Staff member
Joined
Feb 18, 2005
Messages
2,968
Likes
76
Points
98
Website
www.ugbase.eu
10
#5
C++:
0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] 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: [email protected] = car [email protected] struct
0A8C: write_mem 0xB7CD68 size 4 val [email protected] vp 0
if
86BD:   is_obstacles_between [email protected] [email protected] [email protected] and [email protected] [email protected] [email protected] solid 1 car 1 actor 1 object 1 particle 0
then
      ...
end
 
OP
OP
Parazitas

Parazitas

Well-Known Member
Joined
Jan 2, 2017
Messages
1,409
Likes
153
Points
78
Location
Lithuania
Website
ugbase.eu
15
#6
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 [email protected]
    0AD1: "Obstacles Detection Status: %d" 1 [email protected]
end

end

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

if // Detect Vehicle
86BD:   is_obstacles_between [email protected] [email protected] [email protected] and [email protected] [email protected] [email protected] solid 1 car 1 actor 0 object 0 particle 0
then
    [email protected] = 1 // Obstacles Detection Status
    if
    0AB1: @GetClosestVehicle 1 InRadius 10.0 _Return: VehicleHandle [email protected]
    then
        0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 0.0 0.0  
        06D5: [email protected] = create_racing_checkpoint_at [email protected] [email protected] [email protected] point_to [email protected] [email protected] [email protected] type 2 radius 1.0
        wait 100
        06D6: disable_racing_checkpoint [email protected]
    end
end 

if // Detect Object
86BD:   is_obstacles_between [email protected] [email protected] [email protected] and [email protected] [email protected] [email protected] solid 1 car 0 actor 0 object 1 particle 0
then
    [email protected] = 1 // Obstacles Detection Status
    0AB1: @GetClosestObject 1 InRadius 10.0 _Return: XYZ [email protected] [email protected] [email protected] Model [email protected]
    06D5: [email protected] = create_racing_checkpoint_at [email protected] [email protected] [email protected] point_to [email protected] [email protected] [email protected] type 2 radius 1.0
    wait 100
    06D6: disable_racing_checkpoint [email protected]
end    
0AB2: ret 1 [email protected]

:get3DXYZInFrontOf
{ 
    Return:
        PosX-InFrontOf
        PosY-InFrontOf
        PosZ-InFrontOf
             
    Example: 0AB1: @get3DXYZInFrontOf 6 XYZ [email protected] [email protected] [email protected] Z_Angle [email protected] Y_Angle [email protected] Distance 9.5 Return_XYZ_To [email protected] [email protected] [email protected]
}
[email protected] *= -1.0
02F6: [email protected] = sine [email protected]
006B: [email protected] *= [email protected]
005B: [email protected] += [email protected]
02F7: [email protected] = cosine [email protected]
006B: [email protected] *= [email protected]
005B: [email protected] += [email protected]
02F7: [email protected] = cosine [email protected]
0073: [email protected] /= [email protected]
02F6: [email protected] = sine [email protected]
006B: [email protected] *= [email protected]
005B: [email protected] += [email protected]
0AB2: ret 3 [email protected] [email protected] [email protected]

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

:GetClosestObject
0087: [email protected] = [email protected] // (float)
0A8D: [email protected] = read_memory 0xB7449C size 4 virtual_protect 0
000A: [email protected] += 0x4
0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
for [email protected] = 0 to 89344 step 0x100
    0A8D: [email protected] = read_memory [email protected] size 1 virtual_protect 0
    000A: [email protected] += 0x1
    if and
        0029:  [email protected] >= 0x00 
        001B:  0x80 > [email protected]
    then 
        005A: [email protected] += [email protected]     
        if and
        03CA:   object [email protected] exists
        02CC:   object [email protected] bounding_sphere_visible
        then     
            0400: store_coords_to [email protected] [email protected] [email protected] from_object [email protected] with_offset 0.0 0.0 0.0
            if
            00DF:   actor $PLAYER_ACTOR driving
            then
                03C0: [email protected] = actor $PLAYER_ACTOR car
                0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 0.0 0.0
            else
                04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 0.0 0.0
            end
            0509: [email protected] = distance_between_XY [email protected] [email protected] and_XY [email protected] [email protected]
            if
            0025:   [email protected] > [email protected]  // (float)
            then
                0087: [email protected] = [email protected] // (float)
                0984: [email protected] = object [email protected] model
                0400: store_coords_to [email protected] [email protected] [email protected] from_object [email protected] with_offset 0.0 0.0 0.0
                0087: [email protected] = [email protected] // (float)
                0087: [email protected] = [email protected] // (float)
                0087: [email protected] = [email protected] // (float)
                0085: [email protected] = [email protected] // (int)
            end
        end
    end 
end  
0AB2: ret 4 [email protected] [email protected] [email protected] [email protected]
 

monday

Well-Known Member
Joined
Jun 23, 2014
Messages
1,036
Likes
71
Points
98
20
#7
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...
 
OP
OP
Parazitas

Parazitas

Well-Known Member
Joined
Jan 2, 2017
Messages
1,409
Likes
153
Points
78
Location
Lithuania
Website
ugbase.eu
15

0x688

Wtf I'm not new....
Staff member
Administrator
Joined
Feb 18, 2013
Messages
1,076
Likes
54
Points
98
#11
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)
 
OP
OP
Parazitas

Parazitas

Well-Known Member
Joined
Jan 2, 2017
Messages
1,409
Likes
153
Points
78
Location
Lithuania
Website
ugbase.eu
15
#12
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:
OP
OP
Parazitas

Parazitas

Well-Known Member
Joined
Jan 2, 2017
Messages
1,409
Likes
153
Points
78
Location
Lithuania
Website
ugbase.eu
15
#13
@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: [email protected] = actor $PLAYER_ACTOR car                                                    
    0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 0.0 0.0                                                                                                           
    if
    0AB1: @GetClosestVehicle 1 InRadius 20.0 _Return: VehicleHandle [email protected]
    then
        0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 0.0 0.0  
        0AB1: @turning_mechanism 4 XY [email protected] [email protected] XY [email protected] [email protected] _returnedAngle [email protected]
        0AD1: "Angle: %f" 1337 [email protected]
    end
end

end

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

//0AB1: call_scm_func @turning_mechanism 4 XY XY _returnedAngle [email protected]
:turning_mechanism
0AB1: @getZAngleBetweenPoints 4 from_XY [email protected] [email protected] and_XY [email protected] [email protected] store_to [email protected]        
0172: [email protected] = actor $PLAYER_ACTOR Z_angle
[email protected] -= 360.0
0097: make [email protected] absolute_float
005B: [email protected] += [email protected]
02F6: [email protected] = sine [email protected]
02F7: [email protected] = cosine [email protected]
0604: get_Z_angle_for_point [email protected] [email protected] store_to [email protected]
    if and
    0021:   [email protected] > 180.0
    //0023:   355.0 > [email protected]
    0023:   200.0 > [email protected]
    then //press left
    0B56: set_game_key 0 state -255 
    //0B56: set_game_key 16 state 255
        /*if
        0023:   200.0 > [email protected]
        then
        0B56: set_game_key 6 state 255 
        else
        0B56: set_game_key 6 state 0
        end */                          
    else
        if and
        0021:   [email protected] > 5.0
        //0033:   180.0 >= [email protected] //lower or equal  
        0033:   155.0 >= [email protected] //lower or equal
        then //press right  
        0B56: set_game_key 0 state 255
        //0B56: set_game_key 16 state 255
            /*if
            0021:   [email protected] > 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 [email protected]

:getZAngleBetweenPoints
0063: [email protected] -= [email protected]
0063: [email protected] -= [email protected]
0604: get_Z_angle_for_point [email protected] [email protected] store_to [email protected]
0AB2: 1 [email protected]
 
Top