Search In
• More options...
Find results that contain...
Find results in...

# simple question - how to jump if int = a certain #

## Recommended Posts

my coding is really bad - but I am learning. I have:

`0209: @0 = random_int  400  611;all cars`

but while using that it can create a car(s) that crashes the game. so how could I make it so if "@0" equals a certain number it will jump to the beginning of the thread. I have a list of car IDs that may crash the game so all I need is the code to make this work.

would this work:

`0209: @0 = random_int  400  611;all cars00D6: if  10039:   @0 ==  402 ;; integer values0039:   @0 ==  454 ;; integer values0039:   @0 ==  499 ;; integer values0039:   @0 ==  455 ;; integer values004C: jump_if_true ££CAR_SPAWN`

how do you jump if something is true? are my middle lines any good? also, what about the "00D6: if 1" line? please help me out if you know.

thanks,

TGH

Edited by ThAtSgOtTaHuRt

##### Share on other sites

if's work like this: for each condition you have you add one to the if parameter. The parameter also starts at 0. So if you have 4 conditions like you have, you want if 3. Or, if 23 if any one of them can cause it to jump, whereas with if 3 every single condition must be false for it to jump.

Also, to make a condition NOT, change the first nubmer of the opcode to an 8:

`0209: @0 = random_int  400  611;all cars00D6: if  238039:   NOT @0 ==  402;; integer values8039:   NOT @0 ==  454;; integer values8039:   NOT @0 ==  499;; integer values8039:   NOT @0 ==  455;; integer values004C: jump_if_flase ££CAR_SPAWN`

##### Share on other sites

thanks for your help, it really helped me a lot, but could you explain the

if 23 if any one of them can cause it to jump

now say if I had 33 cars in my list - what number would I use to jump if ANY ONE is false? 232?

-TGH

##### Share on other sites

i think thats better

`0209: @0 = random_int  400  611;all cars00D6: if  238039:   @0 ==  402;; integer values8039:   @0 ==  454;; integer values8039:   @0 ==  499;; integer values8039:   @0 ==  455;; integer values004C: jump_if_flase ££CAR_SPAWN0247: request_model @0`

##### Share on other sites

here is what I have in total but since my RANDOM_INT can be any car - it sometimes crashes the game. so I have a list of all boats, police vehilces, and trains that I dont want to be able to be spawned. I have 33 in the list - what "if" number would I use to include all 33 vehicles but allow ANY ONE to actiate teh jump.

`:CAR_SPAWN0001: wait 1000 ms00D6: if 100E1:   key_pressed  0   6;aim + handbrake00E1:   key_pressed  0  18;crouch + horn004D: jump_if_false ££CAR_SPAWNjf ££CAR_SPAWN0209: @0 = random_int  400  611;all cars00D6: if  232 <-------------------------------------[PROBLEM AREA]8039:   NOT @0 ==  472;; integer values8039:   NOT @0 ==  473;; integer values8039:   NOT @0 ==  493;; integer values8039:   NOT @0 ==  595;; integer values8039:   NOT @0 ==  484;; integer values8039:   NOT @0 ==  430;; integer values8039:   NOT @0 ==  453;; integer values8039:   NOT @0 ==  452;; integer values8039:   NOT @0 ==  446;; integer values8039:   NOT @0 ==  454;; integer values8039:   NOT @0 ==  416;; integer values8039:   NOT @0 ==  427;; integer values8039:   NOT @0 ==  490;; integer values8039:   NOT @0 ==  528;; integer values8039:   NOT @0 ==  407;; integer values8039:   NOT @0 ==  544;; integer values8039:   NOT @0 ==  523;; integer values8039:   NOT @0 ==  598;; integer values8039:   NOT @0 ==  596;; integer values8039:   NOT @0 ==  597;; integer values8039:   NOT @0 ==  599;; integer values8039:   NOT @0 ==  594;; integer values8039:   NOT @0 ==  441;; integer values8039:   NOT @0 ==  464;; integer values8039:   NOT @0 ==  501;; integer values8039:   NOT @0 ==  465;; integer values8039:   NOT @0 ==  464;; integer values8039:   NOT @0 ==  590;; integer values8039:   NOT @0 ==  569;; integer values8039:   NOT @0 ==  449;; integer values8039:   NOT @0 ==  537;; integer values8039:   NOT @0 ==  538;; integer values8039:   NOT @0 ==  570;; integer values004D: jump_if_false ££CAR_SPAWN0247: request model @0038B: load requested models00D6: if  00248:   model @0 available04C4: create_coordinate @1 @2 @3 from_actor \$Player_Actor offset  0.0  8.0  1.000A5: @4 = create_car @0 at  @1 @2 @302AC: set_car @4 immunities 1 1 1 1 101C3: remove_references_to_car @4;; randomizes car for next use0001: wait 2000 ms0002: jump ££CAR_SPAWN`

