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

GTA SA: Deleting Parked Car Generators


psychedelist
 Share

Recommended Posts

I want to be able to spawn a car, same place every time, but model can be different each time. I considered 3 different ways but got stuck with each of them:

 

1. Create one parked car generator, keep the reference, and change the model it spawns dynamically. Is changing model in a parked car generator possible?

 

2. Whenever needing to change the model, delete the existing parked car generator and create a new one. If i have the generator handle in a variable, how can i delete it from the game permanently?

 

3. Spawn the car manually. For parked car generators, there's an opcode that sets "has been owned" flag for the generated car, but for manually created cars i need to set that flag myself. What is the address for this flag in the vehicle struct? I looked at this, assumed that a char is one byte, picked a known vehicle-related address from the wiki page, tried to offset that to the "owned" flag, and it didn't work, there must been something i did wrong.

 

Can anyone help me with at least one of those ways, please?

 

 

Link to comment
Share on other sites

Do you want to create a car generator with radom cars through main.scm? Because it would be much easier through .ipl 'cars' section. Anyway, if I understand you correctly, you can try using opcode 0732: which disables existing car generator from spawning a vehicle.

 

You want opcode 0A17: set_parked_car_generator '$BLAHBLAH' to_player_owned '0/1'

Edited by firedihm
Link to comment
Share on other sites

1) Yes, we can change the model. You could use model -1 to generate random vehicles from the current popcycle, but I'm assuming you want more control.

 

2) Deleting the existing cargen and adding another is a simpler solution than changing the model.

 

3) Create car codes: This is probably the way to go so I won't go into too much detail about the cargens just yet. I was hunting for the player owned flag on spawned cars and I think I found it in my mobile saves, but it also looks like it is set by default on created cars. I saw reference to a flag that would "park" a create car but didn't follow through to find an opcode just yet. Created cars are player owned by default matches my observations; I can't think of any time CJ has earned a wanted level from entering a mission vehicle.

 

With that in mind, do you still want to mess with the cargens? Do you have a need to park a car that is no player owned?

 

This is the reference I'm using to identify the vehicle flags that includes the player owned flag. I need to enumerate these flags in my 010 template; they are difficult to tease out of a pair of dwords. I'm not sure if the vehicle records I've isolated in my mobile saves are complete match for memory, and I it's been a while since I've tried to manage active vehicles, but we can probably work out the offsets now that I know what I'm looking for, but I'm not sure it will be necessary.

 

Older post with examples for "unallocating" cargens using cleo 3 and an SCM function. Feel free to quote here if you think it will help. The SCM function is based on Fastman92's guide, How to Properly add Car Generators with Cleo Script. This strategy creates cargens that don't save.

 

Sweet. It looks like Nick007 has already tracked down the player owned flag for us. <link>

Edited by OrionSR
Link to comment
Share on other sites

Do you want to create a car generator with radom cars through main.scm? Because it would be much easier through .ipl 'cars' section. Anyway, if I understand you correctly, you can try using opcode 0732: which disables existing car generator from spawning a vehicle.

 

You want opcode 0A17: set_parked_car_generator '$BLAHBLAH' to_player_owned '0/1'

I don't want to modify any existing car generators, i need to create one myself (from cleo script) and be able to change the model it spawns at any time, or delete the generator and create a new one with a new model. I already knew about that the "player owned" opcode and was going to use it if i ended up using generators.

 

 

1) Yes, we can change the model. You could use model -1 to generate random vehicles from the current popcycle, but I'm assuming you want more control.

 

2) Deleting the existing cargen and adding another is a simpler solution than changing the model.

 

3) Create car codes: This is probably the way to go so I won't go into too much detail about the cargens just yet. I was hunting for the player owned flag on spawned cars and I think I found it in my mobile saves, but it also looks like it is set by default on created cars. I saw reference to a flag that would "park" a create car but didn't follow through to find an opcode just yet. Created cars are player owned by default matches my observations; I can't think of any time CJ has earned a wanted level from entering a mission vehicle.

 

With that in mind, do you still want to mess with the cargens? Do you have a need to park a car that is no player owned?

1. Yes, i need to be able to choose the model it spawns.

 

