Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      2. Updates
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Red Dead Online

      1. Blood Money
      2. Frontier Pursuits
      3. Find Lobbies & Outlaws
      4. Help & Support
    3. Crews

    1. Grand Theft Auto Series

      1. Bugs*
      2. St. Andrews Cathedral
    2. GTA VI

    3. GTA V

      1. Guides & Strategies
      2. Help & Support
    4. GTA IV

      1. The Lost and Damned
      2. The Ballad of Gay Tony
      3. Guides & Strategies
      4. Help & Support
    5. GTA San Andreas

      1. Classic GTA SA
      2. Guides & Strategies
      3. Help & Support
    6. GTA Vice City

      1. Classic GTA VC
      2. Guides & Strategies
      3. Help & Support
    7. GTA III

      1. Classic GTA III
      2. Guides & Strategies
      3. Help & Support
    8. Portable Games

      1. GTA Chinatown Wars
      2. GTA Vice City Stories
      3. GTA Liberty City Stories
    9. Top-Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    1. Red Dead Redemption 2

      1. PC
      2. Help & Support
    2. Red Dead Redemption

    1. GTA Mods

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Red Dead Mods

      1. Documentation
    3. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    4. Featured Mods

      1. Design Your Own Mission
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Rockstar Games

    2. Rockstar Collectors

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Movies & TV
      5. Music
      6. Sports
      7. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Announcements

    2. Forum Support

    3. Suggestions

Is there an opcode to pick random vehicles without range? (Non-consecutive IDs)


Nico
 Share

Recommended Posts

I've been messing with the Trucks with Trailers script to add functionality to other trucks I added, and I also want to add variety to the cars pulled by the tow trucks. For that specific feature, this CLEO script uses this opcode:

0209: [email protected] = random_int_in_ranges 604 606 

IDs 604 and 605 correspond to the wrecked versions of Glendale and Sadler. I want to extend this and include other beater cars like Clover, Tampa and others I added, but they are not consecutive IDs with these two. How can I do that?

Edited by Nico
Did you see the frightened ones? Did you hear the falling bombs? Did you ever wonder...

CslLPae.png

...why we had to run for shelter when the promise of a brave new world unfurled beneath a clear blue sky?
Link to comment
Share on other sites

This can be easily accomplished using arrays but then you must deal with the limited amount of local variables available, especially in CLEO. For starters, SWITCH_START (2161) and SWITCH_CONTINUED (2162) commands would do the trick unless you like something more advanced, limitless and equally as compact:

arraytest.txt

// Switch to GTA:SA SCR mode.

{$CLEO}

// Guarantee a 4-byte alignment.
goto @script_start
hex
    FF
end

/*
int aWreckedCars[4] = { MI_CLOVER, MI_TAMPA, MI_GLENsh*t, MI_SADLsh*t };
*/
:_aWreckedCars
hex
    1E020000 25020000 5C020000 5D020000
end

:script_start

var
    [email protected]: Int
    [email protected]: Int
    [email protected]: Int
end

0A9F: get_pointer_to_this_script [email protected]
0A8E: [email protected] = [email protected] + 0x10 // offsetof(CRunningScript, m_pStartAddress)
0A8D: read_memory [email protected] size 4 vp FALSE store_to [email protected]

[email protected] += 0x3C // offsetof(CRunningScript, m_aLocalVariables[0])
[email protected] -= @_aWreckedCars
[email protected] -= [email protected]
[email protected] /= 4

while true
    0209: generate_random_int_in_range 0 4 store_to [email protected]
    [email protected] += [email protected]
    [email protected] = 0
    repeat
        0001: wait 0
        03F0: use_text_commands TRUE
        0342: set_text_center TRUE
        045A: display_text_with_number 320.0 300.0 tkey 'NUMBER' number [email protected]([email protected],1i) // ~1~
    until [email protected] >= 3000
end

 

Edited by Wesser

012          345
678   9A   BCD
EFG HIJK LMN
OPQR  STUV
WX    YZ

Link to comment
Share on other sites

In your example, the beater cars are represented by hex values, right? Is it possible to recall them by their model ID instead? The script I want to edit picks vehicles based on their ID rather than hex values.

 

I'm gonna post the entire script I want to edit:

Spoiler
// This file was decompiled using SASCM.ini published on 2021-07-05
{$CLEO .cs}

script_name 'NONAME' 

:NONAME_11
wait 0 
if 
   Player.Defined($PLAYER_CHAR)
jf @NONAME_11 
068D: get_camera_position_to [email protected] [email protected] [email protected] 
if 
get_random_car_in_sphere_no_save_recursive [email protected] = random_vehicle_near_point [email protected] [email protected] [email protected] in_radius 1000.0 find_next 0 pass_wrecked 1 
jf @NONAME_11 

:NONAME_76
wait 0 
if 
   not Car.Wrecked([email protected])
jf @NONAME_911 
03F3: get_car [email protected] primary_color_to [email protected] secondary_color_to [email protected] 
0A12: get_car [email protected] tertiary_color_to [email protected] quaternary_color_to [email protected] 
if 
   not [email protected] == 6 
jf @NONAME_911 
if 
   Car.Model([email protected]) == #RDTRAIN
jf @NONAME_227 
[email protected] = 515 
[email protected] = 7 
0209: [email protected] = random_int_in_ranges 0 2 
if 
[email protected] = 0 
jf @NONAME_212 
[email protected] = 450 
jump @NONAME_524 

:NONAME_212
[email protected] = 591 
jump @NONAME_524 