Edited by ThAtSgOtTaHuRt

##### Share on other sites

`:CAR_SPAWN0001: wait 1000 ms00D6: if 100E1:   key_pressed  0   6;aim + handbrake00E1:   key_pressed  0  18;crouch + horn004D: jump_if_false ££CAR_SPAWN00D6: if  68039:   NOT @0 ==  472;; integer values8039:   NOT @0 ==  473;; integer values8039:   NOT @0 ==  493;; integer values8039:   NOT @0 ==  595;; integer values8039:   NOT @0 ==  484;; integer values8039:   NOT @0 ==  430;; integer values8039:   NOT @0 ==  453;; integer values00D6: if  68039:   NOT @0 ==  452;; integer values8039:   NOT @0 ==  446;; integer values8039:   NOT @0 ==  454;; integer values8039:   NOT @0 ==  416;; integer values8039:   NOT @0 ==  427;; integer values8039:   NOT @0 ==  490;; integer values8039:   NOT @0 ==  528;; integer values00D6: if  68039:   NOT @0 ==  407;; integer values8039:   NOT @0 ==  544;; integer values8039:   NOT @0 ==  523;; integer values8039:   NOT @0 ==  598;; integer values8039:   NOT @0 ==  596;; integer values8039:   NOT @0 ==  597;; integer values8039:   NOT @0 ==  599;; integer values00D6: if  68039:   NOT @0 ==  594;; integer values8039:   NOT @0 ==  441;; integer values8039:   NOT @0 ==  464;; integer values8039:   NOT @0 ==  501;; integer values8039:   NOT @0 ==  465;; integer values8039:   NOT @0 ==  464;; integer values8039:   NOT @0 ==  590;; integer values00D6: if  48039:   NOT @0 ==  569;; integer values8039:   NOT @0 ==  449;; integer values8039:   NOT @0 ==  537;; integer values8039:   NOT @0 ==  538;; integer values8039:   NOT @0 ==  570;; integer values004D: jump_if_false ££CAR_SPAWN0247: request model @0038B: load requested models00D6: if  00248:   model @0 available04C4: create_coordinate @1 @2 @3 from_actor \$Player_Actor offset  0.0  8.0  1.000A5: @4 = create_car @0 at  @1 @2 @302AC: set_car @4 immunities 1 1 1 1 101C3: remove_references_to_car @4;; randomizes car for next use0001: wait 2000 ms0002: jump ££CAR_SPAWN`

##### Share on other sites

Or, if 23 if any one of them can cause it to jump, whereas with if 3 every single condition must be false for it to jump.

How would I change that so any ONE (one not all) would be able to jump to the start. The way you have it requires ALL of them to be false in order to jump - or does it not? Would I make it "00D6: if 26"

Edited by ThAtSgOtTaHuRt

##### Share on other sites

Yes, adding 20 to the if number makes it an OR statement, without the 20 it is AND. I think the limit on if numbers is 6 or 7 or something. Just split it up into several different if statements.

@ocram88: removing the NOT bits just makes it harder to see what is happening, as people may not notice the 8 instead of 0 as the first opcode number.

##### Share on other sites

sweet, thanks! (to all) also I have one more question that should go into another topic but I will ask it here:

I created a coordinate for which the car will spawn at. But the coordinate doesnt have an angle - every time a car spawns it points towards 0 (rotation - relative the WORLD) Is there anyway that I can always make the car face 90 from the players current location (not 90 relative to the worlds z-axis, but perpendicular to the player).

For example I want this to happen: the player is currently looking in the 45 degree (relative to the worlds z-axis) direction and the car will spawn away from the player at the angle of 135 (45 + 90) how is this possible to do?

thanks,

TGH

##### Share on other sites

Yes, adding 20 to the if number makes it an OR statement, without the 20 it is AND. I think the limit on if numbers is 6 or 7 or something.

7 and 27

Is there anyway that I can always make the car face 90 from the players current location (not 90 relative to the worlds z-axis, but perpendicular to the player).

Absolutely. Here's a rough sketch how

`var = player's z anglevar = var - 90if var<0jump if false next sectionvar = var + 360next sectionthe rest of your code here`

You can check out my car spawn mods for the specifics on how it's done with opcodes to use and all that. Remember that angles are always floats.

##### Share on other sites

*EDIT*

ok I found out how to set players z_angle and how to change the cars z_angle.

I changed what I want to do. I want the car to point towards the player. so how could I do the following:

0172: @12 = actor \$PLAYER_ACTOR z_angle

0175: set_car @4 z_angle_to @12 + 180 <--------- how do I had 180 to a var?

