Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!   (86,290 visits to this link)

    2. News

    1. GTA Online

      1. Find Lobbies & Players
      2. Guides & Strategies
      3. Vehicles
      4. Content Creator
      5. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. 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

    2. Red Dead Redemption

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

    2. Site Suggestions

venom330

Scripting for GTA IV?

Recommended Posts

venom330

Hello, Im new both to this forum and scripting for GTA IV, I got interested in scripting when i saw the bodyguard mods, zombie mods, etc

 

I would love a zombie mod for gta 4 , unfortunately i dont see the existing ones very fun. I have contagium 1.2b but its not very fun for me.

 

first i would just ask: Where do i learn scripting for gta iv? i got C# but find almost no tutorial for scripting in gta 4, secondly, Is there anybody that has zombie textures available for pedestrians?

also, How do i know what commands i can use for gta 4, where do i found these? I cant open scripthook.dll so what programs or tools do i need?

 

 

i got some basics because i was very good in lua language for another game, so i aint that bad smile.gif

 

now ill have a look at the forum see what i can learn biggrin.gif

Share this post


Link to post
Share on other sites
L0uNGeR

 

Hello venom330, welcome to the forums! colgate.gif

 

 

 

first i would just ask: Where do i learn scripting for gta iv?  i got C# but find almost no tutorial for scripting in gta 4......

If you have the .Net ScriptHook package, have a look at this file:

scripthookdotnet_1.7.1.7beta.zip\scripts\for Developers\TestScriptCS\Scripts\TestScripts.cs

See bottom of this post for examples.

 

 

 

also, How do i know what commands i can use for gta 4, where do i found these? I cant open scripthook.dll so what programs or tools do i need?

You can download the documentation for .Net ScriptHook here

If you want a specific function that isn't implemented in .Net ScriptHook, you can start looking for a GTA Native that might help you.

You can find the complete Natives listing here.

Also have a look at Scripting.h from the C++ ScriptHook source code (fixed)

 

 

 

i got some basics because i was very good in lua language for another game, so i aint that bad smile.gif

We actually work(ed) with LUA in GTA IV through the "A.l.i.c.e." plugin...It's just that C#/VB makes everything that much easier, so that's what I use and recommend.

 

 

 

Examples

 

First example in .Net ScriptHook's TestScripts.cs, made into a ready-to-run script:

 

