Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      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. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

[GTASA]Spawn Random Enemy Ped, but won't disappear when player far


DoubleVision
 Share

Recommended Posts

DoubleVision

I'm trying to have a Random Ped spawn. I want it to dissapear quickly when it dies, and I want it to dissapear when I leave the area the ped is. But, I don't know how to have it dissappear after I leave its area. At the moment it spawns with a key press. Afterwards I'll have it spawn automatically.

 

004F: create_thread @RANDOMP_1 ///spawn random enemy ped

:RANDOMP
03A4: name_thread 'RANDOMP'

:RANDOMP_1
0001: wait 0 ms
00D6: if and
not actor.Dead($PLAYER_ACTOR)
not actor.Driving($PLAYER_ACTOR)
00E1: player 0 pressed_key 8 ///d-pad up
004D: jump_if_false @RANDOMP_1
04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 3.0 1.0
0376: [email protected] = create_random_actor_at [email protected] [email protected] -100.0
0332: set_actor [email protected] bleeding 1
0245: set_actor [email protected] walk_style_to "DRUNKMAN"
0223: set_actor [email protected] health_to 1000
0A09: set_actor [email protected] muted 1 // versionB
060B: set_actor [email protected] decision_maker_to 65536
0446: set_actor [email protected] dismemberment_possible 0
04D8: set_actor [email protected] drowns_in_water 0
0946: set_actor [email protected] actions_uninterupted_by_weapon_fire 1
07DD: set_actor [email protected] attack_rate 100 // previously known as temper_to
0A28: set_actor [email protected] swimming_speed_to 2.3
05E2: AS_actor [email protected] kill_actor $PLAYER_ACTOR
0002: jump @RANDOMP_2

:RANDOMP_2
0001: wait 0 ms
00D6: if or
0112: wasted_or_busted // mission only
0118: actor $PLAYER_ACTOR dead
0118: actor [email protected] dead
004D: jump_if_false @RANDOMP_2
0002: jump @RANDOMP_4

:RANDOMP_3
0001: wait 0 ms
00D6: if or
8118: not actor $PLAYER_ACTOR dead
8118: not actor [email protected] dead
004D: jump_if_false @RANDOMP_2

:RANDOMP_4
009B: destroy_actor [email protected]
01C2: remove_references_to_actor [email protected] // Like turning an actor into a random pedestrian
0002: jump @RANDOMP_1

Edited by Dachinko
Link to comment
Share on other sites

 

WHILE TRUEWHILE TRUE    wait 0 ms    IF AND        0256:   player $PLAYER_CHAR defined        80DF:   NOT   actor $PLAYER_ACTOR driving        00E1:   player 0 pressed_key 8      THENBREAK    ENDEND// after the break the code moves forward here 04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 3.0 1.00376: [email protected] = create_random_actor_at [email protected] [email protected] -100.0 // I don't understand why you use -100.0 when we have [email protected]: set_actor [email protected] bleeding 10245: set_actor [email protected] walk_style_to "DRUNKMAN"0223: set_actor [email protected] health_to 10000A09: set_actor [email protected] muted 1 // versionB060B: set_actor [email protected] decision_maker_to 655360446: set_actor [email protected] dismemberment_possible 004D8: set_actor [email protected] drowns_in_water 00946: set_actor [email protected] actions_uninterupted_by_weapon_fire 107DD: set_actor [email protected] attack_rate 100 // previously known as temper_to0A28: set_actor [email protected] swimming_speed_to 2.305E2: AS_actor [email protected] kill_actor $PLAYER_ACTOR   // now lets check if a ped is dead or if it's not near player (or if a player is wasted or busted)WHILE TRUE    wait 0 ms    IF OR        8104:   NOT   actor $PLAYER_ACTOR near_actor [email protected] radius 30.0 30.0 30.0 sphere 0  // define radius by yourself!        0118:   actor [email protected] dead        8256:   NOT   player $PLAYER_CHAR defined    THEN    034F: destroy_actor_with_fade [email protected]    ENDEND// after the break the code moves forward here (the last END will bring back the whole code to the first WHILE TRUE)END

Also you wrote this:

009B: destroy_actor [email protected]: remove_references_to_actor [email protected] // Like turning an actor into a random pedestrian

You can't do anything with the actor after you destroy him. It may even crash the game.

 

 

 

Edited by Jack
  • Like 1
Link to comment
Share on other sites

DoubleVision

Thanks a lot, Jack. Your advice/fix helped a lot. The actor dissappears immediately and a new random ped spawns in its place. Also, it respawns near me when I leave the area and go somewhere else. Just wish I could also get it to spawn inside tunnels & under bridges (pretty much anywhere). Thanks again.

 

