|
 |
|
|
|
|
|
GTA Modification Forums
Scripting for GTA IV?
 |
|
 |
| |
venom330  |
Posted: Tuesday, May 10 2011, 19:16
|
Player Hater

Group: Members
Joined: May 10, 2011

|
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 now ill have a look at the forum see what i can learn
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
L0uNGeR  |
Posted: Tuesday, May 10 2011, 19:52
|
Ya, that's what I said.

Group: Members
Joined: Dec 3, 2008


|
Hello venom330, welcome to the forums! | QUOTE (venom330 @ May 10 2011, 21:16) | | 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.csSee bottom of this post for examples. | QUOTE (venom330 @ May 10 2011, 21:16) | | 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 hereIf 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) | QUOTE (venom330 @ May 10 2011, 21:16) | i got some basics because i was very good in lua language for another game, so i aint that bad  |
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. ExamplesFirst example in .Net ScriptHook's TestScripts.cs, made into a ready-to-run script: | CODE | 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: | CODE | 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"); } } } } | This post has been edited by L0uNGeR on Tuesday, May 10 2011, 20:22
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
L0uNGeR  |
Posted: Tuesday, May 10 2011, 20:30
|
Ya, that's what I said.

Group: Members
Joined: Dec 3, 2008


|
| QUOTE (venom330 @ May 10 2011, 22:13) | | 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| QUOTE (venom330 @ May 10 2011, 22:13) | | 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. | QUOTE (venom330 @ May 10 2011, 22:13) | I couldnt connect to the site  |
I've put up a mirror.
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
L0uNGeR  |
Posted: Tuesday, May 10 2011, 21:11
|
Ya, that's what I said.

Group: Members
Joined: Dec 3, 2008


|
| QUOTE (venom330 @ May 10 2011, 22:40) | | 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: | CODE | AnimationSet anims = new AnimationSet("amb@smoking_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); |
| QUOTE (venom330 @ May 10 2011, 22:40) | | 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 | CODE | // Get a close ped Ped p = World.GetClosestPed(Player.Character.Position, 15f);
// Ped belongs to Gang_Biker1 group p.RelationshipGroup = RelationshipGroup.Gang_Biker1;
// Ped's relation to Gang_Biker1 is Companion p.ChangeRelationship(RelationshipGroup.Gang_Biker1, Relationship.Companion);
// Make the ped HATE everybody except his companions foreach (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  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. | QUOTE | // Make the ped HATE everybody foreach (RelationshipGroup group in Enum.GetValues(typeof(RelationshipGroup))) { p.ChangeRelationship(group, Relationship.Hate); } |
(yay for syntax highlighting!) | QUOTE (venom330 @ May 10 2011, 22:40) | | 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. This post has been edited by L0uNGeR on Tuesday, May 10 2011, 22:21
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
venom330  |
Posted: Tuesday, May 10 2011, 23:26
|
Player Hater

Group: Members
Joined: May 10, 2011

|
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? Then all problems solved, from there i can learn alot and experiment This post has been edited by venom330 on Tuesday, May 10 2011, 23:55
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
venom330  |
Posted: Wednesday, May 11 2011, 08:31
|
Player Hater

Group: Members
Joined: May 10, 2011

|
nice hey i tested the testscript with the zombie and it looks awesome, it was exactly what i wanted, the same drunk animation 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 | CODE |
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(); }
}
}
| This post has been edited by venom330 on Wednesday, May 11 2011, 10:05
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
L0uNGeR  |
Posted: Wednesday, May 11 2011, 17:30
|
Ya, that's what I said.

Group: Members
Joined: Dec 3, 2008


|
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. | CODE | | 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.
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
L0uNGeR  |
Posted: Thursday, May 12 2011, 03:45
|
Ya, that's what I said.

Group: Members
Joined: Dec 3, 2008


|
| QUOTE (venom330 @ May 12 2011, 01:11) | | 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] )| QUOTE (venom330 @ May 12 2011, 01:11) | | and i cant use Dothezombie? |
You can use Dothezombie(), I just told you that you never use it. | QUOTE (venom330 @ May 12 2011, 01:11) | | 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 | CODE | 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. This post has been edited by L0uNGeR on Thursday, May 12 2011, 03:52
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
venom330  |
Posted: Thursday, May 12 2011, 12:16
|
Player Hater

Group: Members
Joined: May 10, 2011

|
Ok i try this | CODE | 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 This post has been edited by venom330 on Thursday, May 12 2011, 12:23
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
L0uNGeR  |
Posted: Thursday, May 12 2011, 19:48
|
Ya, that's what I said.

Group: Members
Joined: Dec 3, 2008


|
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 )| CODE | 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); } } } } } | This post has been edited by L0uNGeR on Thursday, May 12 2011, 21:10
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
Donny78  |
Posted: Saturday, May 14 2011, 15:12
|
Zombie

Group: Members
Joined: Jul 18, 2008


|
| QUOTE (L0uNGeR @ May 14 2011, 13:27) | 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. This post has been edited by Donny78 on Saturday, May 14 2011, 15:16
|
|
|
|
|
 |
|
 |
 |
|
 |
| |
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:
Pages:
(2) [1] 2
Track this topic
Receive email notification when a reply has been made to this topic and you are not active on the board.
Subscribe to this forum
Receive email notification when a new topic is posted in this forum and you are not active on the board.
Download / Print this Topic
Download this topic in different formats or view a printer friendly version.
| |
 |
|
 |
|
|
|
|