Edited by ThAtSgOtTaHuRt

##### Share on other sites

`0172: @12 = actor \$PLAYER_ACTOR z_angle000B: @12 +=  180.00175: set_car @4 z_angle_to @12`

EDIT: Forgot we are dealing with floats.

EDIT(2): Though, be warned. I don't think it will be this simple. (It depends on if the engine can handle angles >= 360.0.)

Edited by Zach

##### Share on other sites

wow thanks, tested and it works

*EDIT*

ALSO

is there a way to define the OPOSITE of a var?

0172: @12 = actor \$PLAYER_ACTOR z_angle

0175: set_car @4 z_angle_to -@12

^doesnt work^ - how can I just make the oposite of a var?

-TGH

Edited by ThAtSgOtTaHuRt

##### Share on other sites
It's cool to see that angles greater than 360 work. If that's the case, then in my example, instead of subtracting 90 and bothering with an if, you could just add 270

##### Share on other sites

the angles work - although, I am having the cars spawn away from me and have them drive towards me and stop next to me. they start at the correct angle (even when its more than 360) but when the angle is more than 360 the cars dont drive strait towards me they just do circles. any ideas?

this might help everyone figure it out - maybe:

`04C4: create_coordinate @1 @2 @3 from_actor \$Player_Actor offset  0.0  25.0  1.0 <---[sPAWNS HERE]04C4: create_coordinate @5 @6 @7 from_actor \$Player_Actor offset  -2.0  1.0  0.0 <---[DRIVES HERE]0172: @12 = actor \$PLAYER_ACTOR z_angle000B: @12 +=  180.0<----------------------------------------------------[POINTS CAR TOWARDS PLAYER]00A5: @4 = create_car @0 at  @1 @2 @30175: set_car @4 z_angle_to @1202AC: set_car @4 immunities 1 1 1 1 1 053F: set_car @4 tires_vulnerable  000A7: car @4 drive_to @5 @6 @7`

as we determined the car faces towards me (z_angle + 180) but when the car's z_angle ends up being more than 360 the car does circles and doesnt drive to the cords

Edited by ThAtSgOtTaHuRt

##### Share on other sites

Maybe the engine just doesn't fully work with those angles. <shrug>

Try this and see if it works:

`04C4: create_coordinate @1 @2 @3 from_actor \$Player_Actor offset  0.0  25.0  1.004C4: create_coordinate @5 @6 @7 from_actor \$Player_Actor offset  -2.0  1.0  0.00172: @12 = actor \$PLAYER_ACTOR z_angle000B: @12 +=  180.0:AngleCheck00D6: if  00033:    360.0 >= @12004D: jump_if_false ££AngleOkay000F: @12 -=  360.0;; floating-point values:AngleOkay00A5: @4 = create_car @0 at  @1 @2 @30175: set_car @4 z_angle_to @1202AC: set_car @4 immunities 1 1 1 1 1053F: set_car @4 tires_vulnerable  000A7: car @4 drive_to @5 @6 @7`

##### Share on other sites
yea, good work, a coterminal angle - I didnt even thingk of that. sure pays off to know your math! yea but now local variables change per thread - so I would have to change them to global variables. Edited by ThAtSgOtTaHuRt

##### Share on other sites
Local variables change per thread, not per label, so that code will work.

##### Share on other sites

ohhh. could you define the difference between thread and lable - so I can get a better understanding and be able to tell the difference. like I said in the beginning - I just started coding. I caught on quick though tutorials and such, but have yet to learn some of the basics.

also could you explain these (what they do), it might help me with the thread\lable concept:

`03A4: name_thread 'NAME'-and-004F: create_thread ££NAME-and-jf ££NAME-and-004E: end_thread`

THANKS for all your help, I really appreciate it.

Edited by ThAtSgOtTaHuRt

##### Share on other sites

In a way, you answered your own question. Basic programming sees line numbers. In SCM, they're called labels because they don't have to be numbers. Name them what makes them easy for you and the compiler will convert them to how the game thinks of it.

Labels are ways of dividing a thread up. Any time you need to be able to jump to a particular part of the code, you will need a label to reference to (not always true, but only CyQ knows how to otherwise ). The most common occurance of this is

`label 1if (some check)jf label 2stuff to run only if the check is truelabel 2stuff that runs after the check regarless of whether it was true or not`

or

`label 1if (some check)jf label 2stuff to run only if the check is truejump label 3label 2stuff to run only if the check is falselabel 3stuff to run after the above regardles of whether it was true or not`

All jumps and whatnot refer to labels. In fact, outside of creating, ending, and naming a thread, you'll never refer to the thread itself. And I'm not even sure naming the thread has any real use.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×