CLEO SNIPPET Convert World Coordinates to Entity's Relative Offsets

ajom

Well-Known Member
Joined
Apr 14, 2020
Messages
71
Likes
36
Points
18
Location
Pluto
#1
This Snippet Gets the Pedestrian / Car / Object / Building / Particle XYZ Offsets That is Relative to the World XYZ Coordinates.
Code:
:worldCoordsToEntityOffsets
{
By Wesser modernized by ajom
Description: Convert world coordinates to entity's relative offsets.
Passed:     [email protected] - entity pointer     [email protected] - position X     [email protected] - position Y     [email protected] - position Z
Result:     [email protected] - relative offset X     [email protected] - relative offset Y     [email protected] - relative offset Z
Example:   0AB1: @worldCoordsToEntityOffsets 4 _entity 0x00000000 _coords_XYZ 0.0 0.0 0.0 _storeoffsets_XYZ [email protected] [email protected] [email protected]
}
[email protected] += 0x14 // CEntity.m_clPlaceable.m_pclMatrix
0A8D: [email protected] = read_memory [email protected] size 4 virtual_protect 0
0A8E: [email protected] = [email protected] + 0x30 // CMatrix.m_clOrigin
0AA5: call 0x40FE60 num_params 3 pop 3 pclVectorB [email protected] pclVectorA [email protected] pclOffset [email protected] // vectorSub
0AA5: call 0x59C810 num_params 3 pop 3 pclMatrix [email protected] pclAbsOffset [email protected] pclRelOffset [email protected] // absToRelOffset
0AB2: ret 3 offsetX [email protected] offsetY [email protected] offsetZ [email protected]

Code:
066A: [email protected] = attach_particle "PETROLCAN" to_actor [email protected] with_offset 0.0 0.116 0.048 rotation [email protected] [email protected] [email protected] type 1
0669: [email protected] = attach_particle "EXHALE" to_actor $ACTOR_RYDER with_offset [email protected] [email protected] [email protected] type 1
09A0: actor $PLAYER_ACTOR attach_object [email protected] with_offset 0.0 0.0 0.0 on_bone 5 16 perform_animation "NULL" IFP_file "NULL" time -1
08A0: actor [email protected] in_radius 100.0 near_model #NULL with_offset 0.0 0.0 0.0 end_script_named "PCUSTOM" // IF and SET
06C2: AS_actor -1 goto -1762.369 951.1278 23.7487 mode 4 turn_radius 1.0 stop_radius 1.0 actor [email protected] with_offset 0.0 0.0 0.0
070A: AS_actor [email protected] attach_to_object [email protected] offset 0.0 0.0 0.0 on_bone 6 16 perform_animation "NULL" IFP_file "NULL" time 1
069B: attach_object [email protected] to_actor [email protected] with_offset 0.0 0.5 -1.0 rotation 0.0 0.0 0.0
09B8: create_blood_gush_at $TEMPVAR_FLOAT_1 $TEMPVAR_FLOAT_2 $TEMPVAR_FLOAT_3 with_offset [email protected] [email protected] [email protected] density 20 on_actor $ACTOR_RYDER
06A7: put_actor $PLAYER_ACTOR into_turret_on_car [email protected] at_car_offset -0.2 0.5 0.0 position 1 shooting_angle 110.0 70.0 with_weapon 43
04F4: put_actor [email protected] into_turret_on_object [email protected] offset_from_object_origin 2.85 -0.7 5.9 orientation 0 both_side_angle_limit 360.0 lock_weapon 0
0464: put_actor [email protected] into_turret_on_car [email protected] at_car_offset [email protected] [email protected] [email protected] position 0 shooting_angle_limit 0.0 with_weapon 0
067C: put_camera_on_actor $PLAYER_ACTOR offset 0.0 2.0 -2.0 rotation 0.0 0.0 0.0 tilt 0.0 switchstyle 2
067E: put_camera_on_actor [email protected] offset 0.0 -5.0 4.0 target_actor [email protected] tilt 0.0 switchstyle 2
067B: put_camera_on_car $1238 with_offset -1.5 1.5 1.5 point_to_actor $1237 tilt 6.0 2
04C4: store_coords_to $TEMPVAR_FLOAT_1 $TEMPVAR_FLOAT_2 $TEMPVAR_FLOAT_3 from_actor [email protected] with_offset 1.0 3.0 1.0


I used this snippets on many single player mods that I created, thus, this snippet is almost useful on any modes even at SAMP and MTA. Some Example Applications of This Snippet:
Code:
00A0: store_actor $PLAYER_ACTOR position_to [email protected] [email protected] [email protected]
0AE2: [email protected] = random_vehicle_near_point [email protected] [email protected] [email protected] in_radius 10.0 find_next 0 pass_wrecked 1
if 056E:   car [email protected] defined
then
    if 0547:   actor $PLAYER_ACTOR colliding_with_car [email protected]
    then
        0A97: [email protected] = car [email protected] struct
        0AB1: @worldCoordsToEntityOffsets 4 _entity [email protected] _coords_XYZ [email protected] [email protected] [email protected] _storeoffsets_XYZ [email protected] [email protected] [email protected]
        0464: put_actor $PLAYER_ACTOR into_turret_on_car [email protected] at_car_offset [email protected] [email protected] [email protected] position 2 shooting_angle_limit 360.0 with_weapon 0
    end
end
 
Top