Jump to content

[GTA SA] Throwing cars and objects to the player's position


Recommended Posts

I'm trying to create a script where a vehicle spawns above a certain actor, and I want that vehicle to be thrown to the player's position, like in a specific direction towards him and at a "proper" speed. I'm trying to use something like this:

 

00AA: store_car 21@ position_to 13@ 14@ 15@
00A0: store_actor $PLAYER_ACTOR position_to 6@ 7@ 8@
0063: 6@ -= 13@
0063: 7@ -= 14@
0604: get_Z_angle_for_point 6@ 7@ store_to 22@
0175: set_car 21@ Z_angle_to 22@
02F8: get_car 21@ Z_angle_sine_to 25@
02F9: get_car 21@ Z_angle_cosine_to 26@
25@ *= -1.0       
07D5: set_car 21@ velocity_in_direction_XYZ 25@ 26@ 18@ rotation_velocitiesXY 0.0 0.0 unk 22@


But it's not working at all, there are a couple of times where it kinda 'works' but it's not what I'm trying to achieve. It's like the vehicle disappears instantly but it seems to be thrown at an extreme speed and never towards the player, the angle is inconsistent, I have seen the vehicle fly to the sky and such, and I have tried modifying and changing these values a lot and nothing seems to work. I tried to make it similar to an object-throwing script but this isn't doing what I want. I hope somebody can help me with this.

 

I don't know what opcode 02F8: and 02F8: returns, but the result is wrong

 

Your calculation for the angle by opcode 0604: is ok, then just use opcode 02F6: and 02F7:

and for other parameters of opcode 07D5: only zero

 

 

{$CLEO .cs}
thread 'THROCAR'

while true
    wait 0

    if 
        0256:   player $PLAYER_CHAR defined
    then
        if
            0AB0:   key_pressed 8//-----------------------------press backspace
        then
            04C4: create_coordinate 11@ 12@ 13@ from_actor $PLAYER_ACTOR offset 0.0  15.0  0.2
            0172: 14@ = actor $PLAYER_ACTOR Z_angle 
            0247: request_model #ALPHA
            038B: load_requested_models
            00A5: 21@ = create_car #ALPHA at 11@ 12@ 13@
            14@ += 180.0
            0175: set_car 21@ z_angle_to 14@
            0249: release_model #ALPHA
            wait 1250

            00AA: store_car 21@ position_to 13@ 14@ 15@
            00A0: store_actor $PLAYER_ACTOR position_to 6@ 7@ 8@
            0063: 6@ -= 13@
            0063: 7@ -= 14@
            0604: get_Z_angle_for_point 6@ 7@ store_to 22@
            02F6: 25@ = sine 22@ // (float) 
            02F7: 26@ = cosine 22@ // (float) 
            //25@ *= 0.5 // (float) 
            //26@ *= 0.5 // (float) 
            25@ *= -1.0
            07D5: set_car 21@ velocity_in_direction_XYZ 25@ 26@ 0.0 rotation_velocitiesXY 0.0 0.0 unk 0.0
            wait 5000
            01C3: remove_references_to_car 21@ 
        end  
    end
end

 

 

 

 

 

 

Thank you! Now it's working fine. I have only one more question; for example, if I'm close to the actor, the vehicle goes above me, towards the calculated direction. If I'm far, it actually hits me. So it's working fine in the XY direction, but I want to know if it's possible to add that other direction/angle (like vertically). Thank you for your help.

 

With the help of Pythagorean theorem and opcode 0604: can we calcuculate the vertical angle
and then a usefull value for the z-param of opcode 07D5: by getting sine of that angle

            0063: 15@ -= 8@            
            0AEE: 23@ = 6@ pow 2.0 //all floats
            0AEE: 24@ = 7@ pow 2.0 //all floats
            005B: 23@ += 24@ // (float)             
            01FB: 27@ = square_root 23@
            0604: get_Z_angle_for_point 15@ 27@ store_to 28@            
            02F6: 29@ = sine 28@ // (float)

          
            
but the result works not good enough, i believe, it's because of the gravity effect
so i made a correction depending to the distance

0509: 17@ = distance_between_XY 13@ 14@ and_XY 6@ 7@
17@ *= 0.001
005B: 29@ += 17@ // (float)

 

Test the script below
Consider that the car always spawns at same height

00A5: 21@ = create_car #ALPHA at 11@ 12@ 15.0

So you test can different vertical angles, if the height of CJ is different when car spawns (use jetpack)

 

Then you can make tests with several distances

04C4: create_coordinate 11@ 12@ 13@ from_actor $PLAYER_ACTOR offset 0.0  15.0  5.2
04C4: create_coordinate 11@ 12@ 13@ from_actor $PLAYER_ACTOR offset 0.0  30.0  5.2
04C4: create_coordinate 11@ 12@ 13@ from_actor $PLAYER_ACTOR offset 0.0  50.0  5.2

 

 

{$CLEO .cs}
thread 'THROCAR'

while true
    wait 0

    if 
        0256:   player $PLAYER_CHAR defined
    then
        if
            0AB0:   key_pressed 8//-----------------------------press backspace
        then
            04C4: create_coordinate 11@ 12@ 13@ from_actor $PLAYER_ACTOR offset 0.0  30.0  5.2
            0172: 14@ = actor $PLAYER_ACTOR Z_angle 
            0247: request_model #ALPHA
            038B: load_requested_models
            00A5: 21@ = create_car #ALPHA at 11@ 12@ 15.0
            14@ += 180.0
            0175: set_car 21@ z_angle_to 14@
            0249: release_model #ALPHA

            00AA: store_car 21@ position_to 13@ 14@ 15@
            00A0: store_actor $PLAYER_ACTOR position_to 6@ 7@ 8@
            0509: 17@ = distance_between_XY 13@ 14@ and_XY 6@ 7@
            17@ *= 0.001
            0063: 6@ -= 13@
            0063: 7@ -= 14@
            0604: get_Z_angle_for_point 6@ 7@ store_to 22@
            02F6: 25@ = sine 22@ // (float) 
            02F7: 26@ = cosine 22@ // (float) 
            25@ *= -1.0
            
            0063: 15@ -= 8@            
            0AEE: 23@ = 6@ pow 2.0 //all floats
            0AEE: 24@ = 7@ pow 2.0 //all floats
            005B: 23@ += 24@ // (float)             
            01FB: 27@ = square_root 23@
            0604: get_Z_angle_for_point 15@ 27@ store_to 28@            
            02F6: 29@ = sine 28@ // (float)
            005B: 29@ += 17@ // (float)
            
            07D5: set_car 21@ velocity_in_direction_XYZ 25@ 26@ 29@ rotation_velocitiesXY 0.0 0.0 unk 0.0
            wait 3000
            01C3: remove_references_to_car 21@ 
        end  
    end
end

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.