limdingwen Posted August 28, 2015 Share Posted August 28, 2015 (edited) 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 August 28, 2015 by limdingwen Link to comment Share on other sites More sharing options...
limdingwen Posted August 30, 2015 Author Share Posted August 30, 2015 Can't find this post in boards, bumping? :\ Link to comment Share on other sites More sharing options...
Shmoopy Posted August 30, 2015 Share Posted August 30, 2015 (edited) 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 August 30, 2015 by Shmoopy Link to comment Share on other sites More sharing options...
limdingwen Posted August 31, 2015 Author Share Posted August 31, 2015 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 More sharing options...
OrionSR Posted August 31, 2015 Share Posted August 31, 2015 (edited) 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 August 31, 2015 by OrionSR Shmoopy 1 Link to comment Share on other sites More sharing options...
limdingwen Posted September 1, 2015 Author Share Posted September 1, 2015 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 More sharing options...
Shmoopy Posted September 1, 2015 Share Posted September 1, 2015 (edited) I was sloppy, hold on I'll fix thisIt 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 September 1, 2015 by Shmoopy Link to comment Share on other sites More sharing options...
limdingwen Posted September 2, 2015 Author Share Posted September 2, 2015 (edited) 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. 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 September 2, 2015 by limdingwen Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now