004F: create_thread @RANDOMP_1 ///spawn random enemy ped

:RANDOMP
03A4: name_thread 'RANDOMP'

:RANDOMP_1
0001: wait 0 ms
00D6: if and
0256: player $PLAYER_CHAR defined
not actor.Dead($PLAYER_ACTOR)
not actor.Driving($PLAYER_ACTOR)
004D: jump_if_false @RANDOMP_1
04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 3.0 1.0
0376: [email protected] = create_random_actor_at [email protected] [email protected] -100.0
0332: set_actor [email protected] bleeding 1
0245: set_actor [email protected] walk_style_to "DRUNKMAN"
0223: set_actor [email protected] health_to 1000
0A09: set_actor [email protected] muted 1 // versionB
060B: set_actor [email protected] decision_maker_to 65536
0446: set_actor [email protected] dismemberment_possible 0
04D8: set_actor [email protected] drowns_in_water 0
0946: set_actor [email protected] actions_uninterupted_by_weapon_fire 1
07DD: set_actor [email protected] attack_rate 100 // previously known as temper_to
0A28: set_actor [email protected] swimming_speed_to 2.3
05E2: AS_actor [email protected] kill_actor $PLAYER_ACTOR
0002: jump @RANDOMP_2

:RANDOMP_2
0001: wait 0 ms
00D6: if or
8104: NOT actor $PLAYER_ACTOR near_actor [email protected] radius 30.0 30.0 30.0 sphere 0 // define radius by yourself! ///added
0118: actor [email protected] dead
8256: NOT player $PLAYER_CHAR defined ///added
0112: wasted_or_busted // mission only
0118: actor $PLAYER_ACTOR dead
0118: actor [email protected] dead
004D: jump_if_false @RANDOMP_2
0002: jump @RANDOMP_4

:RANDOMP_4
034F: destroy_actor_with_fade [email protected]
0002: jump @RANDOMP_1

Edited by Dachinko
Link to comment
Share on other sites

 

04C4
: store_coords_to 1@ 2@ 3@ from_actor $PLAYER_ACTOR with_offset 0.0 3.0 1.0
0376: 4@ = create_random_actor_at 1@ 2@ -100.0 // I don't understand why you use -100.0 when we have [email protected]

 

-100.0 is a special Z coord value which automatically finds the Z height for the specified XY position. It works well, it's very underrated.

Link to comment
Share on other sites

DoubleVision

Hi, Jack and Deji. Thanks for responding. The "-100" works, but when I go to a tunnel like in los santos where the outside top part is very high the game will freeze as I go in deeper.

 

And when I use "[email protected]" is works, but the actor will spawn from way up in the sky if I'm flying, using heli, using flying cars, using super cj flying, etc all while in the sky. Is there any way around this to have actor spawn in tunnels, outside too, on the ground no matter what I freely do? basicly I want the actor to always spawn directly on the ground even if I'm flying, driving a vehicle, and on foot. Sorry guys for requesting too much. Thanks very much guys. Also, Sorry to get back to the thread late.

Edited by Dachinko
Link to comment
Share on other sites

Do this check:

IF    04C8:   actor $PLAYER_ACTOR driving_flying_vehicleTHEN04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 3.0 1.00376: [email protected] = create_random_actor_at [email protected] [email protected] -100.0ELSE04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset 0.0 3.0 1.00376: [email protected] = create_random_actor_at [email protected] [email protected] [email protected]
Link to comment
Share on other sites

DoubleVision

I tried to include in your last fix but I kept doing it incorrectly, because I wasn't sure where to place it in the script. I kept spawning too many actors at once when I tried doing (I kept doing it wrong somehow). but I tried this one and it kinda worked:

 

004F: create_thread @RANDOMZA_1 ///spawn random enemy ped

:RANDOMZA
03A4: name_thread 'RANDOMZA'

:RANDOMZA_1
0001: wait 0 ms
077E: get_active_interior_to [email protected]
0819: [email protected] = actor $PLAYER_ACTOR distance_from_ground ///"[email protected]' is 3 feet up in z
00D6: if and
0039: [email protected] == 0
0023: 3.0 > [email protected]
0256: player $PLAYER_CHAR defined
not actor.Dead($PLAYER_ACTOR)
004D: jump_if_false @RANDOMZA_1
04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset -3.0 20.0 1.0
0376: [email protected] = create_random_actor_at [email protected] [email protected] [email protected]
0173: set_actor [email protected] Z_angle_to 0.0
0332: set_actor [email protected] bleeding 1
0245: set_actor [email protected] walk_style_to "OLDMAN"
0223: set_actor [email protected] health_to 1000
0A09: set_actor [email protected] muted 1 // versionB
060B: set_actor [email protected] decision_maker_to 65536
0446: set_actor [email protected] dismemberment_possible 0
04D8: set_actor [email protected] drowns_in_water 0
0946: set_actor [email protected] actions_uninterupted_by_weapon_fire 1
07DD: set_actor [email protected] attack_rate 100 // previously known as temper_to
0A28: set_actor [email protected] swimming_speed_to 2.3
03FE: set_actor [email protected] money 0
05E2: AS_actor [email protected] kill_actor $PLAYER_ACTOR
0002: jump @RANDOMZA_2

