Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    5. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA IV Mods
    6. GTA Chinatown Wars

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA SA Mods
    10. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA VC Mods
    11. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA III Mods
    12. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. News

    2. Forum Support

    3. Site Suggestions

herrhund

Tankers with Trailer in Traffic

Recommended Posts

herrhund

Hi, i try to make a code, but it doesn't work....

With the code every Tanker in the Traffic near the player should get a trailer attached....

I tried so many things but either the game crashes or the Mission Builder....

This is the code it have, could you please have a look @ it?

I know now there are many Mistakes but i tried so long and i hoped the game won't crash anymore, so I changed my code a few times tounge.gif

Sry for my bad English wink.gif

 

 

:LabelBus0001: wait  50 ms04C4: create_coordinate [email protected] [email protected] [email protected] from_actor $player_actor offset  30.0  30.0  0.004C4: create_coordinate [email protected] [email protected] [email protected] from_actor $player_actor offset  -30.0  -30.0  0.00005: $VT = -1 ;; floating-point values 053E: $VT = get_random_car_with_actors -1 in_area [email protected] [email protected] [email protected] [email protected]: if  0  8039:   NOT   $VT == -1 ;; integer values0137:   car $VT id == #Petrol004D: jump_if_false ££LabelLabelBus 00D6: if  007AB:   car -1 attached_to_car @327  004D: jump if false ££Labelattach0002: jump ££Labelbus:Labelattach0001: wait  5 ms0247: request model #petrotr038B: load requested models00A5: $anh = create_car #Petrotr at  0.0  0.0  0.00249: release model #petrotr0893: put_trailer $anh on_cab $VT0002: jump ££Labelbus

 

Share this post


Link to post
Share on other sites
Quadropheniac90
I don't know, never tried to do something like that, but don't you think it's possible to assign an external script to all heavy trucks, and create a trailer 50 coords above them and then attach them. Don't know about external scripts for cars though, I'm gonna try something, I'll get back to you.

Share this post


Link to post
Share on other sites
mbell

Some problems that I see offhand:

 

Unless you're using something other than BW's Mission Builder 0.33, the @ should go before your var numbers.

 

 

053E: $VT = get_random_car_with_actors -1 in_area [email protected] [email protected] [email protected] [email protected]

 

This opcode expects coordinates as X1, Y1, X2, Y2. You're giving it X1, Y1, Y2, Z2. Use @0 @1 @3 @4 instead.

 

 

07AB:   car -1 attached_to_car @327

 

I'm not sure of the syntax of this opcode, and whether or not it can take a -1 as a parameter. Instead of @327 at the end, you need $VT to check if something is attached to the tanker in question.

 

You need a loop that waits to see if the model you requested has been loaded. Use something like this after your load_requested_models

 

:LabelAttachLoad0001: wait  0 ms00D6: if  00248:   model #Petrotr available004D: jump_if_false ££LabelAttachLoad

 

 

Finally, there may be an issue with the fact that you're spawning the trailer at 0.0,0.0,0.0. Does the attach code pull the trailer from where it is and attach it to the cab? If not, you should use create_coordinate from_car with an offset to spawn the trailer somewhere near the cab.

Share this post


Link to post
Share on other sites
herrhund

Ok, let me edit this bugs tounge.gif

I hope it's correct now, but now i can't compile it dontgetit.gif

Could anyone of you try it, plz?

 

 

:LabelBus

0001: wait  50 ms

04C4: create_coordinate [email protected] [email protected] [email protected] from_actor $player_actor offset  30.0  30.0  0.0

04C4: create_coordinate [email protected] [email protected] [email protected] from_actor $player_actor offset  -30.0  -30.0  0.0

0005: $VT = -1 ;; floating-point values

053E: $VT = get_random_car_with_actors -1 in_area [email protected] [email protected] [email protected] [email protected]

00D6: if  0 

8039:  NOT  $VT == -1 ;; integer values

0137:  car $VT id == #Petrol

004D: jump_if_false ££LabelLabelBus

 

00D6: if  0

07AB:  car -1 attached_to_car $VT 

004D: jump if false ££Labelattach

0002: jump ££Labelbus

 

:Labelattach

0001: wait  5 ms

0247: request model #petrotr

:LabelAttachLoad

0001: wait  0 ms

00D6: if  0

0248:  model #Petrotr available

004D: jump_if_false ££LabelAttachLoad