:NONAME_227
if 
   Car.Model([email protected]) == #LINERUN
jf @NONAME_242 
[email protected] = 403 
[email protected] = 435 
[email protected] = 7 
jump @NONAME_524 

:NONAME_242
if 
   Car.Model([email protected]) == #PULVER
jf @NONAME_276 
[email protected] = 12574 
[email protected] = 435 
[email protected] = 7 
jump @NONAME_524 

:NONAME_276
if 
   Car.Model([email protected]) == #PETRO
jf @NONAME_291 
[email protected] = 514 
[email protected] = 584 
[email protected] = 7 
jump @NONAME_524 

:NONAME_291
if 
   Car.Model([email protected]) == #CERBERUS
jf @NONAME_325 
[email protected] = 12519 
[email protected] = 12520 
[email protected] = 7 
jump @NONAME_524 

:NONAME_325
if 
   Car.Model([email protected]) == #TRACTOR
jf @NONAME_378 
[email protected] = 531 
[email protected] = 610 
0209: [email protected] = random_int_in_ranges 157 163 
jump @NONAME_524 

:NONAME_378
if 
   Car.Model([email protected]) == #TOWTRUCK
jf @NONAME_430 
[email protected] = 525 
0209: [email protected] = random_int_in_ranges 604 606 
[email protected] = 50 
jump @NONAME_524 

:NONAME_430
if 
   Car.Model([email protected]) == #UTILITY
jf @NONAME_479 
[email protected] = 552 
[email protected] = 611 
[email protected] = 50 
jump @NONAME_524 

:NONAME_479
if 
   Car.Model([email protected]) == #BAGGAGE
jf @NONAME_494 
[email protected] = 485 
0209: [email protected] = random_int_in_ranges 606 609 
[email protected] = 16 
jump @NONAME_524

:NONAME_494
if 
   Car.Model([email protected]) == #BOBTAIL
jf @NONAME_509 
[email protected] = 12512 
0209: [email protected] = random_int_in_ranges 606 609 
[email protected] = 16 
jump @NONAME_524

:NONAME_509
if 
   Car.Model([email protected]) == #TUG
jf @NONAME_512
[email protected] = 583 
[email protected] = 608 
[email protected] = 16 
jump @NONAME_524

:NONAME_512
if 
   Car.Model([email protected]) == #ARTICT3
jf @NONAME_911 
[email protected] = 591 
[email protected] = 435
[email protected] = 16 

:NONAME_524
wait 0 
get_vehicle_pointer [email protected] = vehicle [email protected] 
0A8E: [email protected] = [email protected] + 1188 // int 
read_memory [email protected] = read_memory [email protected] size 1 virtual_protect 0 
if and
   not [email protected] == 2 
87AB:   not car -1 has_attached_trailer [email protected] 
jf @NONAME_948 
0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 0.0 0.0 
[email protected] = Car.Angle([email protected])
046C: [email protected] = car [email protected] driver 
Model.Load([email protected])
Model.Load([email protected])
Model.Load([email protected])
if and
   Model.Available([email protected])
   Model.Available([email protected])
   Model.Available([email protected])
jf @NONAME_524 
0395: clear_area 1 at [email protected] [email protected] [email protected] radius 3.0 
wait 0 
Car.Create([email protected], [email protected], [email protected], [email protected], [email protected])
Car.Angle([email protected]) = [email protected]
0229: set_car [email protected] primary_color_to [email protected] secondary_color_to [email protected] 
0A11: set_car [email protected] tertiary_color_to [email protected] quaternary_color_to 6 
0294: set_car [email protected] sprayable 0 
0407: store_coords_to [email protected] [email protected] [email protected] from_car [email protected] with_offset 0.0 -5.0 0.0 
0395: clear_area 1 at [email protected] [email protected] [email protected] radius 3.0 
Car.Create([email protected], [email protected], [email protected], [email protected], [email protected])
Car.Angle([email protected]) = [email protected]
0893: put_trailer [email protected] on_cab [email protected] 
Model.Destroy([email protected])
Model.Destroy([email protected])
wait 0 
if 
   not [email protected] == -1 
jf @NONAME_901 
Actor.CreateAsDriver([email protected], PedType.Mission1, [email protected], [email protected])
Car.SetDriverBehaviour([email protected], CarMission.Cruise)
00AE: set_car [email protected] traffic_behaviour_to 4 
cleo_set_car_engine_on [email protected] engine_state_to 1 
Model.Destroy([email protected])
Actor.RemoveReferences([email protected])

:NONAME_901
Car.RemoveReferences([email protected])
Car.RemoveReferences([email protected])

:NONAME_911
   not get_random_car_in_sphere_no_save_recursive [email protected] = random_vehicle_near_point [email protected] [email protected] [email protected] in_radius 1000.0 find_next 1 pass_wrecked 1 
jf @NONAME_76 
jump @NONAME_11 

:NONAME_948
wait 0 
0A11: set_car [email protected] tertiary_color_to [email protected] quaternary_color_to 6 
0294: set_car [email protected] sprayable 0 
jump @NONAME_911 

 

Edited by Nico
Did you see the frightened ones? Did you hear the falling bombs? Did you ever wonder...

CslLPae.png

...why we had to run for shelter when the promise of a brave new world unfurled beneath a clear blue sky?
Link to comment
Share on other sites

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
 Share

  • 1 User Currently Viewing
    0 members, 0 Anonymous, 1 Guest

×
×
  • Create New...

Important Information

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