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

    3. Suggestions

Scripting Random Events


MorphMan
 Share

Recommended Posts

Hi Guys!

 

Im really new to coding/scripting so I'm not going to lie.....I know hardly anything (just the basics) but I'm learning smile.gif

 

I was thinking of possibly making a script that allows random things to happen but how would I go about doing it?

 

One idea was to allow random gang drive-bys against other gangs just as you walk down the street...out of know where.

 

As I mentioned earlier, Im really new to scripting, but I was thinking that it could be possible? ie Spawn a car with say 2 Gang (A) members and spawn another group on the streets Gang (B) and tell them to target them? possible?

 

Anyone got any ideas of how I would create this?

 

Thanks in advance!

Link to comment
Share on other sites

wow... being new to scripting random events you should start SIMPLE.

 

Writing a drive by script is not simple for somebody learning the basics. So here is what i did, since i basically taught myself through example and lots of questioning:

 

1: learn pedestrian spawning. Learn how to set there relationshipgroups, i.e., cop, civmale, civfemale, player, dealer, criminal, medic, fireman, etc. Then set whether they are a companion, liked, nuetral, disliked, or hated by changing their relationships to other groups.

 

2: Set a weapon to them. A knife, a gun, etc.

 

3: If you spawn a civmale with a knife that hates a dealer, he should attack a dealer just due to relationships.

 

4: Then code in a random number generator, and if the number hits you set the event for, then that pedestrian will spawn.

 

 

But yes, what you're asking is possible to do, it'll just take some time to learn the coding behind the game to make it work.

Link to comment
Share on other sites

Haha yer maybe I should start simple tounge.gif

 

 

Those learning steps sound pretty useful, i'll learn those and see how it goes. Thanks smile.gif

 

 

 

Edit: Ive learnt how to Spawn Peds now with relationship groups but how do I give them a weapon?

 

Thanks again !

Edited by MorphMan
Link to comment
Share on other sites

Here's some high-level info about how you could go about doing this, if you want actual coding help feel free to ask

 

- Create several lists of the things you'd like to spawn: which cars, which weapons, and which peds

- Randomly generate numbers between 0 and the lengths of each list to get random cars, weapons, and peds from the lists

- Generate random coordinates around the player's current position (and then maybe add some distance to it so that these guys appear far away otherwise they'll plop down in front of you and that looks weird tounge.gif)

- Give weapons to the peds and place them inside the cars

- Spawn the cars at the coordinates you generated earlier

- Set them as enemies and mark them as able to do drive-bys

Link to comment
Share on other sites

Thanks again for the replies Guys!

 

ShakingASS: oh, is it? How is it better? smile.gif and I agree with jitsuin tounge.gif

 

Motorsport71: Yer, I'm still stuck on adding Weapons to people sad.gif

Link to comment
Share on other sites

Try this:

 

X.Weapons.MP5.Ammo = 30000;

 

 

X is the value you are using to designate "ped", whether it be "p" or "ped" or "bob" whatever.

Link to comment
Share on other sites

Okay so i've add a weapon to the ped, however they wont use it (apart from being shot or aimed at by me or the police). Ive changed their Relationship to Hate pratically everyone, and they do fight with anyone but not shoot at them confused.gif

 

Ive added p.Task.ShootAt, p.StartKillingSpree (and other weapon related properties) but they'll hold the MP5 and aim it at another closest Ped until they fight in which they drop it in favour of melee.

 

Am I missing somthing?

Also the GetNearestPed doesn't seem to get ones who are in animation i.e. Sign holders, Talking, Getting up, in a group etc or even ones in vehicles. I always get a Script error in Game and have to reaload the script.....help? tounge.gif

 

 

Edited by MorphMan
Link to comment
Share on other sites

 

What's the script error that you get?

Hi AngryAmoeba

 

the Error I get is:

 

System.NullReferenceException: Object reference not set to an instance of an object.

Link to comment
Share on other sites

you need to check if ped exists before u do stuff with them so before your code executes add this check:

 

 

