Difference between revisions of "Spawn a vehicle"
(some examples added. still needed the explanation of what each opcode/structure does) |
m |
||
(10 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | How to spawn a | + | How to spawn a [[vehicle]] using... |
==... opcode 00A5== | ==... opcode 00A5== | ||
Here's the basic example of creating a vehicle right before a player using [[00A5]] opcode. You need to press the Action button to create a vehicle. | Here's the basic example of creating a vehicle right before a player using [[00A5]] opcode. You need to press the Action button to create a vehicle. | ||
− | + | <source lang="scm">{$CLEO .cs} | |
− | + | ||
+ | 0000: NOP | ||
+ | |||
+ | :CARSPAWN_2 | ||
+ | 0001: wait 250 ms | ||
+ | 00D6: if | ||
+ | 0256: player $PLAYER_CHAR defined | ||
+ | 004D: jump_if_false @CARSPAWN_2 | ||
+ | 00D6: if | ||
+ | 00E1: player 0 pressed_key 4 | ||
+ | 004D: jump_if_false @CARSPAWN_2 | ||
+ | 0247: load_model #INFERNUS | ||
− | + | :CARSPAWN_45 | |
− | + | 00D6: if | |
− | + | 8248: not model #INFERNUS available | |
− | + | 004D: jump_if_false @CARSPAWN_68 | |
− | + | 0001: wait 0 ms | |
− | + | 0002: jump @CARSPAWN_45 | |
− | + | ||
− | + | :CARSPAWN_68 | |
− | + | 04C4: store_coords_to 0@ 1@ 2@ from_actor $PLAYER_ACTOR with_offset 0.0 4.0 1.4 | |
− | + | 0395: clear_area 1 at 0@ 1@ 2@ radius 3.0 | |
− | + | 00A5: 3@ = create_car #INFERNUS at 0@ 1@ 2@ | |
− | + | 01C3: remove_references_to_car 3@ | |
− | + | 0249: release_model #INFERNUS | |
− | + | 0001: wait 2000 ms | |
− | + | 0002: jump @CARSPAWN_2</source> | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | You may learn different ways of loading a model reading [[ | + | You may learn different ways of loading a model reading [[0247#Example|this article]]. |
==... memory hack== | ==... memory hack== | ||
This code also creates a vehicle before a player. | This code also creates a vehicle before a player. | ||
− | + | ||
+ | <source lang="scm">{$CLEO .cs} | ||
− | + | 0000: NOP | |
− | + | ||
− | + | :CARSPAWN_2 | |
− | + | 0001: wait 250 ms | |
− | + | 00D6: if | |
− | + | 0256: player $PLAYER_CHAR defined | |
− | + | 004D: jump_if_false @CARSPAWN_2 | |
− | + | 00D6: if | |
− | + | 00E1: player 0 pressed_key 4 | |
− | + | 004D: jump_if_false @CARSPAWN_2 | |
− | + | 0AA5: call 0x0043A0B6 num_params 1 pop 1 #INFERNUS | |
− | + | 0001: wait 2000 ms | |
− | + | 0002: jump @CARSPAWN_2</source> | |
It works same as the example above. The called procedure does all needed stuff (model loading, coords calculation) itself. But it only works on the version 1.0 US due to the fact the [[Function Memory Addresses (SA)|memory addresses]] differ on various game versions. | It works same as the example above. The called procedure does all needed stuff (model loading, coords calculation) itself. But it only works on the version 1.0 US due to the fact the [[Function Memory Addresses (SA)|memory addresses]] differ on various game versions. | ||
− | ==... opcode | + | ==... car generator opcode== |
− | This is an example of creating a [[014B|parked vehicle]]. Note that once created this vehicle will | + | This is an example of creating a [[014B|parked vehicle]]. Note that once created this vehicle will always be present in your game if you save. |
− | + | <source lang="scm">{$CLEO .cs} | |
− | + | 014B: 0@ = init_parked_car_generator #HOTRING color -1 -1 1 alarm 0 door_lock 0 0 10000 at -2335.069 -1613.274 483.7184 angle 0.0 | |
− | + | 014C: set_parked_car_generator 0@ cars_to_generate_to 101 | |
− | + | 0A95: enable_thread_saving | |
− | + | 0A93: end_custom_thread </source> | |
+ | Since 014B returns the handle of a parked car generator and not a vehicle instance, vehicle-related opcodes will not work on those variables | ||
+ | |||
+ | Other car generator-related opcodes, for San Andreas only: | ||
+ | * [[09E2]] – Creates a parked car generator where the car has a special numplate text. | ||
+ | * [[0A17]] – Sets a parked car generator as owned by the player | ||
+ | |||
+ | Native functions in GTA IV related to car generators: | ||
+ | * [[CREATE_CAR_GENERATOR]] | ||
+ | * [[CREATE_CAR_GENERATOR_WITH_PLATE]] | ||
+ | * [[CREATE_CARS_ON_GENERATORS_IN_AREA]] | ||
+ | * [[DELETE_CAR_GENERATOR]] | ||
+ | * [[DISABLE_CAR_GENERATORS]] | ||
+ | * [[DISABLE_CAR_GENERATORS_WITH_HELI]] | ||
+ | * [[FORCE_GENERATE_PARKED_CARS_TOO_CLOSE_TO_OTHERS]] | ||
+ | * [[IS_OUR_PLAYER_HIGHER_PRIORITY_FOR_CAR_GENERATION]] | ||
+ | * [[REMOVE_CARS_FROM_GENERATORS_IN_AREA]] | ||
+ | * [[SET_ALL_CAR_GENERATORS_BACK_TO_ACTIVE]] | ||
+ | * [[SET_CAR_GENERATORS_ACTIVE_IN_AREA]] | ||
+ | * [[SET_HAS_BEEN_OWNED_FOR_CAR_GENERATOR]] | ||
+ | * [[SWITCH_CAR_GENERATOR]] | ||
− | {{ | + | {{SA-navi}} |
− | + | [[Category:Code Snippets]][[Category:Mission Script]] |
Latest revision as of 18:23, 4 March 2015
How to spawn a vehicle using...
... opcode 00A5
Here's the basic example of creating a vehicle right before a player using 00A5 opcode. You need to press the Action button to create a vehicle.
{$CLEO .cs}
0000: NOP
:CARSPAWN_2
0001: wait 250 ms
00D6: if
0256: player $PLAYER_CHAR defined
004D: jump_if_false @CARSPAWN_2
00D6: if
00E1: player 0 pressed_key 4
004D: jump_if_false @CARSPAWN_2
0247: load_model #INFERNUS
:CARSPAWN_45
00D6: if
8248: not model #INFERNUS available
004D: jump_if_false @CARSPAWN_68
0001: wait 0 ms
0002: jump @CARSPAWN_45
:CARSPAWN_68
04C4: store_coords_to 0@ 1@ 2@ from_actor $PLAYER_ACTOR with_offset 0.0 4.0 1.4
0395: clear_area 1 at 0@ 1@ 2@ radius 3.0
00A5: 3@ = create_car #INFERNUS at 0@ 1@ 2@
01C3: remove_references_to_car 3@
0249: release_model #INFERNUS
0001: wait 2000 ms
0002: jump @CARSPAWN_2
You may learn different ways of loading a model reading this article.
... memory hack
This code also creates a vehicle before a player.
{$CLEO .cs}
0000: NOP
:CARSPAWN_2
0001: wait 250 ms
00D6: if
0256: player $PLAYER_CHAR defined
004D: jump_if_false @CARSPAWN_2
00D6: if
00E1: player 0 pressed_key 4
004D: jump_if_false @CARSPAWN_2
0AA5: call 0x0043A0B6 num_params 1 pop 1 #INFERNUS
0001: wait 2000 ms
0002: jump @CARSPAWN_2
It works same as the example above. The called procedure does all needed stuff (model loading, coords calculation) itself. But it only works on the version 1.0 US due to the fact the memory addresses differ on various game versions.
... car generator opcode
This is an example of creating a parked vehicle. Note that once created this vehicle will always be present in your game if you save.
{$CLEO .cs}
014B: 0@ = init_parked_car_generator #HOTRING color -1 -1 1 alarm 0 door_lock 0 0 10000 at -2335.069 -1613.274 483.7184 angle 0.0
014C: set_parked_car_generator 0@ cars_to_generate_to 101
0A95: enable_thread_saving
0A93: end_custom_thread
Since 014B returns the handle of a parked car generator and not a vehicle instance, vehicle-related opcodes will not work on those variables
Other car generator-related opcodes, for San Andreas only:
- 09E2 – Creates a parked car generator where the car has a special numplate text.
- 0A17 – Sets a parked car generator as owned by the player
Native functions in GTA IV related to car generators:
- CREATE_CAR_GENERATOR
- CREATE_CAR_GENERATOR_WITH_PLATE
- CREATE_CARS_ON_GENERATORS_IN_AREA
- DELETE_CAR_GENERATOR
- DISABLE_CAR_GENERATORS
- DISABLE_CAR_GENERATORS_WITH_HELI
- FORCE_GENERATE_PARKED_CARS_TOO_CLOSE_TO_OTHERS
- IS_OUR_PLAYER_HIGHER_PRIORITY_FOR_CAR_GENERATION
- REMOVE_CARS_FROM_GENERATORS_IN_AREA
- SET_ALL_CAR_GENERATORS_BACK_TO_ACTIVE
- SET_CAR_GENERATORS_ACTIVE_IN_AREA
- SET_HAS_BEEN_OWNED_FOR_CAR_GENERATOR
- SWITCH_CAR_GENERATOR