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: [email protected] = 5.1 //4242.640687

while true
wait 0
if and
Player.Defined($PLAYER_CHAR)
Actor.DrivingVehicleType($PLAYER_ACTOR, #HYDRA)
    then
    03C0: [email protected] = actor $PLAYER_ACTOR car
    if
    Car.Defined([email protected])
    then
    0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 5.0 0.0 //00AA: store_car [email protected] position_to [email protected] [email protected] [email protected]
    0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 [email protected] 0.0
      repeat
      wait 0
      000B: [email protected] += 1.0
      until 86BD:   not no_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
    050A: [email protected] = distance_between_XYZ [email protected] [email protected] [email protected] and_XYZ [email protected] [email protected] [email protected]
    //---DEBUG TEST
    0092: [email protected] = float [email protected] to_integer
    03F0: enable_text_draw 1
    045A: draw_text_1number 10.0 10.0 GXT 'NUMBER' number [email protected]
    else
    Car.RemoveReferences([email protected])
    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
  • Contribution Award [Mods]

#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: [email protected] = current_thread_pointer
0A8E: [email protected] = [email protected] + 0x54 // [email protected], [email protected], [email protected]
0A8E: [email protected] = [email protected] + 0x60 // [email protected], [email protected], [email protected]
0A8E: [email protected] = [email protected] + 0x6C // [email protected], [email protected], [email protected]
0A8E: [email protected] = [email protected] + 0x78 // [email protected]
[email protected] = ORIGIN_X
[email protected] = ORIGIN_Y
[email protected] = ORIGIN_Z
[email protected] = TARGET_X
[email protected] = TARGET_Y
[email protected] = 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 [email protected] pclPoint [email protected] pstTarget [email protected] pstOrigin [email protected] bReturn [email protected] // processLineOfSight
if
    [email protected] == true
then
    // The collision point coordinates will be stored into [email protected], [email protected] and [email protected]
    // The collision entity will be handled by [email protected]
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: [email protected] = actor $PLAYER_ACTOR car
    0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 5.0 0.0
    0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 505.0 0.0
    0AB1: call_scm_func @getCollisionPointCoords 6 origin_x [email protected] origin_y [email protected] origin_z [email protected] target_x [email protected] target_y [email protected] target_z [email protected] get_xyz_coll_point_to [email protected] [email protected] [email protected]
    if 
      [email protected] == true
    then
      020C: create_explosion_with_radius 0 at [email protected] [email protected] [email protected]
    end
  end
end

:getCollisionPointCoords
  0A9F: [email protected] = current_thread_pointer
  0A8E: [email protected] = [email protected] + 0x54 // [email protected], [email protected], [email protected]
  0A8E: [email protected] = [email protected] + 0x60 // [email protected], [email protected], [email protected]
  0A8E: [email protected] = [email protected] + 0x6C // [email protected], [email protected], [email protected]
  0A8E: [email protected] = [email protected] + 0x78 // [email protected]
  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 [email protected] pclPoint [email protected] pstTarget [email protected] pstOrigin [email protected] bReturn [email protected] // processLineOfSight
  0AB2: ret 4 [email protected] [email protected] [email protected] [email protected]

DK22Pac
  • DK22Pac

  • Feroci
  • Joined: 12 Apr 2009
  • Ukraine
  • Best WIP Mod 2014 [Grand Theft Auto 3D Contribution]
    Contribution Award [Mods]
    Helpfulness Award [Mods]

#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
  • Contribution Award [Mods]

#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 [email protected] origin_y [email protected] origin_z [email protected] target_x [email protected] target_y [email protected] target_z [email protected] get_xyz_coll_point_to [email protected] [email protected] [email protected] get_coll_entity_to [email protected]
then
    // [...]
end

[...]

:getCollisionPointCoords
0A9F: [email protected] = current_thread_pointer
0A8E: [email protected] = [email protected] + 0x3C // [email protected], [email protected], [email protected]
0A8E: [email protected] = [email protected] + 0x48 // [email protected], [email protected], [email protected]
0A8E: [email protected] = [email protected] + 0x54 // [email protected], [email protected], [email protected]
0A8E: [email protected] = [email protected] + 0x60 // [email protected]
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 [email protected] pclPoint [email protected] pstTarget [email protected] pstOrigin [email protected] bReturn [email protected] // processLineOfSight
[email protected] == true
0AB2: ret 4 [email protected] [email protected] [email protected] [email protected]

@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