if (Exists(p)){   //so if this true then u can give the ped instructions}

 

 

edit: just pretend im not here lol

Edited by jitsuin
Link to comment
Share on other sites

@jitsuin

That will avoid NonExistingObjectException errors, but not NullReferenceException errors.

 

"Null reference" means you're trying to use a variable that doesn't yet refer to anything. For example, this code will produce a NullReferenceException:

 

Ped newPed;newPed.Money = 100; // error

 

This will also cause the error:

 

Ped newPed;if (newPed.Money > 0) // error{   // stuff}

 

So you would fix it by making the variable reference something before trying to use it, for example:

 

Ped newPed = World.GetClosestPed(Player.Character.Position, 10.0F);

 

Link to comment
Share on other sites

oh my bad, didnt read the specifics, more like i recognized the statement instead of actually reading it lol

Link to comment
Share on other sites

Thats strange, because I was putting it in correctly as you showed. How do you make it so if there isnt a Ped nearby it will keep looking?

 

Its probally quite simple, but I cant work it out sad.gif

 

Thanks

Link to comment
Share on other sites

Just realized I was wrong! blush.gif

 

You can avoid both NullReferenceException and NonExistingObjectException errors by using the Exists() function, like jitsuin said. Exists() really does this:

 

if (theObject != null && theObject.Exists())

 

So if the Ped is null, Exists() returns false.

Link to comment
Share on other sites

Got it working thanks tounge.gif

 

I have slightly changed my script to make random things happen (not just the Drive by.....Still to work that one out tounge.gif) and so far I have three events, People dropping dead (if random number = 650 -666) and people bursting into flames (still deciding on the probabilty) and Random Fights. Thinking of including a riot (Molotovs and baseball bats), Ive already got it working but only with spawing peds instead grabbing them of the street, so give me time smile.gif

 

Anyone want to throwing in some ideas that I could possibly include (Keep in mind I've only just started learning c#)

 

Thanks again for the help Guys!

Edited by MorphMan
Link to comment
Share on other sites

i think it would be funny to see a car of puerto rican gangsters pull up to a lone rival gang member, maybe a lone chinese guy or black gangster, they all get out of a car, beat the sh*t out of him and then get back in car and leave xD

 

like a car of one gangster type that roams around city looking for rival gangs to beat up

 

give it a shot...lol

Link to comment
Share on other sites

 

i think it would be funny to see a car of puerto rican gangsters pull up to a lone rival gang memebr, beat the sh*t out of him and then get in car and leave xD

 

give it a shot...lol

 

haha sounds like an idea, Ill have a stab at it tounge.gif

Link to comment
Share on other sites

Oh that was another problem I had:

 

Ive got the co-ordinates of a location but how do I make things spawn (Every now and then) there i.e. selected Peds, vehicles etc or even make it a goto marker?

Link to comment
Share on other sites

Look at line 103 on this page for the native to what looks to me is used to spawn a ped, tbh i never used so im not 100%. Yeah so ALMOST every answer to any question you may have will be here:

 

http://code.google.com/p/gta4modding/sourc...Scripting.h?r=5

 

and also u can check:

 

http://code.google.com/p/gta4modding/sourc...h?spec=svn5&r=5

 

Try using...

 

 

GTA.Native.Function.Call("CREATE_CHAR", type, model, x, y, z, pPed, unknownTrue);

 

Edited by jitsuin
Link to comment
Share on other sites

Let me know if it works or not, im at work but when i go home i plan on working on this mod ive been working on all week and i will need to figure out how to spawn peds so hey...you are helping me too! biggrin.gif

Link to comment
Share on other sites

 

Oh that was another problem I had:

 

Ive got the co-ordinates of a location but how do I make things spawn (Every now and then) there i.e. selected Peds, vehicles etc or even make it a goto marker?

The .NET script hook has that stuff built in. I recommend downloading the reference documentation from the script hook thread.

 

Here's where to look in the documentation for specific things.

Spawning a ped: World.CreatePed()

Spawning a vehicle: World.CreateVehicle()

Telling a ped to go somewhere: Ped.Tasks.GoTo() or Ped.Tasks.RunTo()

Telling a ped to drive somewhere: Ped.Tasks.DriveTo()

 

Lots of other useful stuff in there too!

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.