:RANDOMZA_2
0001: wait 500 ms
00D6: if or
8104: NOT actor $PLAYER_ACTOR near_actor [email protected] radius 30.0 30.0 30.0 sphere 0 // define radius by yourself! ///added
0118: actor [email protected] dead
8256: NOT player $PLAYER_CHAR defined ///added
0118: actor $PLAYER_ACTOR dead
0118: actor [email protected] dead
004D: jump_if_false @RANDOMZA_2
0002: jump @RANDOMZA_4

:RANDOMZA_4
0001: wait 100 ms
034F: destroy_actor_with_fade [email protected]
0002: jump @RANDOMZA_1

Link to comment
Share on other sites

DoubleVision

Sorry for bump, but I believe I edited the script with jack's fix right this time. The only thing I wonder is why some/certain peds spawn more often than others? Thanks to everyone that helped me. Here's the script:

 

///spawns zombie (random Ped id, each time different Ped)
///zombie dissappears when it dies and reappears immediately
///zombie disappears after you die and reappears
///zombie dissappears and respawns when you're far away & you leave area
///zombie spawns on ground if driving flying vehicles fix by jack

004F: create_thread @RANDOMZA_1 ///spawn random enemy ped 01

:RANDOMZA
03A4: name_thread 'RANDOMZA'

:RANDOMZA_1
0001: wait 0 ms
077E: get_active_interior_to [email protected]
0819: [email protected] = actor $PLAYER_ACTOR distance_from_ground
00D6: if and
0039: [email protected] == 0
0023: 3.0 > [email protected]
0256: player $PLAYER_CHAR defined
not actor.Dead($PLAYER_ACTOR)
004D: jump_if_false @RANDOMZA_2
0002: jump @RANDOMZA_3

:RANDOMZA_2
0001: wait 50 ms
00D6: if and
04C8: actor $PLAYER_ACTOR driving_flying_vehicle
0256: player $PLAYER_CHAR defined
not actor.Dead($PLAYER_ACTOR)
004D: jump_if_false @RANDOMZA_1
04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset -5.0 20.0 1.0
0376: [email protected] = create_random_actor_at [email protected] [email protected] -100.0
0002: jump @RANDOMZA_4

:RANDOMZA_3
0001: wait 50 ms
04C4: store_coords_to [email protected] [email protected] [email protected] from_actor $PLAYER_ACTOR with_offset -3.0 20.0 1.0
0376: [email protected] = create_random_actor_at [email protected] [email protected] [email protected]
0002: jump @RANDOMZA_4

:RANDOMZA_4
0173: set_actor [email protected] Z_angle_to 0.0
0332: set_actor [email protected] bleeding 1
0245: set_actor [email protected] walk_style_to "OLDMAN"
0223: set_actor [email protected] health_to 1000
0A09: set_actor [email protected] muted 1 // versionB
060B: set_actor [email protected] decision_maker_to 65536
0446: set_actor [email protected] dismemberment_possible 0
04D8: set_actor [email protected] drowns_in_water 0
0946: set_actor [email protected] actions_uninterupted_by_weapon_fire 1
07DD: set_actor [email protected] attack_rate 100 // previously known as temper_to
0A28: set_actor [email protected] swimming_speed_to 2.3
03FE: set_actor [email protected] money 0
05E2: AS_actor [email protected] kill_actor $PLAYER_ACTOR
0002: jump @RANDOMZA_5

:RANDOMZA_5
0001: wait 0 ms
00D6: if or
8104: NOT actor $PLAYER_ACTOR near_actor [email protected] radius 30.0 30.0 30.0 sphere 0 // define radius by yourself! ///added
0118: actor [email protected] dead
8256: NOT player $PLAYER_CHAR defined ///added
0112: wasted_or_busted // mission only
0118: actor $PLAYER_ACTOR dead
0118: actor [email protected] dead
004D: jump_if_false @RANDOMZA_5
0002: jump @RANDOMZA_6

:RANDOMZA_6
0001: wait 100 ms
034F: destroy_actor_with_fade [email protected]
0002: jump @RANDOMZA_1

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