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

MorphMan

Scripting Random Events

Recommended Posts

MorphMan

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!

Share this post


Link to post
Share on other sites
motorsport71

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.

Share this post


Link to post
Share on other sites
MorphMan

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

Share this post


Link to post
Share on other sites
motorsport71

How are you coding? in c++, c#, v.b.? Are you using ScriptHookDotNet?

Share this post


Link to post
Share on other sites
MorphMan

Im (trying tounge.gif) to code in c#, and yes with ScriptHookDotNet

Share this post


Link to post
Share on other sites
rappo

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

Share this post


Link to post
Share on other sites
MorphMan

Thanks Rappo!

 

Ill have a crack at those steps, see how I go. Thanks for offering your help smile.gif

Share this post


Link to post
Share on other sites
motorsport71

@Morphman

Did you get weapons figured out?

Share this post


Link to post
Share on other sites
ShakingASS

Learn sco scripting way better than extranal scripts.

Share this post


Link to post
Share on other sites
jitsuin

^ur av needs to be like a minute longer

Share this post


Link to post
Share on other sites
MorphMan

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

Share this post


Link to post
Share on other sites
motorsport71

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.

Share this post


Link to post
Share on other sites
MorphMan

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

Share this post


Link to post
Share on other sites
Symbiote

What's the script error that you get?

Share this post


Link to post
Share on other sites
MorphMan

 

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.

Share this post


Link to post
Share on other sites
jitsuin

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

Share this post


Link to post
Share on other sites
Symbiote

@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);

 

Share this post


Link to post
Share on other sites
jitsuin

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

Share this post


Link to post
Share on other sites
MorphMan

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

Share this post


Link to post
Share on other sites
Symbiote

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.

Share this post


Link to post
Share on other sites
MorphMan

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

Share this post


Link to post
Share on other sites
jitsuin

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

Share this post


Link to post
Share on other sites
MorphMan

 

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

Share this post


Link to post
Share on other sites
jitsuin

good luck ;D

Share this post


Link to post
Share on other sites
MorphMan

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?

Share this post


Link to post
Share on other sites
jitsuin

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

Share this post


Link to post
Share on other sites
MorphMan

Cheers smile.gif

Share this post


Link to post
Share on other sites
jitsuin

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

Share this post


Link to post
Share on other sites
MorphMan

haha, sure thing icon14.gif

Share this post


Link to post
Share on other sites
Symbiote

 

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!

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.