Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      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. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

Get car handle and mark it as used by script


limdingwen
 Share

Recommended Posts

Hello.

 

I am writing a mod to allow people to "lock" their cars, so that it does not despawn. To do that, I have to obtain the car handle of a car, make the game know that I am using the car so that it does not despawn, then remove_references_to_car when the player "unlocks" the car.

 

In tutorials, I see that when you spawn a car, the game marks it as used by script. But how do you get handle of existing car, and make the game mark it as used by script?

 

I tried these opcodes:

 

03C0: actor $PLAYER_ACTOR car

This specifically said that it will not save the car, so nope, the car still despawns.

 

0811: actor $PLAYER_ACTOR used_car

Even though not documented, according to some guy on the forums, this will not save the car as well. True, the car despawns.

 

00D9: actor $PLAYER_ACTOR car // Add to mission cleanup

This should save the car, but it always returns me -1 as car handle when player is in car. I also don't want the player's car to disappear after a mission (if they use the mod during the mission) so the mission cleanup thing is also a problem. The documentation also recommended not to use it as it is mission-based.

 

0763: add_car_reference

Does not work. According to some guy on the forums, this only works in missions.

 

So, is there an opcode or a way to make the game mark an existing car as being used by a script (opposite of remove_references_to_car)? Thank you.

 

Edit: If a car is marked as used, will it be impounded, despawned by forced car spawning in missions, or despawned by other scripts?

Edited by limdingwen
Link to comment
Share on other sites

Here you go:

0AB1: call_scm_func @CarSaveRefs 1 vehicle [email protected]
:CarSaveRefs0A97: [email protected] = car [email protected] struct0085: [email protected] = [email protected]: [email protected] = [email protected]@ += 0x428 [email protected] += 0x4A4 0A8C: write_memory [email protected] size 1 value 136 virtual_protect 00A8C: write_memory [email protected] size 1 value 2 virtual_protect 00AB2: ret 0

To check if a certain car will be deleted by the game or not:

0A97: [email protected] = car [email protected] struct0AA8: CVehicle::CanBeDeleted 0x6D1180 struct [email protected] num_params 0 pop 0 returns: bool [email protected]    [email protected] == 0then0AD1: show_formatted_text_highpriority "~g~The car wont be removed by the game" time 5000 else0AD1: show_formatted_text_highpriority "~r~The car will be removed by the game" time 5000 end
Edited by Shmoopy
Link to comment
Share on other sites

Thank you! I'll be testing this code out later, and if it works, it shall be awesome. I'm writing in CLEO though, so I assume that CarSaveRefs is part of main.scm?

Link to comment
Share on other sites

Nah, it's not in main.scm. I'm not all that familiar with call_scm_func but I think what you've got here are all the important snippets for your cleo script without the context of a full script. You might want to search tutorials for other uses of opcode 0AB1.

 

I think what you want to do is put the 0AB1 line in the main body of your script to do the work you require. The :CarSaveRefs segment would go outside of the main body of your script where it can't be executed unless called - so stick it at the end or jump around it. The third snippet is simply an example of how to check the status. You'd need to rework it for your own purpose.

 

Mission cars usually don't get impounded. But impounds are weird, you'd need to check to be sure. The easiest places to impound cars are within 30 units of the Broadway behind the Idlewood car wash when the Pimping mission is started, any floor of the Emerald Isle carpark - just change floors or leave the building, several hundred meters around the schools when started, and the whole map when a triathlon is started.

 

Garages won't save mission cars. Pay'n'sprays tend to reset a lot of properties.

Edited by OrionSR
Link to comment
Share on other sites

Thanks Orion, I'm sure that information will come in handy. I'll test the impound after I get the code working. I added the code inline to the one portion I needed to obtain ownership of the car. It seems that it turns the engine off, CVehicle::CanBeDeleted returns 0, however, the car despawned. I tested it by leaving the area around the car using another car, then carjacking two more people on the other side of the city and driving back.

 

I checked gtamodding.com's Memory Addresses page, and it says that for car structs, +0x428 refers to engine state. Can't find +0x4A4 though. Weird. Is there something wrong with what I understand?

Link to comment
Share on other sites

I was sloppy, hold on I'll fix this

It works flawlessly, I hijacked 3 different cars and put them in different places then I spawned a Hunter and left town then went back to check if the cars were still there, they were:

Here is the code that I used to test it:

 


while truewait 0    if and        00DF:   actor $PLAYER_ACTOR driving        0AB0:   key_pressed 73 // Pressed i    then    wait 250    03C0: [email protected] = actor $PLAYER_ACTOR car    0AB1: call_scm_func @CarSaveRefs 1 vehicle [email protected]        0AD1: show_formatted_text_highpriority "Car saved!" time 2000     endendend_thread:CarSaveRefs0A97: [email protected] = car [email protected] struct0AA6: CVehicle::SetRef 0x6D5D70 struct [email protected] num_params 1 pop 0 20AB2: ret 0

 

 

 

Use this code and tell me if it worked for you, make sure you have the 1.0 US version (Hoodlum)

 

 

Bytheway there is another way to do this,its done by NOPing the function which is responsible in removing the refs of the vehicles, but I wonder if this will lead to a massive lag, gonna try it later.

Edit:

 

I believe the function is RemoveRefsToVehicle(0x871f20), we turn its first opcode to a ret with this:

0A8C: write_memory 0x871F20 size 4 value 194 virtual_protect 0 

Now anything that calls this function will get nothing from it as it returns 0 instantly with this tweak.

 

Try it and give feedback.

Edited by Shmoopy
Link to comment
Share on other sites

Try it and give feedback.

 

Thanks for the replies. The first time I tried it, it didn't work, but it worked after I deleted driveby.cs, which I think was despawning cars manually. In fact, it worked a little too well.

 

Here are the results of my testing:

 

1. Using Idlewood Broadway, Driving School and Lowrider Meet, I found that the cars will not be impounded.

2. Using the Lowrider Meet, I found that cars will not be despawned due to force-spawning. The new car (from the lowrider meet) will just spawn into the "locked" car.

3. Getting wasted does not despawn the "locked" car.

 

There were some worrying moments though. I parked a FCR-600 next to Woozie's apartment, "locked" it, and started The Da Nang Thang. I got wasted, and when I came back to his apartment, the bike was no longer there. It might be that I accidentally didn't press the "lock" key long enough for my script to detect it.

 

My script shows a notifying text box when I get into a "locked" car. During Yay Ka Boom Boom, I parked a police bike next to the bomb shop, "locked" it, and completed the mission. When I came back, the bike was still there, but when I got onto it, there was no such notifying text box. It might be that I missed it though, or the "Start vigilante mission" message came after it and replaced it very quickly.

 

I still need to do more testing (daily usage) to see if these glitches still happen.

 

I haven't tested out the second method yet, but I think that will cause massive lag as every NPC car ever made during a session will not despawn.

 

Garages won't save mission cars. Pay'n'sprays tend to reset a lot of properties.

 

I lost a Super GT to a save garage, then I remembered this. :p What happens, I think, is that the script works too well, that even the garage can't despawn it. It stays there until you save and load again. This is a bit problematic. I think that one way of circumventing this is tell the user not to lock the car in the garage, but I'm afraid someone won't read the readme.

 

I haven't tested out Pay'n'sprays yet. I'll get back to you on that one.

 

Edit: I am worried that clearing ownership for the cars ("unlocking") used by missions during the missions may cause the mission scripts to lose ownership as well. The car would then despawn and the mission would say that the car was wrecked, failing it. I'm going to test it out.

 

Gotta make sure it's rock solid before releasing it.

Edited by limdingwen
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.