038B: load requested models

00A5: $anh = create_car #Petrotr at  0.0  0.0  0.0

0249: release model #petrotr

0893: put_trailer $anh on_cab $VT

0002: jump ££Labelbus

Share this post


Link to post
Share on other sites
Demarest

You have an if 2 conditionals, but the operand is 0. Use 1 or 21 depending on how you'd like to argue them. However, you won't need to becuase you don't need the -1 check. If it's #petrol, it won't be -1. You should have an if player defined check before executing the offset from player commands. -1 cannot be a car value and locals as high as 327 can only be used during missions. Again, won't matter because I don't even know what you're checking for there. You could negate that conditional to avoid having double jumping. Also, has 0893 been discovered yet? I checked the database and it's unlisted and I don't remember reading that in the opcode thread. It didn't compile because you still hadn't done what mbell said about the @s. Also, you want the load requested models BEFORE checking to see if they're loaded.

 

:LabelBus0001: wait  50 ms00D6: if  00256:   player $PLAYER_CHAR defined004D: jump_if_false ££LabelBus04C4: create_coordinate @0 @1 @2 from_actor $player_actor offset  30.0  30.0  0.004C4: create_coordinate @3 @4 @5 from_actor $player_actor offset  -30.0  -30.0  0.0053E: @6 = get_random_car_with_actors -1 in_area [email protected] [email protected] [email protected] [email protected]: if  0 0137:  car @6 id == #Petrol004D: jump_if_false ££LabelLabelBus0247: request model #petrotr038B: load_requested_models:LabelAttachLoad0001: wait  0 ms00D6: if  00248:  model #Petrotr available004D: jump_if_false ££LabelAttachLoad00A5: @7 = create_car #Petrotr at  0.0  0.0  0.00249: release model #petrotr0893: put_trailer @7 on_cab @60002: jump ££Labelbus

 

Edited by Demarest

Share this post


Link to post
Share on other sites
herrhund

Ok, i see.... I didn't finish the script because the Mission Builder refused to compile..... cryani.gif

Now i tried your fixed Script and he says "Internal Error Script Type not set"

 

To 0893:

The Opcodes.txt says:

0893: put_trailer @37 on_cab @34

 

And i found this in the DB "P: $trailerID, $carID

- Puts trailer on truck cab. Use right vehicles or funky effects will happen."

Share this post


Link to post
Share on other sites
mbell

Close the main.txt file, and reopen it. In the open file dialog, make sure Open as main script is checked (in the lower left). Then try compiling. If that doesn't work, close SAMB entirely, restart it, and follow the above instructions.

Share this post


Link to post
Share on other sites
Demarest
You'll only get that message for brand new scripts and/or ones loaded from the recently open menu. mbell's step-by-step will get around that.

Share this post


Link to post
Share on other sites
Quadropheniac90
I think that should be @1. Local vars should work if I'm right.

Share this post


Link to post
Share on other sites
Quadropheniac90
Oh, yeah, that's it, it should be @0 instead of [email protected] biggrin.gif

Share this post


Link to post
Share on other sites
Demarest
In original code, the -1 is there. Don't know why, but it's there. Not sure why it's been mentioned twice now about the @s coming ahead of the number and we're still talking about it, but maybe you should read the Builder readme before you continue. Will take you about 10-15 minutes, but will spare you countless "little" mistakes like this, let alone making them repeatedly after being told to correct them.

Share this post


Link to post
Share on other sites
herrhund

Ok, my mistake... I copied some parts of the code from my other code for VC.... Now I have this:

 

 

:LabelBus

0001: wait  50 ms

00D6: if  0

0256:  player $PLAYER_CHAR defined

004D: jump_if_false ££LabelBus

04C4: create_coordinate @0 @1 @2 from_actor $player_char offset  30.0  30.0  0.0

04C4: create_coordinate @3 @4 @5 from_actor $player_char offset  -30.0  -30.0  0.0

;00A0: store_actor $PLAYER_char position_to $xpos $ypos $zpos

053E: @6 = get_random_car_with_actors -1 in_area @0 @1 @3 @4

00D6: if  0

0137:  car @6 id == 514

004D: jump_if_false ££LabelBus

 

 

:LabelAttachLoad

0001: wait  0 ms

00D6: if  0

0248:  model 608 available

004D: jump_if_false ££LabelAttachLoad

00A5: @7 = create_car 608 at  0.0  0.0  0.0

