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

parvez

help me to improve this code

Recommended Posts

parvez

{$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

Share this post


Link to post
Share on other sites
Sloth-

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-

Share this post


Link to post
Share on other sites
parvez
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

Share this post


Link to post
Share on other sites
Sloth-

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-

Share this post


Link to post
Share on other sites
parvez

for which game do you created this code

 

Share this post


Link to post
Share on other sites
Sloth-

GTA San Andreas, of course! :colgate:

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

Edited by Sloth-

Share this post


Link to post
Share on other sites
parvez

sorry it's my mistake

please make code for gta vc

 

Share this post


Link to post
Share on other sites
Sloth-

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-

Share this post


Link to post
Share on other sites
parvez

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

Share this post


Link to post
Share on other sites
parvez

 

 

 

i don't know how can i thank to you

Share this post


Link to post
Share on other sites
Sloth-

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-

Share this post


Link to post
Share on other sites
parvez

{$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  

Share this post


Link to post
Share on other sites
Sloth-
Posted (edited)

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-

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.