Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      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

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

(C# .NET) Can someone look at my script a tell me what my mistakes are and how to make it work?


Nyinny
 Share

Recommended Posts

 I'm an absolute beginner and trying to create a basic delivery mission but apparently, I couldn't make it work.

using System;
using System.Windows.Forms;
using GTA;
using GTA.Native;
using GTA.Math;
using System.Drawing;

namespace BurritoJob
{
    public class Main : Script
    {
        Blip BurritoJobBlip;
        Vector3 BurritoJobBlipPosition = new Vector3(5329.36f, -5182.76f, 81.66f);

        Vehicle burrito;

        int missionindex;
        bool IsBurritoJobActive = false;
        bool DestinationMarkerExcists;

        public Main()
        {
            Tick += onTick;
            KeyDown += onKeyDown;
        }
        private void onTick(object sender, EventArgs e)
        {
            if(IsBurritoJobActive == false)
            {
                Blip BurritoJobBlip;
                Vector3 BurritoJobBlipPosition = new Vector3(5329.36f, -5182.76f, 81.66f);

                BurritoJobBlip = World.CreateBlip(BurritoJobBlipPosition);
                BurritoJobBlip.Color = BlipColor.Yellow;
                BurritoJobBlip.Sprite = (BlipSprite)477;
                BurritoJobBlip.Name = "Burrito Job";

                World.DrawMarker(MarkerType.VerticalCylinder, BurritoJobBlipPosition, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(1.5f, 1.5f, 2.2f), Color.FromArgb(255, 255, 0));
            }

            if(IsBurritoJobActive == true)
            {
                missionindex = 0;

                Blip BurritoJobDestinationBlip;
                Vector3 BurritoJobDestinationBlipPosition = new Vector3(3334.38f, -4901.42f, 110.42f);

                switch (missionindex)
                {
                    case 0:
                        {
                            if (Game.Player.Character.IsInVehicle(burrito) || Game.Player.Character.IsSittingInVehicle(burrito))
                            {
                                missionindex = 5;
                            }
                            else
                            {
                                UI.Notify("Get in the van!");
                                Blip burritoBlip = burrito.AddBlip();
                                burritoBlip.Color = BlipColor.Blue;
                            }
                        }
                        break;
                    
                   
                    case 5:
                        {
                            DestinationMarkerExcists = true;
                            if (DestinationMarkerExcists)
                            {
                                BurritoJobDestinationBlip = World.CreateBlip(BurritoJobDestinationBlipPosition);
                                BurritoJobDestinationBlip.Color = BlipColor.Red;
                                BurritoJobDestinationBlip.Sprite = (BlipSprite)358;
                                BurritoJobDestinationBlip.Name = "Destination";
                                BurritoJobDestinationBlip.ShowRoute = true;
                                World.DrawMarker(MarkerType.VerticalCylinder, BurritoJobDestinationBlipPosition, new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(5f, 5f, 2.2f), Color.FromArgb(255, 255, 0));
                                UI.Notify("Deliver the goods to the destination");
                                if (burrito.Position.DistanceTo(BurritoJobDestinationBlipPosition) < 5f)
                                {
                                    missionindex = 10 ;
                                }
                            }
                        }
                        break;

                    case 10:
                        {
                            UI.Notify("Unloading truck...");
                            Game.Player.Character.FreezePosition = true;
                            burrito.FreezePosition = true;
                            Script.Wait(4000);
                            Game.Player.Character.FreezePosition = false;
                            burrito.FreezePosition = false;
                            missionindex = 15;
                        }
                        break;

                    case 15:
                        {
                            Game.Player.Money = Game.Player.Money + 8000;
                            UI.Notify("You earned ~g~$8000 ");
                            missionindex = 20;
                        }
                        break;

                    case 20:
                        {
                            DestinationMarkerExcists = false;
                            missionindex = 25;
                        }
                        break;

                    case 25:
                        {
                            Blip BringBackBurritoBlip = World.CreateBlip(BurritoJobDestinationBlipPosition);
                            BringBackBurritoBlip.Color = BlipColor.Red;
                            BringBackBurritoBlip.Sprite = (BlipSprite)358;
                            BringBackBurritoBlip.Name = "Destination";
                            BringBackBurritoBlip.ShowRoute = true;
                            World.DrawMarker(MarkerType.VerticalCylinder, new Vector3(5347.67f, -5201.07f, 82.60f), new Vector3(0f, 0f, 0f), new Vector3(0f, 0f, 0f), new Vector3(5f, 5f, 2.2f), Color.FromArgb(255, 255, 0));
                            UI.Notify("Bring back the van");
                            if (burrito.Position.DistanceTo(BurritoJobDestinationBlipPosition) < 5f)
                            {
                                burrito.Delete();
                                missionindex = 30;
                            }
                             
                        }
                        break;

                    case 30:
                        {
                            IsBurritoJobActive = false;
                        }
                        break;
                }

            }

        }
        private void onKeyDown(object sender, KeyEventArgs e)
        {
            if (Game.Player.Character.Position.DistanceTo(BurritoJobBlipPosition) < 1.6f)
            {
                DisplayHelpTextThisFrame("Press ~INPUT_CONTEXT~ to Start Burrito Job!");
                if (Game.IsEnabledControlJustPressed(2, GTA.Control.Context))
                {

                    burrito = World.CreateVehicle(VehicleHash.Burrito5, (new Vector3(5347.67f, -5201.07f, 82.60f)));
                    burrito.Heading = 0.94f;
                    
                    IsBurritoJobActive = true;
                }
            }
        }
            
        
        void DisplayHelpTextThisFrame(string text)
        {
            Function.Call(Hash._SET_TEXT_COMPONENT_FORMAT, "STRING");
            Function.Call(Hash._ADD_TEXT_COMPONENT_STRING, text);
            Function.Call(Hash._0x238FFE5C7B0498A6, 0, 0, 1, -1);
        }
        
    }
}

 

Edited by Nyinny
Link to comment
Share on other sites

poland stronk

C# and .NET aren't familiar to me.

 

Can you expand on the issue? Do you get any errors during compilation process, the script fails to initialize in the game or is this purely a question regarding one of the imported libraries and their usage?

 

Btw. why are you importing GTA.Native and GTA.Math if you have already invoked entire library (GTA) at the beginning? Like I said I don't know much about those languages but at least it should give you full access to all methods in your script.

Edited by poland stronk
Link to comment
Share on other sites

I want to create a mission where it spawns a van and you have to drive it to a certain location but something is always wrong and some parts of the mission don't load properly or don't even load at all. For example when it finally put the destination marker to its place, it should have also placed a blip on the map but nothing happened.

And although I'm making progress slowly, it always stops me that I can't figure out why my script doesn't work.

 

 

11 hours ago, poland stronk said:

Btw. why are you importing GTA.Native and GTA.Math if you have already invoked entire library (GTA) at the beginning? Like I said I don't know much about those languages but at least it should give you full access to all methods in your script.

https://pastebin.com/pKJ8vd7S  It's from this template i used.

  • Like 1
Link to comment
Share on other sites

Thank you, I watched the videos and created a similar simpler script but still have problems with the posted one. I guess I should slow down my pace and shouldn't start with a very complicated script.

Link to comment
Share on other sites

poland stronk
On 10/21/2020 at 1:05 PM, Nyinny said:

For example when it finally put the destination marker to its place, it should have also placed a blip on the map but nothing happened.

 

Look at your code in your switch block. The script breaks from the switch-case each time new mission stage is reached. You should write the entire mission in one case and use other cases when player for example blows up the van, attains wanted level or dies. The game should check those before initating code for the next mission objective. At least that's what I think is happening.

Edited by poland stronk
Link to comment
Share on other sites

I tried it and have made significant progress, most parts of the mission are working now. Thank you!!

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.