Quantcast

Jump to content

» «
Photo

[SA] Find point coords based on y-axis offset distance before collisio

4 replies to this topic
jackusCTB
  • jackusCTB

    Peon

  • Members
  • Joined: 29 Jun 2012
  • Belgium

#1

Posted 08 December 2013 - 12:40 PM Edited by jackusCTB, 08 December 2013 - 12:41 PM.

Hello, in these days I tried to write a function which find a point coords which is parallel to another point on the y-axis as soon as it collides with something (Tried using 86BD). Yes, it sounds difficult to understand, so a picture is worth a thousand words:

e57540293667435.jpg 

As you may see, if I know the world coords of the center of the plane, I would like to get the coords of the point which collides with something (in the picture case, the point near the railway, near the "y"), so I used 0407 to store the plane position, then I reused 0407 with 1.0 as y offset and the increment the y var by 1.0 until there's an obstacle between plane (x,y,z) and point (x,y,z)

 

That's the script I wrote. Looks like it has an infinite loop within the "until... repeat" construct, in fact, the new point y var always increase by 1.0, forever...

{$CLEO}

0000: NOP

0007: 7@ = 5.1 //4242.640687

while true
wait 0
if and
Player.Defined($PLAYER_CHAR)
Actor.DrivingVehicleType($PLAYER_ACTOR, #HYDRA)
    then
    03C0: 0@ = actor $PLAYER_ACTOR car
    if
    Car.Defined(0@)
    then
    0407: store_coords_to 1@ 2@ 3@ from_car 0@ with_offset 0.0 5.0 0.0 //00AA: store_car 0@ position_to 1@ 2@ 3@
    0407: store_coords_to 4@ 5@ 6@ from_car 0@ with_offset 0.0 7@ 0.0
      repeat
      wait 0
      000B: 7@ += 1.0
      until 86BD:   not no_obstacles_between 1@ 2@ 3@ and 4@ 5@ 6@ solid 1 car 1 actor 1 object 1 particle 0
    050A: 8@ = distance_between_XYZ 1@ 2@ 3@ and_XYZ 4@ 5@ 6@
    //---DEBUG TEST
    0092: 9@ = float 8@ to_integer
    03F0: enable_text_draw 1
    045A: draw_text_1number 10.0 10.0 GXT 'NUMBER' number 9@
    else
    Car.RemoveReferences(0@)
    end
end
end
    
     
    

I really appreciate your help, time or simply the interest!


Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Feroci
  • Joined: 19 Aug 2006
  • Unknown

#2

Posted 08 December 2013 - 01:39 PM Edited by Wesser, 08 December 2013 - 01:46 PM.

Yours is one of the most frequently asked questions. You should have done a search before posting. Try to adapt this code snippet (untested):
const
    ORIGIN_X = 0.0
    ORIGIN_Y = 0.0
    ORIGIN_Z = 0.0
    TARGET_X = 1.0
    TARGET_Y = 1.0
    TARGET_Z = 1.0
end
0A9F: 0@ = current_thread_pointer
0A8E: 1@ = 0@ + 0x54 // 6@, 7@, 8@
0A8E: 2@ = 0@ + 0x60 // 9@, 10@, 11@
0A8E: 3@ = 0@ + 0x6C // 12@, 13@, 14@
0A8E: 4@ = 0@ + 0x78 // 15@
6@ = ORIGIN_X
7@ = ORIGIN_Y
8@ = ORIGIN_Z
9@ = TARGET_X
10@ = TARGET_Y
11@ = TARGET_Z
0AA7: call_function 0x0056BA00 num_params 12 pop 12 bIgnoreShootThroughStuff false bIgnoreSomeObjectsForCamera false bIgnoreSeeThroughStuff false bParticle false bObject true bPed true bVehicle true bBuilding true pclEntity 4@ pclPoint 3@ pstTarget 2@ pstOrigin 1@ bReturn 5@ // processLineOfSight
if
    5@ == true
then
    // The collision point coordinates will be stored into 12@, 13@ and 14@.
    // The collision entity will be handled by 15@.
end

jackusCTB
  • jackusCTB

    Peon

  • Members
  • Joined: 29 Jun 2012
  • Belgium

#3

Posted 08 December 2013 - 03:13 PM

I tried to adapt your code to my script.

The script basically create an explosion at the collision x, y, z coordinates but unfortunately it crash as soon as I press the activation key (T):

{$CLEO}

0000: NOP

while true
wait 0
  if and
    Player.Defined($PLAYER_CHAR)
    Actor.DrivingVehicleType($PLAYER_ACTOR, #HYDRA)
    0AB0: key_pressed 0x54  // T
  then
    03C0: 16@ = actor $PLAYER_ACTOR car
    0407: store_coords_to 6@ 7@ 8@ from_car 16@ with_offset 0.0 5.0 0.0
    0407: store_coords_to 9@ 10@ 11@ from_car 16@ with_offset 0.0 505.0 0.0
    0AB1: call_scm_func @getCollisionPointCoords 6 origin_x 6@ origin_y 7@ origin_z 8@ target_x 9@ target_y 10@ target_z 11@ get_xyz_coll_point_to 12@ 13@ 14@
    if 
      5@ == true
    then
      020C: create_explosion_with_radius 0 at 12@ 13@ 14@
    end
  end
end

:getCollisionPointCoords
  0A9F: 0@ = current_thread_pointer
  0A8E: 1@ = 0@ + 0x54 // 6@, 7@, 8@
  0A8E: 2@ = 0@ + 0x60 // 9@, 10@, 11@
  0A8E: 3@ = 0@ + 0x6C // 12@, 13@, 14@
  0A8E: 4@ = 0@ + 0x78 // 15@
  0AA7: call_function 0x0056BA00 num_params 12 pop 12 bIgnoreShootThroughStuff false bIgnoreSomeObjectsForCamera false bIgnoreSeeThroughStuff false bParticle false bObject true bPed true bVehicle true bBuilding true pclEntity 4@ pclPoint 3@ pstTarget 2@ pstOrigin 1@ bReturn 5@ // processLineOfSight
  0AB2: ret 4 5@ 12@ 13@ 14@

DK22Pac
  • DK22Pac

    Where I Know You From

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine

#4

Posted 08 December 2013 - 03:31 PM

@Wesser you need to reserve 11 variables (44b) for pclPoint param.

Wesser
  • Wesser

    The complexity simplifier, the efficiency optimizer.

  • Feroci
  • Joined: 19 Aug 2006
  • Unknown

#5

Posted 08 December 2013 - 03:33 PM Edited by Wesser, 08 December 2013 - 04:08 PM.

0AB1 behaves very similar to 004F command, that is it allows an undefined amount of arguments whose value gets stored into each local variable of the calling script within the interval 0-32 (timers may be included). These variables shouldn't be overwritten immediately into the SCM function without availing of them at least once, because they are input arguments and so it wouldn't make much sense. Moreover, pay attention on how many values you return which must be equal to those passed at 0AB1 command (they are put after all input arguments). Edit your script as shown below (untested):
if
0AB1: call_scm_func @getCollisionPointCoords 6 origin_x 6@ origin_y 7@ origin_z 8@ target_x 9@ target_y 10@ target_z 11@ get_xyz_coll_point_to 12@ 13@ 14@ get_coll_entity_to 15@
then
    // [...]
end

[...]

:getCollisionPointCoords
0A9F: 10@ = current_thread_pointer
0A8E: 11@ = 10@ + 0x3C // 0@, 1@, 2@
0A8E: 12@ = 10@ + 0x48 // 3@, 4@, 5@
0A8E: 13@ = 10@ + 0x54 // 6@, 7@, 8@
0A8E: 14@ = 10@ + 0x60 // 9@
0AA7: call_function 0x0056BA00 num_params 12 pop 12 bIgnoreShootThroughStuff false bIgnoreSomeObjectsForCamera false bIgnoreSeeThroughStuff false bParticle false bObject true bPed true bVehicle true bBuilding true pclEntity 14@ pclPoint 13@ pstTarget 12@ pstOrigin 11@ bReturn 15@ // processLineOfSight
15@ == true
0AB2: ret 4 6@ 7@ 8@ 9@

@Wesser you need to reserve 11 variables (44b) for pclPoint param.

Yes, my mystake. It can cause some troubles for the storage of the subsequent variables in a thread, unless you inherit the calling of that routine in an SCM function where the locals usage is usually limited. Passing a label pointer or the one of an allocated memory would be better in any way, though.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users