Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. Los Santos Drug Wars
      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. Forum Support

    3. Suggestions

help me to improve this code


parvez
 Share

Recommended Posts

{$CLEO .cs}
0000:
:a1
wait 0
0247: request_model #HFOBE
0247: request_model #CHEETAH 
038B: load_requested_models 
0248:   model #HFOBE available
0248:   model #CHEETAH available 
004D: jump_if_false @a1
jump @a2
:a2
[email protected] = Actor.CurrentCar($player_actor)
009A: [email protected] = create_actor_pedtype 4 model #HFOBE at 330.4796 -1264.8765 11.0712
0187: [email protected] = create_marker_above_actor [email protected]
0173: set_actor [email protected] z_angle_to $player_actor
wait 10000  
repeat
wait 0
until Actor.InCar([email protected], [email protected])
Marker.Disable([email protected]
end_thread

 

 

 

 

i want to put actor in car of player

but this is not working

please help me

Link to comment
Share on other sites

First of all, i suggest you to get used to a high level sintax. Just replace expressions like this:

 

Spoiler
Quote

:a1
wait 0
0247: request_model #HFOBE
0247: request_model #CHEETAH 
038B: load_requested_models 
0248:   model #HFOBE available
0248:   model #CHEETAH available 
004D: jump_if_false @a1

 

 

With this:

Spoiler

 

Quote

repeat
wait 0
0247: request_model #HFOBE
0247: request_model #CHEETAH 
038B: load_requested_models 

until 0248:   model #HFOBE available and 0248:   model #CHEETAH available

Both blocks do exactly the same, but last one is easier to read.

 

Second: you shouldn't call "request_model" instruction inside the loop, instead, call it before the loop:

 

Spoiler

 

Quote

0247: request_model #HFOBE
0247: request_model #CHEETAH 
038B: load_requested_models 

 

repeat
wait 0
until 0248:   model #HFOBE available and 0248:   model #CHEETAH available

 

Third: i will rewrite your full code in high level in order to let you seeing and comparing, and i'll fix some mistakes (the code could still have errors, but at least it's more readable):

Spoiler
Quote

{$CLEO .cs}
thread 'ChooseName'  // <-- use this instead of "0000: NOP", because of best practice

 

0247: request_model #HFOBE
0247: request_model #CHEETAH 
038B: load_requested_models 

 

repeat
wait 0
until 0248:   model #HFOBE available and 0248:   model #CHEETAH available 

{{===jump @a2
:a2===}} // <----- you don't need this at all

 

repeat

wait 0

    [email protected] = Actor.CurrentCar($player_actor)

    {{

        you first need to validate the [email protected] as a true car

        if your code calls this instruction "[email protected] = Actor.CurrentCar($player_actor)" in a moment

        when the player is not in a car, then [email protected] will not be anything, and therefore if

        you call instructions handling it as a car, the game will crash

    }}

    if 056E:   car [email protected] defined // i don't know if this could work too:  "if not [email protected] == -1"

    then

        009A: [email protected] = create_actor_pedtype 4 model #HFOBE at 330.4796 -1264.8765 11.0712
        0187: [email protected] = create_marker_above_actor [email protected]
        0173: set_actor [email protected] z_angle_to $player_actor

        // you should release requested models at this point with opcode 0249 because you aren't going to need them anymore

       

        break

        // notice that i gave a "false" as condition to end loop, so it will never end, unless of course, execution reaches this "break" line
    end

until false

 

wait 10000 // <-- you are trying to use this wait to give actor [email protected] time to enter the car, aren't you?

// but it's totally unnecessary since you are using a loop whose end condition is the actor aboarding the car

 

// you should give the actor [email protected] some instruction to enter the car [email protected] or else he is never going to... i think

 

repeat
wait 0
until Actor.InCar([email protected], [email protected])