using System;using System.Windows.Forms;using GTA;namespace TestScriptCS{   // ### get 10000 bucks each time you press M ###   public class BasicKeyExample : Script   {       public BasicKeyExample()       {           // Bind method BasicKeyExample_KeyDown to the KeyDown event           this.KeyDown += new GTA.KeyEventHandler(this.BasicKeyExample_KeyDown);       }       // KeyDown returns the pressed key.       // but there is no need to check it when your script watches only this one key       private void BasicKeyExample_KeyDown(object sender, GTA.KeyEventArgs e)       {           if (e.Key == Keys.M)               Player.Money += 10000;       }   }}

 

 

Another simple script:

 

 

using System;using System.Windows.Forms;using GTA;namespace TestScriptCS{   public class BasicExample : Script   {       public BasicExample()       {           this.KeyDown += new GTA.KeyEventHandler(this.BasicExample_KeyDown);       }       private void BasicExample_KeyDown(object sender, GTA.KeyEventArgs e)       {           if (e.Key == Keys.M)               DoSomeStuff();       }       private void DoSomeStuff()       {           Ped pl = Player.Character;           if (pl.isAlive)           {               Game.DisplayText("Hello World!");               Wait(600);               pl.SayAmbientSpeech("Thanks");           }       }   }}

 

 

 

 

Edited by L0uNGeR

Share this post


Link to post
Share on other sites
venom330

Thank you , this should be helpfull biggrin.gif

 

gonna have some more look at those example scripts, So for example if you wanna make a simple zombie mod, You replace pedestrian models so it looks realistic and change their behavior to the player to hate and thats it?

 

btw how do you change animations to the pedestrian? like instead of walking they would go drunk or something?

 

 

Also have a look at Scripting.h from the C++ ScriptHook source code

 

I couldnt connect to the site sad.gif

 

 

 

Share this post


Link to post
Share on other sites
L0uNGeR

 

So for example if you wanna make a simple zombie mod, You replace pedestrian models so it looks realistic and change their behavior to the player to hate and thats it?

It's easier said than done, but it is possible yes, there's even a zombie example in TestScripts.cs

 

 

btw how do you change animations to the pedestrian? like instead of walking they would go drunk or something?

You can make them use predefined animations, there's also an example for this in TestScripts.cs (spliff smoking), or you could tweak physics for a ped by learning more about the Euphoria functions.

I don't have any experience with this so I have no idea what the possibilities are.

 

 

I couldnt connect to the site  sad.gif

I've put up a mirror.

Share this post


Link to post
Share on other sites
venom330

Alright thanks tounge.gif

 

How do i replace animations? example swat to make them walk drunk

Edited by venom330

Share this post


Link to post
Share on other sites
L0uNGeR

 

now where do i find these animations? In pedprops i only find textures and models

Here you can find all the animations

http://www.gtamodding.com/index.php?title=...imations_(GTA4)

The game works with Animation Sets, so you request a set, then play an animation from that set, like so:

 

AnimationSet anims = new AnimationSet("[email protected]_spliff");AnimationFlags animflags = AnimationFlags.Unknown12 | AnimationFlags.Unknown11 | AnimationFlags.Unknown09;Player.Character.Animation.Play(anims, "create_spliff", 8.0F, animflags);Player.Character.Animation.WaitUntilFinished(anims, "create_spliff");// Animation as a task:Player.Character.Task.PlayAnimation(anims, "partial_smoke", 8.0F, animflags);

 

 

 

 

and how do i edit behavior to make example a normal citizen to a gang member attitude with no fear?

I haven't tested this, since I never tried to alter a ped's relation to another group, but this might just work.

Question to others: Is this the best way to enumerate an enum? Thnx

 

// Get a close pedPed p = World.GetClosestPed(Player.Character.Position, 15f);// Ped belongs to Gang_Biker1 groupp.RelationshipGroup = RelationshipGroup.Gang_Biker1;// Ped's relation to Gang_Biker1 is Companionp.ChangeRelationship(RelationshipGroup.Gang_Biker1, Relationship.Companion);// Make the ped HATE everybody except his companionsforeach (RelationshipGroup group in Enum.GetValues(typeof(RelationshipGroup))){   if (group == RelationshipGroup.Gang_Biker1)       continue;   p.ChangeRelationship(group, Relationship.Hate);}

 

After test: This works! It's quite funny actually biggrin.gif

There isn't anything in this code to make the ped fearless, but they do start to attack everybody because of the hate relation.

You could just leave out the RelationshipGroup.Gang_Biker1 all together and make them hate everybody, even their own group.

 

// Make the ped HATE everybody

foreach (RelationshipGroup group in Enum.GetValues(typeof(RelationshipGroup))) {

p.ChangeRelationship(group, Relationship.Hate);

}

(yay for syntax highlighting!)

 

 

 

How do i replace animations? example swat to make them walk drunk

There's a Native SET_PED_IS_DRUNK, I don't know if it will do anything.

After test: Doesn't work...

This doesn't replace their animations like you are saying, if that's what you want, you just give them a new animation to perform, as explained above.

 

 

Edited by L0uNGeR

Share this post


Link to post
Share on other sites
venom330

for walking drunk i guess you need some kinda event, like you said above. But i dont need to replace the animations for the pedestrian i think, like the zombie mod i have contagium script it doesnt replace anything, its just an .asi file which i guess makes an event that all pedestrians who get hit by another group pedestrians do the same animation, in that case, some kinda injure animation.

 

can you make a quick simple sample of an animation change on event on a pedestrian if you know how to do ?

or is it possible to find in any testscripts? xD

 

 

 

I mean hm, if you get what i mean, A script triggers on start that a specific Pedestrian (group?) has a specific animation and a hate relation to all others, when he or she attacks another group then they get in the same group as the attacker, thats what the script is about, I find it simple, but as a noob at c# i dont have a clue how to put it as a sample, could you do it please? biggrin.gif

 

Then all problems solved, from there i can learn alot and experiment smile.gif

Edited by venom330

Share this post


Link to post
Share on other sites
L0uNGeR

I'm actually making a zombie mod from scratch now...

Just because it's the most obvious and probably the funniest things you could do in this game.

I haven't looked at any other zombie mods or anything like that except for the example in .Net ScriptHook.

 

This may become an awesome mod, but atm I can't tell how it'll work out, it could be just zombie or more like "special infected" style (L4D).

Share this post


Link to post
Share on other sites
venom330

nice biggrin.gif

 

hey i tested the testscript with the zombie and it looks awesome, it was exactly what i wanted, the same drunk animation biggrin.gif

 

So im trying to do it exact as the testscript but i dont want to have to press any buttons to activate it, i also want them to keep attacking me, this is my code so far, very simple, just like copy paste, got an error though

 

 

using System;using System.Drawing;using System.Windows.Forms;using GTA;namespace test {         public class TaskSequenceExample : Script {       TaskSequence FleeTask;     public TaskSequenceExample() {        // Add tasks to the TaskSequence        FleeTask = new TaskSequence();        FleeTask.AddTask.FightAgainstHatedTargets();         // Get a close ped        Ped p = World.GetClosestPed(Player.Character.Position, 15f);        p.CurrentRoom = Player.Character.CurrentRoom;        p.Task.PerformSequence(FleeTask);        foreach (RelationshipGroup group in Enum.GetValues(typeof(RelationshipGroup)))        {            p.ChangeRelationship(group, Relationship.Hate);        }        p.CurrentRoom = Player.Character.CurrentRoom;     }  }  // ### Press Z and the ped you are aiming at will start walking towards you like a zombie  ###  public class EuphoriaExample : Script {     Ped Zombie;          public EuphoriaExample() {        Interval = 250;        this.Tick += new EventHandler(this.EuphoriaExample_Tick);     }     private void DoTheZombie() {        if (Exists(Zombie)) {           Zombie.isRagdoll = false;           Zombie = null;           return;        }        Game.DisplayText("ZOMBIES!!!");        Zombie.Euphoria.BodyBalance.Start(-1);     }     private void EuphoriaExample_Tick(object sender, EventArgs e) {        if (!Exists(Zombie)) return;        if (Zombie.isGettingUp) return; // wait until the zombie is standing        if (!Zombie.isRagdoll) Zombie.Euphoria.BodyBalance.Start(-1);        if (!Zombie.Euphoria.BodyBalance.isBalanced) { // get up again when fallen to the ground           Zombie.isRagdoll = false;           return;        }        Zombie.Euphoria.LeanToPosition.Amount = 1.0F;        Zombie.Euphoria.LeanToPosition.ApplyAsForce = true;        Zombie.Euphoria.LeanToPosition.Position = Player.Character.Position;        Zombie.Euphoria.LeanToPosition.Start();     }   }}

 

Edited by venom330

Share this post


Link to post
Share on other sites
L0uNGeR

In the TaskSequenceExample class, TaskSequenceExample() is only fired once, you probably don't want this. Also, you didn't check if the closest ped actually exists (after GetClosestPed).

Also, you specify "p.CurrentRoom" twice.

 

if (!p.Exists()) return;

 

And another: FightAgainstHatedTargets() should have at least one argument.

 

 

In the EuphoriaExample class, the Ped Zombie is never actually assigned or created, so it can't be used. You can also see that DoTheZombie() is never used from anywhere.

Share this post


Link to post
Share on other sites
venom330

Yea i just found FightAgainstHatedTargets() at the scripthook documentation so i was gonna try it out, dont know what kinda argument i should have lol.

 

and i cant use Dothezombie? aww.. so ill have to set an animation for the random ped then, But i only find tutorial activating them by pressing a key, isnt there a command that when the ped is spawned and it sees the player or other peds, then it does the drunk animation and attacks?

 

Share this post


Link to post
Share on other sites
L0uNGeR

 

Yea i just found FightAgainstHatedTargets() at the scripthook  documentation so i was gonna try it out, dont know what kinda argument i should have lol.

FightAgainstHatedTargets( float radius [, int duration] )

 

 

and i cant use Dothezombie?

You can use Dothezombie(), I just told you that you never use it.

 

 

But i only find tutorial activating them by pressing a key, isnt there a command that when the ped is spawned and it sees the player or other peds, then it does the drunk animation and attacks?

You'd have to use Tick

 

public class MyTest : Script{   public MyTest()   {       Interval = 1000;       this.Tick += new EventHandler(MyTest_Tick);   }   internal void MyTest_Tick(object sender, EventArgs e)   {       foreach (Ped p in World.GetAllPeds())       {           if (p != null && p != Player.Character && p.Exists() && p.isAlive)           {               // DO STUFF TO PED           }       }   }}

 

 

World.GetAllPeds() works best for stuff like this, but it could be slow.

You can always use World.GetPeds() with a reasonable radius if the above is too slow.

 

 

Edited by L0uNGeR

Share this post


Link to post
Share on other sites
venom330

Ok i try this

 

 

using System;using System.Drawing;using System.Windows.Forms;using GTA;namespace MyTest{   public class MyTest : Script   {       TaskSequence FleeTask;       public MyTest()       {           // Add tasks to the TaskSequence           FleeTask = new TaskSequence();           FleeTask.AddTask.FightAgainstHatedTargets(3, 5);           FleeTask.AddTask.FightAgainst(Player);           {               Interval = 1000;               this.Tick += new EventHandler(MyTest_Tick);           }       }       internal void MyTest_Tick(object sender, EventArgs e)       {           {               foreach (RelationshipGroup group in Enum.GetValues(typeof(RelationshipGroup)))           {               foreach (Ped p in World.GetAllPeds())               {                   if (p != null && p != Player.Character && p.Exists() && p.isAlive)                       p.Task.PerformSequence(FleeTask);                       p.ChangeRelationship(group, Relationship.Hate);                   {                       // DO STUFF TO PED                   }               }               }           }       }                   Ped Zombie;                                                  private void DoTheZombie() {                       if (Exists(Zombie))                       Zombie.isRagdoll = false;                       Zombie = null;                       return;                                  }   }        ERROR    --->      Zombie = Player.GetTargetedPed(); {                   if (!Exists(Zombie)) return;                   Game.DisplayText("ZOMBIES!!!");                   Zombie.Euphoria.BodyBalance.Start(-1);               }               {                   if (!Exists(Zombie)) return;                   if (Zombie.isGettingUp) return; // wait until the zombie is standing                   if (!Zombie.isRagdoll) Zombie.Euphoria.BodyBalance.Start(-1);                   if (!Zombie.Euphoria.BodyBalance.isBalanced)                   { // get up again when fallen to the ground                       Zombie.isRagdoll = false;                       return;                   }                   Zombie.Euphoria.LeanToPosition.Amount = 1.0F;                   Zombie.Euphoria.LeanToPosition.ApplyAsForce = true;                   Zombie.Euphoria.LeanToPosition.Position = Player.Character.Position;                   Zombie.Euphoria.LeanToPosition.Start();}}

 

 

 

But i get error at Zombie, It says: a namespace cannot directly contain members such as fields or methods

 

I want it to 1 script, so if you go around then you see some peds walking like zombies without you need to aim at them! cant find command, but i wanna find another command instead of you must aim so they become zombies. So i want all the text to go together, They attack everybody they see except their own zombie faction, Could you fix the problem ? xD

Edited by venom330

Share this post


Link to post
Share on other sites
L0uNGeR

Your code is completely messed up, are you even using Visual Studio or?

Also, you can't do BodyBalance and Tasks at the same time, I've tried it.

You could however pause BodyBalance and do a task, then continue BodyBalance, but it looks awkward.

 

I did a test with the code below, right now I commented out the "PerformSequence" because it still needs a check to see if they already have this task.

If you un-comment the line, they keep restarting the Task so it looks weird.

For now, this works, everybody hates everybody, no special faction or anything, I'm still working on that.

 

EDIT: This is probably better for setting relationships:

 

World.SetGroupRelationship( RelationshipGroup group, Relationship level, RelationshipGroup targetgroup )

 

 

using System;using GTA;namespace MyTest{   public class MyTest : Script   {       TaskSequence FightTask;       public MyTest()       {           Interval = 1000;           FightTask = new TaskSequence();           FightTask.AddTask.FightAgainstHatedTargets(3, 5);           FightTask.AddTask.FightAgainst(Player);           this.Tick += new EventHandler(MyTest_Tick);       }       internal bool IsPedReady(Ped p)       {           return (p != null && p != Player.Character && p.Exists() && p.isAlive);       }       internal void SetPedHateEverybody(Ped p)       {           if (!p.Exists()) return;           foreach (RelationshipGroup group in Enum.GetValues(typeof(RelationshipGroup)))               p.ChangeRelationship(group, Relationship.Hate);       }       internal void MyTest_Tick(object sender, EventArgs e)       {           // Code in here is being run the whole time, according to "Interval"           foreach (Ped p in World.GetAllPeds())           {               if (IsPedReady(p))               {                   SetPedHateEverybody(p);                   //p.Task.PerformSequence(FightTask);               }           }       }   }}

 

Edited by L0uNGeR

Share this post


Link to post
Share on other sites
venom330

Yeah sorry im still very nooby xd

 

but i tried atleast, ehm ok i take this code, but is it then possible to include the zombie thing aswell? becuase i want the zombie thing O.o

 

should i add it here?

 

SetPedHateEverybody(p);

//p.Task.PerformSequence(FightTask);

 

Zombie things

Zombie things

Zombie things

Zombie things

Zombie things

Zombie things

 

}

}

}

}

}

Share this post


Link to post
Share on other sites
L0uNGeR
Yeah sorry im still very nooby xd

 

but i tried atleast, ehm ok i take this code, but is it then possible to include the zombie thing aswell? becuase i want the zombie thing O.o

 

should i add it here?

 

SetPedHateEverybody(p);

//p.Task.PerformSequence(FightTask);

 

Zombie things

Zombie things

Zombie things

Zombie things

Zombie things

Zombie things

 

}

}

}

}

}

Yes it is possible, but it requires a much more advanced system to take care of the "BodyBalance" for ALL the zombies, instead of just 1.

Share this post


Link to post
Share on other sites
Donny78

Off topic:

 

You don't have to use the "internal" and "this" keywords (sorry forgot name of them), you can just do:

 

 

void myFunc() {}// andTick += new .......

 

 

Not a big deal, just telling you so you save on redundant code.

Share this post


Link to post
Share on other sites
L0uNGeR
Off topic:

 

You don't have to use the "internal" and "this" keywords (sorry forgot name of them), you can just do:

 

 

void myFunc() {}// andTick += new .......

 

 

Not a big deal, just telling you so you save on redundant code.

Thanks for the heads up, but: Every example that I've seen used "this.tick" and "private void ...."

I only started using internal instead of private because I understood that it was better.

Why do all Hazard's examples use "this" and "private" ? I'm sure he's not a beginner...

Share this post


Link to post
Share on other sites
lindsayslorach

I'm pretty sure variables and methods are private anyway, so there's no need to have the private keyword.

Share this post


Link to post
Share on other sites
Donny78

 

Thanks for the heads up, but:  Every example that I've seen used "this.tick"  and "private void ...."

I only started using internal instead of private because I understood that it was better.

Why do all Hazard's examples use "this" and "private" ?  I'm sure he's not a beginner...

 

There could be reasons it's used in the examples you're using but in the above code it's not required as no other objects/instances/classes are being accessed anywhere. All the keywords are designed to allow access to other classes/instances etc, if you're not doing this then there is no need to use them.

 

Check out the MSDN website, it's got tons of great information on this type of thing.

 

Edit:

 

Grabbed a few links for you dude, Access Modifiers, this.

Edited by Donny78

Share this post


Link to post
Share on other sites
L0uNGeR

Well the code was actually a straight copy/paste from a much bigger script....

You should probably check the TestScripts.cs from the ScriptHook.Net package, there's "private" and "this" in every class and my code is not much different.

I'm not saying I know best, I'm still learning and I appreciate the help.

Share this post


Link to post
Share on other sites
Donny78

I'm no expert either (by far!), it was just something I noticed so I thought I'd throw my two cents in dude icon14.gif

 

It's a good suggestion to look at the examples, not looked at them since a very early version of the scripthook.

Share this post


Link to post
Share on other sites
gavlar1992

Could someone help me create this, i'm pretty much new to scripting/coding. i really would want this to work though

 

OK, so i have a really cool new idea. I've recently started adding extra (not replacing) vehicles into the game, and a few times i've added a car that is a tuned version of one i already have, and added the ext_rare tag to it.. so its kinda like a rare tuned version... eg i have a mercedes and the amg version.. bmw and the haman version etc

 

MY IDEA: seeing as theres lots of these car mods kicking around and i was thinking of making a mod whereby you would go to brucies garage with a certain car.. eg a sultan and you would pay so much money and it would give you a sultanrs... so thus 'tuning' the car.. even though its just swapping the model. so im guessing the script would check the car name, display a prompt somewhere or even a menu, asking if you want it pimped, if yes then destroy the car, take x amount of money and spawn the new car associated with that car.. i.e sultanrs if the players car is a sultan.. and in my case 'turismogt' if players car is 'turismo'... etc... i get the idea but i'm no good at coding.. i can read basic bits etc but not create a script really from scratch without some help... could someone please help me with this?

 

I think this mod would be pretty impressive.. hey it could even turn into a huge overhaull and come with its own IMG file of these extra modded vehicles.. gtaiv NEEDS some form of tuning cars, even if its not really doing so.

 

Any help is much appreciated.

Share this post


Link to post
Share on other sites
lamar_mustapha

i would assume u need the hash and then create using hash, try using the model name u added to vehicles.ide to get it's hash code

 

http://www.gtamodding.com/index.php?title=CREATE_CAR

http://www.gtamodding.com/index.php?title=GET_HASH_KEY

 

C#

 

int myAddedCarsHash = GTA.Native.Function.Call("GET_HASH_KEY", "ModelNameofCarAdded");Vehicle myCar = null;GTA.Native.Function.Call("CREATE_CAR", myAddedCarsHash, Game.LocalPlayer.Character.Position.X, (Game.LocalPlayer.Character.Position.Y + 5), Game.LocalPlayer.Character.Position.Z, myCar, true);GTA.Native.Function.Call("SET_CAR_ON_GROUND_PROPERLY", myCar);myCar.Heading = Game.LocalPlayer.Character.Heading;

 

 

im just taking a wild guess but try that, i positioned car on ground in front of u with car pointing the direction u r looking

Edited by lamar_mustapha

Share this post


Link to post
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

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.