Jump to content

What's wrong?


Recommended Posts

I don't understand what's wrong with my script, everything seems to be ok but whenever I start playing it crashes. I've tried to fix it but I can't get it to work, so I thought I'd ask for help from here.

 

 

:AIRthread 'AIR':AIR_1if0442: player $PLAYER_CHAR in_car $AIR else_jump @AIR_2jump @AIR_3:AIR_2jump @AIR_1:AIR_3if01F3: car $AIR airborneelse_jump @AIR_1Camera.Shake(1000)04BA: set_car $AIR speed_instantly 50.0end_thread

 

 

Thanks in advance.

Link to comment
https://gtaforums.com/topic/265854-whats-wrong/
Share on other sites

My Sanny code is blergh (I'm OLD SCHOOL! cool.gif ), but are you defining the car $AIR anywhere else in the script? As in creating the car $AIR?

 

Is there any other code you have related to this that is not posted?

 

EDIT: Where does it crash? When you start the game? When you get into the car? When you get "air"?

Edited by ceedj
Link to comment
https://gtaforums.com/topic/265854-whats-wrong/#findComment-4024752
Share on other sites

That is not a car. That is a GENERATOR. Firstly, rename it to $AIR_GEN. In the second line of code, change the $8584 to your generator variable, in this case, now $AIR_GEN.

 

You CAN get the handle of the car, which is what you need to check if a car is airborne, with this:

 

03c1:  get_player_car	// $player_char, $carID - puts actual Car into $carID (use instead of store_player_car)

 

 

Your code might look like this:

 

03C1: $AIR = player $PLAYER_CHAR car

 

 

There is also a code for CREATING cars with a handle as well.

Link to comment
https://gtaforums.com/topic/265854-whats-wrong/#findComment-4024761
Share on other sites

*EDIT*

I don't understand why doesn't it work, everything should be correct.

 

 

:AIRthread 'AIR':AIR_103C1: $AIR = player $PLAYER_CHAR carjump @AIR_2:AIR_2if0443: player $PLAYER_CHAR in_a_carelse_jump @AIR_3jump @AIR_4:AIR_3jump @AIR_2:AIR_4if01F3: car $AIR airborneelse_jump @AIR_2Camera.Shake(1000)04BA: set_car $AIR speed_instantly 50.0end_thread

 

 

I also changed that it can be any car. Sorry for being such a noob whatsthat.gif

Edited by Mag-got
Link to comment
https://gtaforums.com/topic/265854-whats-wrong/#findComment-4024763
Share on other sites

Knowledge Novice

No worries, we all start out as a noob (it gets easier though). I'm using BW's Mission Builder v1.3, here's what I came up with. I used a local variable (0@) instead of a global variable ($AIR) to label the car, just so you know. This code affects any car that you drive. And if you're using Sanny Builder, I don't think that this MB code will work in it, but I'm still not familiar with Sanny. Hopefully you can follow this example and change the code appropriately if need be.

 

 

 

:AIR03A4: name_thread "Air":AIR_10001: wait  50 ms00D6: if  0 0256:   player $PLAYER_CHAR defined004D: jump if false ££AIR_100D6: if  000E0:   player $PLAYER_CHAR driving 004D: jump if false ££AIR_103C1: 0@ = player $PLAYER_CHAR car:AIR_20001: wait  50 ms00D6: if  00256:   player $PLAYER_CHAR defined004D: jump if false ££Remove_Reference200D6: if  0  00E0:   player $PLAYER_CHAR driving004D: jump if false ££Remove_Reference200D6: if  101F3:   car 0@ airborne00E1:   key_pressed  0  16004D: jump if false ££AIR_20003: shake camera  100004BA: set car  0@ speed instantly  50.0:AIR_30001: wait  50 ms00D6: if  21 01F3:   car 0@ airborne00E1:   key pressed  0  16004D: jump if false ££AIR_10002: jump ££AIR_3:Remove_Reference201C3: remove references to car 0@0002: jump ££AIR_1

 

 

Label :AIR_1

In the label :AIR_1 I checked to make sure that the char is defined and to see if the char is driving a vehicle. If either of these were not true the code would jump back to :AIR_1 and check again. If they were true then it labels the car that you are driving to '0@'.

 

Label :AIR_2

In the label :AIR_2 I checked again to make sure that the char is still defined (not busted or wasted) and that he is still driving a car. If either of these are false the code will jump to :Remove_Reference since we need to remove any reference to the car since we are no longer in it. But if the char is still defined and still driving the car the code will proceed to see if the car is 'airborne' and if you are pressing the 'gas' key. Unless both of these are true then the code will jump back to :AIR_2 to recheck the conditions all over again. Otherwise it causes the camera to shake and sets the car's speed instantly to 50.0 . The code then continues on to

 

Label :AIR_3

:AIR_3 checks to see if the car is still airborne or if you are sill pressing the gas key. If either of these are true then the code loops back to :AIR_3, continuously rechecking until the car is no longer in the air and you've released the gas. This helps prevent loss of control of the car by preventing the 'set speed instantly' command from being activated again until you're on the ground otherwise the car could fly out of control. Now the code jumps back to :AIR_1 to start the process all over again. The car is unstable during jumps due to the 'set speed instantly' command. I can't think of a solution to that right now. If you have any questions just ask. Later.

 

 

 

Link to comment
https://gtaforums.com/topic/265854-whats-wrong/#findComment-4024814
Share on other sites

Knowledge Novice

Okay, the first thing that I'm going to say is that I just installed Sanny Builder about five minutes ago. This is the first time that I've ever used it, ever. It seems similar to the the other MB that I've used, but with more...stuff. I'm sure I'll manage, I just wanted you to know that I'm not at all familiar with it up to this point just in case I do something that doesn't make any sense. Anyway, here goes.

 

You say that the game works fine until you enter a car and press the gas button. I'm thinking that it may be an error due to a mistake while adding the code the the scm. Using BW's MB I copied my code from this page and added it to the main.scm and it works fine. Then I tried doing the same thing except I used Sanny this time. This led to problems when I tried to compile. However, since I had a compiled scm with the code already in it, I just used Sanny to decompile it. This way everything should be Sanny compatible, I believe (syntax, labels, etc). Since this is kind of new to me I'll just post the decompiled Sanny code in hopes that this may help clear up the problem.

 

With create_threads

 

004F: create_thread @AIR 

 

 

Add above --Mission 0--

 

:AIR03A4: name_thread 'AIR' :AIR_100001: wait 50 ms 00D6: if 0256:   player $PLAYER_CHAR defined 004D: jump_if_false @AIR_10 00D6: if 00E0:   player $PLAYER_CHAR driving 004D: jump_if_false @AIR_10 03C1: 0@ = player $PLAYER_CHAR car :AIR_540001: wait 50 ms 00D6: if 0256:   player $PLAYER_CHAR defined 004D: jump_if_false @AIR_160 00D6: if 00E0:   player $PLAYER_CHAR driving 004D: jump_if_false @AIR_160 00D6: if and01F3:   car 0@ airborne 00E1:   key_pressed 0 16 004D: jump_if_false @AIR_54 0003: shake_camera 1000 04BA: set_car 0@ speed_instantly 50.0 :AIR_1270001: wait 50 ms 00D6: if or01F3:   car 0@ airborne 00E1:   key_pressed 0 16 004D: jump_if_false @AIR_10 0002: jump @AIR_127 :AIR_16001C3: remove_references_to_car 0@ // Like turning a car into any random car 0002: jump @AIR_10 

 

 

I would attempt to rewrite the code in Sanny, but I've only just installed it and I'm a bit tired right now, so hopefully this will help ensure that everything is in place as far as the mod itself is concerned. Try adding this to your main.scm and see how it goes. If it still doesn't work then I would guess that it's either improperly installed or a flaw on my part dealing with the new MB. Just take your time and be careful of careless errors. If there is still a problem someone (or myself once I learn a little more about Sanny) will try and help you out. Talk at you later Mag-got.

 

P.S.

Exactly which GTA is this code being added to anyway? Just in case anyone else comes along to help, I'll mention that I've written this code in VC. Probably doesn't matter, but anyway. See ya.

 

Edited by Knowledge Novice
Link to comment
https://gtaforums.com/topic/265854-whats-wrong/#findComment-4025105
Share on other sites

 

I don't understand why doesn't it work, everything should be correct.

It's fairly obvious what's wrong in your code, if you just read through it like the game does. Have you read any coding tutorials? You should. And as said, use local vars - in addition, car generators and car references (handles) are not the same and you can use car-related opcodes (set_car...) only with car references. The only opcode (IIRC) you can use on generators is that opcode which sets if it's turned on or off (014C).

 

Re-read your code, in the order the game does (follow jumps and read the next labels code-wise):

:AIRthread 'AIR':AIR_103C1: $AIR = player $PLAYER_CHAR carjump @AIR_2:AIR_2if0443: player $PLAYER_CHAR in_a_carelse_jump @AIR_3jump @AIR_4:AIR_3jump @AIR_2:AIR_4if01F3: car $AIR airborneelse_jump @AIR_2Camera.Shake(1000)04BA: set_car $AIR speed_instantly 50.0end_thread

 

 

If you actually read coding tutorials and coding discussions on the forums, you'd see that in label :AIR_2, if the player isn't in a car, it will begin an infinite loop that keeps jumping back to :AIR_2 (passing along the useless label :AIR_3 along the way...). You need to put at least (actually, preferably) 1 'wait' opcode, otherwise the game just keeps looping threw without stopping and can't continue. As a result, it freezes.

No matter how strong your proccessor is, if you create a Windows .bat(ch) file with this:

:Labelgoto Label

 

 

it WILL take up 99% of your CPU power (that last percent would be taken up as well, but Windows thankfully doesn't allow that) until you close that program.

 

Also important, you should use local vars, and place the if-player-driving check BEFORE you store his car...it should be obvious why. In this case, it won't cause crashes because IIRC if the target isn't in a car, the opcode will set the variable to -1. Which means it could very well crash later, at :AIR_4 (if it reaches it...), since the code has a high potential to be executing:

 

if01F3: car -1 airborne

 

...which will probably crash the game.

 

Lastly, you NEED to have safeguards - when you handle with vehicles, actors, (you will very rarely need to worry about this with objects, I suppose) and the player, before each time you use them in an opcode, you need to check that they still exist and are valid (and sometimes you have to check if they're alive/not destroyed). YES, the player too!

Thankfully, you don't actually have to put a check EACH time you access actors/vehicles. You only need to do that each time the game 'wait's (each time you use the wait opcode) - since if the game doesn't continue (like it never did with your inf loop), the actors/vehicles won't be able to die yet anyway.

For the player (it doesn't matter if you use $player_actor or $player_char in the opcodes following it, this is for both), you use the following conditional:

 

(if) player $PLAYER_CHAR defined

 

For actors-

 

(if) actor $actor_id dead

 

For vehicles-

 

(if) car $car_id wrecked;;and you may also want to check if it's sunk

 

(look up the opcode numbers).

 

You should also use 'actor' opcodes instead of 'player' opcodes, when able. If not more, it's simply better practice. Also there are at least a couple of occurences when the 'player' opcodes tend to crash in SA (unlike the 'actor' equivalents). As said, you only need the if $player_char defined check - if thats true, $player_actor will be valid as well.

 

 

Here's your code, fixed and compacted (psuedo-code):

 

:AIRthread 'AIR':AIR_1wait 1000;;checks every 1 second (1000ms == 1 sec). you may want a faster frequency (lower the wait time)if0256: player $PLAYER_CHAR defined;;checks if the player is wasted/bustedelse_jump @AIR_1if00DF: actor $PLAYER_ACTOR driving;;checks if the actor is in a car. note that this returns true even if he is in a passenger seatelse_jump @AIR_103C0: @0 = actor $PLAYER_ACTOR car;;get the player's car and store the reference in @0if01F3: car @0 airborneelse_jump @AIR_1Camera.Shake(1000)04BA: set_car @0 speed_instantly 50.001C3: remove_references_to_car @0;;if you don't do this, the car will never disappear and will stay in memory. if you have too many cars like that, random traffic will become smallerjump @AIR_1;;if you end_thread, this code won't execute anymore...you need to jump to the beginning so it keeps on executing. you may want to make sure to only have one speed set each time the car is airborne. In that case, you can only jump to the top once it has landed. something like this (if you use this, remove the 'jump' and 'remove_references' lines above)-;;;;;;;;;;;;;;;;;;:AIR_2wait 30;high priority loop. checks every 1/3 secondsif and;;if 10256: player $PLAYER_CHAR defined;;if the player is alive8119: NOT   car @0 wrecked;;AND the car isn't destroyedelse_jump @AIR_ENDif and;;if 101F3:   car @0 airborne0448:   actor $PLAYER_ACTOR in car @0;;checks if the player is still in the carelse_jump @AIR_2;;if both are true, jump to the top of the label;;if: 1.(the car is not airborne) OR 2.(the player isn't in the car) the code continues to here.:AIR_END01C3: remove_references_to_car @0jump @AIR_1;;return to the beginning

 

 

I'm writing this in the morning now so it may be a bit off.

 

Novice, your code isn't safe because it doesn't check if the car is destroyed neither if the player is still driving it (during your :AIR_2 the player might switch cars. Probably not in a normal way, but you should still accout for it in case there's another code thread that puts you quickly in a car etc or something.)

Also, your :AIR_3 check can be flipped to eliminate the jump opcode.

Edited by Bigun
Link to comment
https://gtaforums.com/topic/265854-whats-wrong/#findComment-4025536
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
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

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