Marker.Disable([email protected]

0A93: end_custom_thread  // use this instead of "end_thread" for CLEO threads

 

 

Hope this helps.

 

Also, i suggest you to read sanny builder help section, specifically the "coding" section. It covers the high level sintax for conditionals and loops.

The decompiled main.scm can teach you a lot about how doing everything in SCM. You just need to learn how to read it.

Tip: you really don't need to understand everything, simply go to missions that do stuff that you want to know how to do it, then go for the specific lines.

Good thing is that SCM opcodes are very self explanatory, so you shouln't have problems finding what you need.

 

Or you can search for specific opcodes inside the main.scm in order to study the context in which those are used and learn how to use them.

 

You can always ask here if you feel too much confused of course!

Edited by Sloth-
Link to comment
Share on other sites

20 hours ago, Sloth- said:

First of all, i suggest you to get used to a high level sintax. Just replace expressions like this:

 

  Hide contents

 

 

With this:

  Hide contents

 

Both blocks do exactly the same, but last one is easier to read.

 

Second: you shouldn't call "request_model" instruction inside the loop, instead, call it before the loop:

 

  Hide contents

 

 

Third: i will rewrite your full code in high level in order to let you seeing and comparing, and i'll fix some mistakes (the code could still have errors, but at least it's more readable):

  Hide contents

 

 

Hope this helps.

 

Also, i suggest you to read sanny builder help section, specifically the "coding" section. It covers the high level sintax for conditionals and loops.

The decompiled main.scm can teach you a lot about how doing everything in SCM. You just need to learn how to read it.

Tip: you really don't need to understand everything, simply go to missions that do stuff that you want to know how to do it, then go for the specific lines.

Good thing is that SCM opcodes are very self explanatory, so you shouln't have problems finding what you need.

 

Or you can search for specific opcodes inside the main.scm in order to study the context in which those are used and learn how to use them.

 

You can always ask here if you feel too much confused of course!

thanks bro

but it did not worked

 

Edited by parvez
Link to comment
Share on other sites

I checked, and yes i found several mistakes.

I'll put the fixed code with some commentaries (i will remove previous commentaries in this one):

 

Spoiler
{$CLEO .cs}
thread 'ChooseName'

0247: request_model #HFORI
0247: request_model #CHEETAH
038B: load_requested_models

repeat
wait 0
until 0248:   model #HFORI available and 0248:   model #CHEETAH available

repeat
wait 0
    0811: [email protected] = actor $PLAYER_ACTOR used_car // best to use opcode 0811 instead of this "[email protected] = Actor.CurrentCar($player_actor)"
    if 056E:   car [email protected] defined
    then
        009A: [email protected] = create_actor_pedtype 4 model #HFORI at 330.4796 -1264.8765 11.0712
        0187: [email protected] = create_marker_above_actor [email protected]
        //0173: set_actor [email protected] z_angle_to $player_actor // <-- this opcode only accepts floats, "$player_actor" is not a valid parameter
        0249: release_model #HFORI
        0249: release_model #CHEETAH
        break
    end
until false

// Added this to check when player is close enough to actor before give that actor the instruction to get in the car
repeat
wait 0
until 00F2:   actor [email protected] near_actor $PLAYER_ACTOR radius 20.0 20.0 sphere 0

0AD1: show_formatted_text_highpriority "Finally you arrived!" time 2000
05CA: AS_actor [email protected] enter_car [email protected] passenger_seat 0 time -1

repeat
wait 0
until Actor.InCar([email protected], [email protected])

Marker.Disable([email protected])
0A93: end_custom_thread

 

This code is still not fully optimized. I leave that to you, because that depends on what do you want to do exactly.

 

Some extra notes:

 

1. Previously, you've been requested this model #HFOBE, but it really doesn't exist, so i replaced by #HFORI

2. In my previous code, i was making multiline commentaries with {{ ... }}, but i forgot it was only singles { ... }

 

3. Please, take a look at this carefully:

 

You were using SCM classes to capture the vehicle owned by the player [email protected] = Actor.CurrentCar($player_actor)

I noticed this wasn't working as i expected, because always returned a valid vehicle (even if i was on foot!).

 

So, what did i do? check directly the opcode that captures the car.

Go to Sanny Builder Menu > Tools > IDE tools > Opcode search...

Enter following keywords in search bar: "actor car"

 

The first opcode i found was this:

00D9: [email protected] = actor $PLAYER_ACTOR car // add to mission cleanup

But it also wasn't working as i expected. While "[email protected] = Actor.CurrentCar($player_actor)" always returned a false valid car, 00D9 never returned a valid car (even when i entered in the car).

 

I searched that opcode in the decompiled main.scm, and after a while i noticed this:

