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

    3. Suggestions

C# .net scripting, please help a noob with some stuff :)


ShadowCoderKing
 Share

Recommended Posts

ShadowCoderKing

hi im very new at this and im only used to making cleo mods for sa so please bear with me

 

how do i stop spawned peds from dying in one hit from a head shot ?

 

i'd like to get subtitle text to appear in game when i want but dont know the codes

 

i'd like to start making mission type script mods and im open to any help and advice thanks : )

Edited by SpiderMight
Link to comment
Share on other sites

SpiderMight. I'm new to C# too. I have managed to script a mod that allows me to spawn in peds. So, I'm going to give you a part of my code.

 

 

if(e.KeyCode == Keys.H) ((Remove these messages that have double brackets. You can change 'H' to any key you'd like to.))
{
Ped player = Game.Player.Character;
GTA.Math.Vector3 SpawnLoc = player.Position + (player.ForwardVector * 5); ((If you know how to change the direction that the ped spawns in, you may do so.))
string model_name = "a_c_husky"; ((You don't need to spawn in a Husky. You can change that. I chose a Husky, because it was what I used when I made this script.))
Ped companion = GTA.World.CreatePed(model_name, SpawnLoc);
}
}
}

I hope my code is simple enough and tidy enough for you to understand and implement into your script. I do not need credit, or gratitude. I only want you to thrive in scripting. :)

Link to comment
Share on other sites

ShadowCoderKing

thanks wolfgum.

 

how do i remove a blip from a ped, when i try it always stays on the radar

   Blip OneMarker = EnemyOne.AddBlip();     if (Entity.Exists(EnemyOne) && EnemyOne.IsDead)           {                EnemyOne.Delete();                OneMarker.Remove();             }
Edited by SpiderMight
Link to comment
Share on other sites

sollaholla

 

thanks wolfgum.

 

how do i remove a blip from a ped, when i try it always stays on the radar

 

Make sure you're not doing:

EnemyOne.AddBlip();

-- in the OnTick method. You should only be adding the blip to the Ped when you create him/her. (In your case at-least)

 

 

 

And remove the blip like this:

if (Entity.Exists(EnemyOne) && EnemyOne.IsDead){    // Yep, that's right, that's it. Since the blip is attached to EnemyOne, once you delete     // the ped, the blip will also be removed.    EnemyOne.Delete();}
Edited by sollaholla
Link to comment
Share on other sites

ShadowCoderKing

that is simple thank you, do you know how to add subtitle text on the screen ?

Edited by SpiderMight
Link to comment
Share on other sites

sollaholla

that is simple thank you, do you know how to add subtitle text on the screen ?

Absolutely! All you need to do is make a static call to the GTA.UI class.

// This is the first override.GTA.UI.ShowSubtitle ("My Text Goes Here");// This is the second override.GTA.UI.ShowSubtitle ("My Text Goes Here", /*duration in milliseconds.*/ 7000);// There are other methods of notification as well.GTA.UI.Notify ("This is a notification!");
Link to comment
Share on other sites

ShadowCoderKing

thanks so much !!

 

also how do i make multiple IFs

if (Entity.Exists(Enemy1) && Enemy1.IsDead && Entity.Exists(Enemy2) && Enemy2.IsDead)//does it work like this to have multiple IFs in the one code, just keep adding && ?
Edited by SpiderMight
Link to comment
Share on other sites

sollaholla
if (Entity.Exists(Enemy1) && Enemy1.IsDead && Entity.Exists(Enemy2) && Enemy2.IsDead)//does it work like this to have multiple IFs in the one code, just keep adding && ?

Woahhh, you definitely don't want to do that. You're going to need to create a list. Which is WAY more suited to what you want to do.

public MyConstructor (){    MyPeds = new List<Ped>();    KeyUp += OnKeyUp;    Tick += OnTick;}// At the top of your program make sure to add "using System.Collections.Generic;"public List<Ped> MyPeds { get; }private void OnKeyUp (object sender, KeyEventArgs e){    // This goes down to after you create your ped    MyPeds.Add (thePedICreated);    // Do other stuff}private void OnTick (object sender, EventArgs e){    // Make sure at the top of your program to add "using System.Linq;"    // This is what's called a for loop, you can read more about it here: https://docs.microsoft.com/en-us/dotnet/articles/csharp/language-reference/keywords/for    for (int i = 0; i < MyPeds.Count; i++)    {        // Now we're inside the loop (iterating over each ped in the list.        // Let's make sure to grab a ped from the stack.        Ped p = MyPeds[i];        if (Entity.Exists (p) && p.IsDead)        {            p.Delete();        }    }    // This is a difficult one to explain but we're basically removing any dead peds from the list,    // this way our list isn't filled with empty references.    // Read more here: https://msdn.microsoft.com/en-us/library/bb549418(v=vs.110).aspx    MyPeds = MyPeds.Where (x => Entity.Exists(x) && !x.IsDead).ToList();}
Edited by sollaholla
Link to comment
Share on other sites

ShadowCoderKing
public MyConstructor (){    MyPeds = new List<Ped>(); // MyPeds comes up with an error on this line, its read only    KeyUp += OnKeyUp;    Tick += OnTick;}

Thanks but how to fix MyPeds part ?

its got a read only error

Link to comment
Share on other sites

sollaholla
public MyConstructor (){    MyPeds = new List<Ped>(); // MyPeds comes up with an error on this line, its read only    KeyUp += OnKeyUp;    Tick += OnTick;}

Thanks but how to fix MyPeds part ?

its got a read only error

 

Ensure that the name of your constructor is the same name as your class.

Link to comment
Share on other sites

ShadowCoderKing

i cant get it to work, it still come up with read only error and whats the code to spawn peds using this list method, can you please fix it up for me thanks

using GTA;using GTA.Math;using GTA.Native;using System;using System.Windows.Forms;using System.Collections.Generic;using System.Linq;public class Mission1 : Script{    int EnemyRelationShipGroup = Function.Call<int>(Hash.GET_HASH_KEY, "HATES_PLAYER");     public Mission1()    {        MyPeds = new List<Ped>();        Tick += OnTick;        KeyDown += OnKeyDown;        KeyUp += OnKeyUp;    }    private void OnTick(object sender, EventArgs e)    {        for (int i = 0; i < MyPeds.Count; i++)        {            // Now we're inside the loop (iterating over each ped in the list.            // Let's make sure to grab a ped from the stack.            Ped p = MyPeds[i];            if (Entity.Exists(p) && p.IsDead)            {                p.Delete();            }        }        MyPeds = MyPeds.Where(x => Entity.Exists(x) && !x.IsDead).ToList();    }    void OnKeyDown(object sender, KeyEventArgs e)    {    }    public List<Ped> MyPeds { get; }    void OnKeyUp(object sender, KeyEventArgs e)    {        if (e.KeyCode == Keys.U)        {            // how do i spawn peds using this list method         }    }}
Edited by SpiderMight
Link to comment
Share on other sites

ShadowCoderKing

bump sorry for double post but i need help :(

Edited by SpiderMight
Link to comment
Share on other sites

sollaholla

Do it the same way you did it previously, except after you create the ped, just write:

MyPeds.Add(thePedYouJustCreated);
Link to comment
Share on other sites

Lancerator

I only have to say that your videos are so f*cking sh*tty.

  • Like 1
Link to comment
Share on other sites

ShadowCoderKing

 

Do it the same way you did it previously, except after you create the ped, just write:

MyPeds.Add(thePedYouJustCreated);

thanks :)

 

how do i make the script wait an infinite amount of time ?

Script.Wait(infinite); // not working for me
Edited by SpiderMight
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.