0249: release model 608

0893: put_trailer @7 on_cab @6

0002: jump ££Labelbus

 

and the game chashes after Loading sad.gif

Share this post


Link to post
Share on other sites
Opius

That's because you assume that once the opcode is run, @6 will contain a vehicle. Sometimes (all the time, with your code), no vehicle will be assigned to that variable.

 

Solution:

Set @6 to -1 before running the get_car opcode, then after it's run, check if it still is -1. If it ISN'T -1, then a car was found and assigned, and it's safe to continue execution. If it still is -1, jump back to the top and try again.

Share this post


Link to post
Share on other sites
Demarest

Originally he did. I was the one who pulled it out.

 

Your new code is missing the request model command.

Share this post


Link to post
Share on other sites
ZAZ

Is it possibble to release the model 608 and after that to command it again by @7 ?

 

00A5: @7 = create_car 608 at  0.0  0.0  0.0

0249: release model 608

0893: put_trailer @7 on_cab @6

0002: jump ��Labelbus

 

Share this post


Link to post
Share on other sites
Demarest
Yes. @7 is the object in the game world. The model is only needed to create it. To discard it once you're done using it is smart. It would crash the game if the release model command was instead remove references to @7. I hope that makes sense.

Share this post


Link to post
Share on other sites
ZAZ

 

I hope that makes sense.

Oh yes, thanks for teaching, Demarest.

__________________________________

 

Oh, I saw that You release the models in this thread

Why did You do so, when You destroy them at the end ?

Edited by ZAZ

Share this post


Link to post
Share on other sites
mbell

There are 3 separate actions that you may be confusing:

 

Releasing the models frees up memory for loading other models that the engine wants (such as all of the other junk on the streets around you). This has no visible effect on the game. However, if you've created any instances of the model, they will remain after you release the model (in this case, the trailer, @7).

 

Destroying an object (which is done by a variable, not a generic model type) removes it from the game instantly.

 

Removing references to an object will cause the engine to remove the object whenever it's most convenient to do so. Usually this means that if you look away for a while, or drive a block away, the object will disappear, and any variable references to it will become invalid. Attempting to use a reference after this command is bad, and will most likely cause a crash (unless you get lucky and your use of the reference occurs before the object is removed).

 

Thus, the usual sequence of events should be the following:

-request model (say #FIRETRUK), wait until it's loaded

-create instance (call it @1 for now)

-release model (#FIRETRUK)

-do stuff with @1

-when @1 is no longer needed, you have 2 options:

a) Destroy @1 instantly

b) Remove references to @1

-in either case, you should not attempt to do anything else with @1 after this point

Share this post


Link to post
Share on other sites
Demarest
Oh, I saw that You release the models in this thread

Why did You do so, when You destroy them at the end ?

That was my revision of somebody else's code. When I do that, I sometimes reproduce the errors of others. But mbell has explained it rather well smile.gif

Share this post


Link to post
Share on other sites
Un3462

hmm.

 

first of all, an external script is probably a better idea for this, but i don't know if the opcode that attaches one to a car model has been found yet (it's bound to exist though).

 

second, if you're going to do it as a normal thread;

- just set the get_car for the whole world. should be -3000.0,-3000.0,3000.0,3000.0 or something.

- the -1 means "any model" for the get_car opcode, iirc. so just set that to 514 (or better yet, the name from the ide), and remove the check that follows.

- you're going to quickly fill up the mission car list with this. you could remove references to the car after adding the trailer, but then you'd probably get it again with the next get_car. i can think of some solutions but they'd all get pretty complex.

Share this post


Link to post
Share on other sites
ZAZ

 

Releasing the models frees up memory for loading other models that the engine wants

Is it important to release the models ? I scripted much stuff without release and had no problems.

Is it important to release special in Demarests animation thread ?

 

Share this post


Link to post
Share on other sites
mbell

 

But mbell has explained it rather well smile.gif

Thanks smile.gif

 

@ZAZ: You can get away with not releasing models up to a point, but it's good practice to release them to avoid running out of memory. (I'm assuming that it'd be possible to eventually crash the game by requesting too many models). I'm not sure which release special you're referring to...if it's the release of a special ped model, then yes, it's important to do it, just as with releasing anything else.

Share this post


Link to post
Share on other sites
Demarest
- just set the get_car for the whole world. should be -3000.0,-3000.0,3000.0,3000.0 or something.