00D9: [email protected] = actor $PLAYER_ACTOR car // mission only 

It says in the comment: "mission only"

 

So i got really confused because i thought this was the only "capturing aboarded car" opcode, so i searched in google "opcode 00D9", and in the very first page i found (https://gtagmodding.com -opcode database-), it says:

 

Quote

This opcode also works in normal scripts, however a lot of code is based on missions, so it is better to use 03C0 or 0811 depending on the situation.

And that way i realized the opcode i needed was

0811: [email protected] = actor $PLAYER_ACTOR used_car

 

The reason i tell you all of this is because you need to learn how to solve problems by yourself. So i'm showing a possible methodology.

You can always find people here in the forums that can help, but you aren't going too far as a coder if you are going to need help for every single problem you find...

 

 

Tip: i don't recommend too much the use of SCM classes.

The reason? I find them incomplete, and few documented. The opcodes, in the other hand, have a lot of documentation, and you even have a very comfy search system integrated in the sanny builder for opcodes. Just get used to the keywords:

 

Do you need to create an actor? search "actor create"

Do you need to create an object? search "object create"

Do you need to load models? search "model load" (you could think of the keyword "request", but you are not going to find it that way)

Do you need to check if an actor is on certain coordinates? search "actor in sphere"

 

Other common searches (self explanatory, i think): "destroy actor", "destroy object", "release model", "model available", "actor remove references", "car remove references", "actor in car", "actor driving", "actor put at", "car put at", "create checkpoint", "marker actor", "marker car", "disable marker".

 

Searches not so self explanatory:

"lowp", "highp" (for displaying lowpriority/highpriority gxt texts)

"text box" (for displaying those help texts, that appears in the left-superior corner)

"draw text" (for custom position and dimensions texts)

"styled" (for special texts, like those that shows the beggining mission, or the "passed mission", or the "failed mission")

 

There are certain special opcodes that order actors to perform certain actions: search those with keyword "AS_actor".

 

With a little practice, you will get a lot familiarized with opcodes in general. But there are certain opcodes hard to manage or understand, because they are unknown for the community.

 

Read tutorials if you still feel confused.

Spoiler

 

 

Feel free to ask anyways if you still have problems. :lol:

Edited by Sloth-
Link to comment
Share on other sites

GTA San Andreas, of course! :colgate:

Don't tell me you were talking about III or VC...

Edited by Sloth-
Link to comment
Share on other sites

Here you go:

Spoiler
{$CLEO .cs}
thread 'ChooseN' // <-- can't be larger than 7 characters

wait 1000

0247: request_model #HFOBE
0247: request_model #CHEETAH
038B: load_requested_models

repeat
wait 0
until 0248:   model #HFOBE available and 0248:   model #CHEETAH available

00BB: text_lowpriority 'TEST1' 3000 ms 1 // Go find a car!

repeat
wait 0
    03C0: [email protected] = actor $PLAYER_ACTOR car 
    if [email protected] > 0
    then
        009A: [email protected] = create_actor_pedtype 4 model #HFOBE at 330.4796 -1264.8765 11.0712
        0187: [email protected] = create_marker_above_actor [email protected]
        //0173: set_actor [email protected] z_angle_to $player_actor // <-- this opcode only accepts floats, "$player_actor" is not a valid parameter
        0249: release_model #HFOBE
        0249: release_model #CHEETAH
        00BB: text_lowpriority 'TEST2' 3000 ms 1 // Go and pick up the actor...
        break
    end
until false

// Added this to check when player is close enough to actor before give that actor the instruction to get in the car
repeat
wait 0
until 00F2:   actor [email protected] near_actor $PLAYER_ACTOR radius 20.0 20.0 sphere 0

00BB: text_lowpriority 'TEST3' 2000 ms 1 // Finally you arrived!
01D4: actor [email protected] go_to_car [email protected] and_enter_it_as_a_passenger 

repeat
wait 0
until Actor.InCar([email protected], [email protected])

Marker.Disable([email protected])
05DC: end_custom_thread

 

 

You must create a file *.fxt and place inside VC folder/cleo/cleo_text in order to watch the texts displayed:

Spoiler
TEST1	Go find a car!
TEST2	Go and pick up the actor...
TEST3	Finally you arrived!

TEST4	Car: ~1~

 

 

Everything i said before still applies to GTA III and VC, but opcode keywords can change.

Edited by Sloth-
Link to comment
Share on other sites

many many.......

thanks to you

thank you 

thank you😂😂😂

i wnt one more help from you

 

 

can you please make a car spawner for gta vc

if you don't like 

don't make it 

i don't force you

please

Link to comment
Share on other sites

There are already spawning cars mods out there.... Is something like this what you want?

Spoiler

 

 

Here's another one:

Spoiler

 

Download links on the description.

Edited by Sloth-
Link to comment
Share on other sites

  • 2 weeks later...

{$CLEO .cs}
0000:nop
:a1
0247: request_model #INFERNUS 
038B: load_requested_models 
0248:   model #INFERNUS available 
004D: jump_if_false @a1 
04C4: create_coordinate [email protected] [email protected] [email protected] from_actor $player_actor offset 5.0 3.2 0.0 
0002: jump @a2 
:a2
repeat
wait 0
until 0AB0: key_pressed 35
00A5: [email protected] = create_car #INFERNUS at [email protected] [email protected] [email protected]
0249: release_model #INFERNUS
04C1: remove_references_to_car
jump @a1

 

i created this mod for spawning (infernus) in gta vice city on key presssed end key

but when i press end key the game spawns more than one infernus

please help me to improve this code  

Link to comment
Share on other sites

Common mistake all of us make: you wait until player has pressed key to do your spawning. After that you repeat cicle and wait again until player has pressed key.

Problem is that all of this happens so fast that when your code reaches the "repeat until pressed key" for the second time, player has not released the key the first time. Result: the car spawns again and again.

 

To avoid it:

Spoiler
{$CLEO .cs}
0000:nop
:a1
0247: request_model #INFERNUS 
038B: load_requested_models 
0248:   model #INFERNUS available 
004D: jump_if_false @a1 
04C4: create_coordinate [email protected] [email protected] [email protected] from_actor $player_actor offset 5.0 3.2 0.0 
0002: jump @a2 
:a2
repeat
wait 0
until 0AB0: key_pressed 35
00A5: [email protected] = create_car #INFERNUS at [email protected] [email protected] [email protected]
0249: release_model #INFERNUS
04C1: remove_references_to_car

repeat
wait 0
until 8AB0: not key_pressed 35 // wait until key has released

jump @a1 

 

 

Other commentaries, if you're interested:

1.

Spoiler
04C1: remove_references_to_car

What are you exactly doing here?

 

Maybe what you really wanted was this?:

01C3: remove_references_to_car [email protected]

 

 

2.

Spoiler

Again: you are requesting the models inside the loop:

:a1
0247: request_model #INFERNUS 
038B: load_requested_models 
0248:   model #INFERNUS available 
004D: jump_if_false @a1 

Apparently, the engine doesn't have problems with this, but is the best practice to require models only once:

0247: request_model #INFERNUS 
038B: load_requested_models 

:a1
0248:   model #INFERNUS available 
004D: jump_if_false @a1 

Maybe you'll face problems in other scenarios if you don't have this in mind.

 

3.

Spoiler
04C4: create_coordinate [email protected] [email protected] [email protected] from_actor $player_actor offset 5.0 3.2 0.0 
0002: jump @a2 
:a2
repeat
wait 0
until 0AB0: key_pressed 35
00A5: [email protected] = create_car #INFERNUS at [email protected] [email protected] [email protected]

You are first storing current player coordinates (with an offset), and then you wait until player press key.
That means, player could move, and go anywhere, but your spawn location will not move at all. If you begin your script in Ocean Beach (for example), and you move to a far locaton (Downtown/Little Havanna or whatever), and press the key, you will not see anything, because your spawn location is in the previous point created in Ocean Beach.

 

To fix that, move the create_coordinate command after the key_press check:

0002: jump @a2 
:a2
repeat
wait 0
until 0AB0: key_pressed 35
04C4: create_coordinate [email protected] [email protected] [email protected] from_actor $player_actor offset 5.0 3.2 0.0 
00A5: [email protected] = create_car #INFERNUS at [email protected] [email protected] [email protected]

And then, you'll always spawn the car where the player goes!

 

I haven't tested this script so i can't guarantee it will work at 100% as you wish.

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