3. I haven't actually tested it, i'll be damned if cars created with Car.Create are owned by default, I'll try it, but..

 

I still think that car generators would be easier in terms of implementation, since i wouldn't have to determine manually whether i should spawn the car or not. If i were to spawn cars myself, i'd have to try simulating the standard car generators behavior, so i'd prefer using the generators if possible. If you already have a working solution to delete a car generator if the only thing known is its handle, and it's not difficult to post it, i'd appreciate it a lot. No, the parked cars won't be whatever player has just owned, I'm going to monitor $IMPORT_CAR variable that spawns cars on ship in SF docks, and then create/park-generate the car near your SF garage, so that the docks import feature is now kind of useful. Any newly imported car would replace the previous one.

 

Edit: just saw your edit, thanks a lot, i'll have a look.

Edited by psychedelist
Link to comment
Share on other sites

You can get a lot more control of your vehicles with create car. Cargens can't have paintjobs, mod parts, immunities, and a host of other properties applied. Simulating a cargen isn't all that difficult. The script will certainly be longer but it is standard practice so there is plenty of reference. And once you work out the first one it's just copy, paste and tweak the properties.

May I suggest: Use fastman's proper cargen function so your cargens can never save, then you only need to delete them when swapping models. I'll post the cargen structure below in case you want to tweak other cargen properties but deleting and replacing is a lot easier than tweaking individual fields.

Cargen Structure in Memory

CarGen structure:  0x00    word             model  0x02    byte[2]          colors  0x04    word[3]          x,y,z, all multiplied by 8  0x0A    byte             heading/360*256  0x0B    byte             alarm chance  0x0C    byte             locked chance  0x0D    byte             flags: bit 2=force spawn, bit 8=player owned  0x0E    word             unknown setting (IPL field 11, scm field 7)  0x10    word             unused delay  0x12    bytes[2]         align  0x14    dword            timer  0x18    word             unknown activity  0x1A    word             number of cars to generate (101 or higher means unlimited generation)  0x1C    byte             IPL stream of binary generators (non-zero records are not saved)  0x1D    byte             allocation flag (set to 0 to unallocate gargen).  0x1E    byte[2]          align

I think I did the math right. This is adapted from the save structure which begins with a 2 byte index, so all offsets should be -2 compared to the save documentation.

 

This editor has a cargen tool that provides and easy way to verify that your cargens are not being saved.

Edited by OrionSR
Link to comment
Share on other sites

 

I'm pretty sure that SASE can modify TTDISA saves, but it doesn't have a box to uncheck for HC. You'll need to set the appropriate global variable to 1 to enable the censor. This is usually $1219 in the PC scripts but it's my understanding that TTDISA has it's own global variable table and it doesn't always match up with the standard scripts. You'll need to verify the appropriate flag in the TTDISA scripts.

 

Edit: Whoops. So this is where this message disappeared to. I posted in the wrong topic. Sorry.

Edited by OrionSR
Link to comment
Share on other sites

Thank you so much for the very detailed answers. They're incredibly helpful, I really appreciate it. I used the "proper cargen" function like you suggested, everything works. By deleting a generator, you mean 014C: set_parked_car_generator [email protected] cars_to_generate_to 0 ? That's what i do with the previous one before initializing a new one.

 

I'm sorry i'm about to ask questions that are somewhat offtopic, but on the other hand they're related to what i'm trying to accomplish, so i hope it's no problem. I'm wondering about reliability of Car.Defined and Actor.Defined checks. My code is executed if Car.Defined($IMPORT_CAR) returns true, and the car's model is different than the previous one stored in a variable. But whenever a car is created, the returned handle is basically a number/address in the vehicle pool. Unless the variable is reset to 0 or -1 manually, can the Defined check give an unexpected positive if the handle happens to point at a valid but irrelevant vehicle that could be created at any time later? If so, do i need to reset my handle manually to 0 or -1 once Car.Defined returns false, and would a "wait 1000" loop be enough for it, or it better be a "wait 0"? This knowledge would help me a lot with building my mod in general, not just this current car generator task.

 

Also, while trying to get rid of crashes in my mod, i added Actor.Defined($Player_Actor) wherever it seemed appropriate, but i have doubts if such check can actually be useful, is it?