I thought the boudaries were 4000 in any direction. Could be wrong. Still, the game isn't even generating traffic except in your immediate vicinity. Why make it larger than it needs to be?

 

@ZAZ: Where do I have an animation thread? Also, as explained many times before, just because something works, does not make it right. If you hold models in memory longer than you need to, even things like traffic patterns can be disrupted. As for remove references, not doing that keeps them in the game FOREVER. That can pile up in no time.

Share this post


Link to post
Share on other sites
Un3462
I thought the boudaries were 4000 in any direction. Could be wrong. Still, the game isn't even generating traffic except in your immediate vicinity. Why make it larger than it needs to be?

because calculating the area around the player takes up time and space? checking the whole map doesn't influence performance negatively, since it just loops through a list of cars, which is the same size whether you check the entire map or just a 1x1 square around the player.

Share this post


Link to post
Share on other sites
ZAZ

 

@ZAZ: Where do I have an animation thread?

Pardon for wrong description. I refered to here and here

 

Share this post


Link to post
Share on other sites
Demarest
the whole world. should be -3000.0,-3000.0,3000.0,3000.0 or something.

blush.gif I apologize for the off-topic, but the useable world is about 3000 in all 4 directions. From day one of haing access to the SA files, I've thought it was 4000. Somebody explain to me how I make it this far along before finally realizing this? blush.gif indeed.

Share this post


Link to post
Share on other sites
Yegorchic

Hello everybody!

 

Sorry for my bad English...

 

I got code of "Tankers with Trailer in Traffic" and edited it...

 

 

:LabelBus0001: wait  100 ms00D6: if  00256:   player $PLAYER_CHAR defined004D: jump_if_false ££LabelBus04C4: create_coordinate $p0 $p1 $p2 from_actor $PLAYER_ACTOR offset  170.0  170.0  0.004C4: create_coordinate $p3 $p4 $p5 from_actor $PLAYER_ACTOR offset  -170.0  -170.0  0.0053E: $ecar = get_random_car_with_actors -1 in_area $p0 $p1 $p3 $p400D6: if  08038:   NOT   $ecar ==  -1;; !!!!!!!!!! [b]Here we MUST check car, if var."ecar" is "-1" then we haven't car...[/b]004D: jump_if_false ££LabelBus00D6: if  0                     0137:   car $ecar id == #PETRO004D: jump_if_false ££LabelBus0247: request model 584038B: load_requested_models  :LabelAttachLoad0001: wait  0 ms00D6: if  00248:  model 584 available004D: jump_if_false ££LabelAttachLoad      ;;!!!!!!!!! Here we must check, is this car have "Trailer"...0407: create coordinate $r0 $r1 $r2 from car $ecar offset 10.0  10.0  0.0;;!! We got coordinates0407: create coordinate $r3 $r4 $r5 from car $ecar offset -10.0  -10.0  0.0053E: $ecar2 = get_random_car_with_actors -1 in_area $r0 $r1 $r3 $r4  ;;!! got a car in area near "ecar"00D6: if  08038:   NOT   $ecar2 ==  -1 ;;!! Check var. "ecar2"004D: jump_if_false ££LabelBus00D6: if  0 8137:   NOT   car $ecar2 id == #PETROTR ;;!! If "ecar" is "Trailer" we jump at "LabelBus"004D: jump_if_false ££LabelBus 00A5: $new_trailer = create_car 584 at  0.0  0.0  10.0  ;; !! If "ecar" isn't "Trailer" we create trailer and attach it...0249: release model 5840893: put_trailer $new_trailer on_cab $ecar01C3: remove references to car $ecar;; we must free all vars01C3: remove references to car $ecar201C3: remove references to car $new_trailer0002: jump ££Labelbus

 

Share this post


Link to post
Share on other sites
Opius

$ecar isn't automatically set to -1 if the check doesn't return a car. It will stay unitialised and more than likely crash the game since the next check will return true.

 

Do it like this. (Pseudocode)

 

$ecar = -1053E: $ecar = get_random_car_with_actors -1 in_area $p0 $p1 $p3 $p400D6: if  08038:   NOT   $ecar ==  -1;; !!!!!!!!!! [b]Here we MUST check car, if var."ecar" is "-1" then we haven't car...[/b]004D: jump_if_false ££LabelBus

 

 

This way, $ecar will STAY -1 if a car isn't found.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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


  • 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.