Link to comment
Share on other sites

New questions: No idea, sorry. My cleo scripts tend to be special purpose testing or save editing scripts that serve a special purpose before getting removed. They seldom need to run for long and are rarely shared with others so I tend to skip the finer points of coding. If I need to bulletproof my scripts a little better I usually follow the examples from ZAZ.

 

Added: Do not confuse cargens with the vehicles they spawn. In the example below, $2766 describes the cargen and can be used to change the generation status or player owned properties, but that's it as far as standard opcodes go.

Opcode 014C: does not delete cargens. This is the standard opcode for changing the display status of cargens. There are no standard opcodes for deleting cargens; you'll need to work something out with memory writes. I've reposted my Cleo3 snippet and Cleo4 SCM function below.

"Test code that unallocates the East LS Clover so that it won't be saved." True, but also describes fastman's proper cargen function. Removing the allocation flag will immediately delete the cargen (but not any currently spawned vehicles) and free up the slot for reuse. fastman's proper cargens will persist until... a save is loaded, I believe.

 

Cleo3 Example:

// Test code that unallocates the East LS Clover so that it won't be saved.
{$CLEO .cs}
0000:				
while true
  wait 250
  if
    0AB0:   key_pressed 0x77    // F8
  then
    0085: [email protected] = $2766 // index of the East LS Clover
    [email protected] *= 0x20       // cargen record size
    [email protected] += 0x00c27ad0 // start of cargen structure
    [email protected] += 0x1D       // offset to allocation byte (save offset -2)
    0A8C: write_memory [email protected] size 1 value 0 virtual_protect 0
    wait 250
    00BB: show_text_lowpriority GXT 'FESZ_LS' time 2000 flag 1  // Load Successful.
  end
end

SCM Function:

:DeleteCarGenerator
// Adapted from fastman92's DisableCarGeneratorFromBeingSaved function
// Example: 0AB1: call_scm_func @DeleteCarGenerator 1 cargen_index [email protected]

// Is invalid generator ID?
if or
  -1 >= [email protected]  
  [email protected] >= 500
then
  0AB2: ret 0
end

0A8D: [email protected] = read_memory 0x6F32AA size 1 virtual_protect false // CCarGenerator_size
0AA7: call_function 0x479D60 num_params 1 pop 1 [email protected] store_result_to [email protected] // CCarGenerator* ptr
if
  [email protected] >= 0x30 // is CCarGenerator_extended ?
then
  [email protected] += 0x24 // *** untested ***  
  0A8C: write_memory [email protected] size 2 value 0x0 virtual_protect false // exIplFile
else
  [email protected] += 0x1D
  0A8C: write_memory [email protected] size 1 value 0x0 virtual_protect false // iplFile
end
0AB2: ret 0
Edited by OrionSR
Code Tags
Link to comment
Share on other sites

Another idea to consider: Simulated IPL Streams

 

fastman92's proper cargen function works by exploiting the IPL field associated with the streaming cargens. The cargen limit is 500, standard on PC. There are only 208 standard scm vehicles that are added by the scripts and saved. These tend to be mission specific. Most of the ambient parked vehicles are streamed in with the environment. So if too many scm vehicles are added these cars can't spawn. Hence all the fuss about adding proper cargens. (I figure you know this bit but I may as well complete the documentation.) I don't remember how many IPL streams there are, less than 200 out of 256 anyway. Usually these vehicles are removed when the stream goes inactive.

 

fastman is using the last IPL flag as a way to prevent saving. Since the 255 stream never goes inactive the vehicle persist while playing but won't save. If you wanted to control large groups of vehicles, by county or wanted level, for example, you could modify fastman's code to use some of the other unused upper IPL streams and write a routine that scans for your stream and unallocates the group as needed.

Edited by OrionSR
Link to comment
Share on other sites

Thanks for the clarification, i figured that 014C: wouldn't delete the car generator, but i wrongly assumed that since it isn't going to be saved, i can just leave it there. Now i realized that the save prevention is just an extra precaution, and it's better to delete them properly still, to prevent issues when the game isn't saved/loaded for a long time. I'll "Mark Solved" one of your posts after i'm done testing, thanks again.

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.