Log in to reply
 

My small script won't run. Can anyone search my mistake? I can't find it ;-;...



  • So I've been messing around and here I am making my first script. I've coded all of it but now when I put it in my scripts folder and run the game ScriptHook.Net doesn't even see it... Can anyone help? The idea of the mod is simple. I added 3 Vectors, When you go there you should have a marker and when near the marker you press E and you regenerate health for 10 Dollars. Here's the code, not that large:
    using GTA;
    using GTA.Native;
    using GTA.Math;
    using System;
    using System.Windows.Forms;
    using System.Collections.Generic;
    using System.IO;
    using System.Drawing;
    using System.Media;

    public class MedicalCenters : Script
    {
    private string modName = "MedicalCenters";
    private string modCreatorName = "Eyon";
    private string modVersion = "1.0";
    private Ped playerPed = Game.Player.Character;
    private Player player = Game.Player;
    Vector3 med1 = new Vector3(341.540f, -1398.300f, 32.509f);
    Vector3 med2 = new Vector3(360.836f, -585.269f, 28.826f);
    Vector3 med3 = new Vector3(-449.272f, -340.822f, 34.502f);

    public MedicalCenters()
    {
    	UI.Notify(modName + " created by " + modCreatorName + " version "  + modVersion);
    
        Tick += OnTick;
    
        KeyUp += OnKeyUp;
    }
    
    // This is where loops/things are run every frame.
    private void OnTick(object sender, EventArgs e)
    {
        Tick += (o, e) =>
        {
            if (playerPed.IsAlive && playerPed.IsVisible && !playerPed.IsDead)
            {
                World.DrawMarker(MarkerType.VerticalCylinder, med1, Vector3.Zero, Vector3.Zero, new Vector3(341.540f, -1398.300f, 32.509f), Color.Blue);
                var tmpSFs = new Scaleform("PLAYER_NAME_01");
                tmpSFs.CallFunction("SET_PLAYER_NAME", "Medical Center");
                tmpSFs.Render3D(marker2 + new Vector3(0f, 0f, 2f), new Vector3(1f, -141f, 1f), new Vector3(12, 6, 2));
    
                World.DrawMarker(MarkerType.VerticalCylinder, med2, Vector3.Zero, Vector3.Zero, new Vector3(360.836f, -585.269f, 28.826f), Color.Blue);
                var tmpSFs = new Scaleform("PLAYER_NAME_01");
                tmpSFs.CallFunction("SET_PLAYER_NAME", "Medical Center");
                tmpSFs.Render3D(marker2 + new Vector3(0f, 0f, 2f), new Vector3(1f, -141f, 1f), new Vector3(12, 6, 2));
    
                World.DrawMarker(MarkerType.VerticalCylinder, med3, Vector3.Zero, Vector3.Zero, new Vector3(-449.272f, -340.822f, 34.502f), Color.Blue);
                var tmpSFs = new Scaleform("PLAYER_NAME_01");
                tmpSFs.CallFunction("SET_PLAYER_NAME", "Medical Center");
                tmpSFs.Render3D(marker2 + new Vector3(0f, 0f, 2f), new Vector3(1f, -141f, 1f), new Vector3(12, 6, 2));
            }
        }
    
    }
    
    // When you press a key up or release it.
    private void OnKeyUp(object sender, KeyEventArgs e)
    {
        if (World.GetDistance(playerPed.Position, med1) < 1.5000f)
        {
            toolTip("Press ~INPUT_CONTEXT~");
    
            if (e.KeyCode == Keys.E)
            {
                try
                {
                    Game.Player.Money = -10;
                    Game.Player.Health = 200;
    
                }
                catch { UI.Notify("Your health has been restored."); }
            }
        }
    
        if (World.GetDistance(playerPed.Position, med2) < 1.5000f)
        {
            toolTip("Press ~INPUT_CONTEXT~");
    
            if (e.KeyCode == Keys.E)
            {
                try
                {
                    Game.Player.Money = -10;
                    Game.Player.Health = 200;
    
                }
                catch { UI.Notify("Your health has been restored."); }
            }
        }
    
        if (World.GetDistance(playerPed.Position, med3) < 1.5000f)
        {
            toolTip("Press ~INPUT_CONTEXT~");
    
            if (e.KeyCode == Keys.E)
            {
                try
                {
                    Game.Player.Money = -10;
                    Game.Player.Health = 200;
    
                }
                catch { UI.Notify("Your health has been restored."); }
            }
        }
    }
    

    }



  • Ooh seems like the fucking site fixed my issue xD



  • Nevermind I can't figure it out o-o



  • Help please?


  • MODERATOR

    Do you even know how to code? By looking at your code I can tell that you don't seem to know even the basics of programming...



  • @Eyon I can only agree with @Unknown-Modder . Please learn the basics of programming first. You made so many mistakes I don't feel like explaining it all to you.



  • @Cyron43 @Unknown Modder Yep, then I'm gonna take another course of C#... Sorry guys. Do you know any good C# tutorials on Youtube or anywhere? I've taken like 2 but I think those were a little outdated...



  • @Eyon
    What the hell is up with everybody and "YouTube tutorials" these days?

    First of all, either you're going to learn by experience or by getting into books. Preferably both. My school used Head First C# for basic C# and OOP principles.

    As for GTA V scripting, begin smaller. Try doing something on a button press. Try displaying a text continuously or setting a value continuously. Then, mash those together. You learn by doing, but you still need to start from a simple thing.


  • MODERATOR

    @Eyon I advise you to do what ikt said. Also, programming (for GTA) isn't just knowing C# + SHVDN (or a programming language in general), programming is thinking.



  • @ikt What do you mean books thou? You mean books about learning programming languages? I'm 14, and like... the only thing we did at our cheap Informatics lessons at school was messing around in Paint and Word. Pathetic, right? You hardly see any shops dedicated to gaming or other in my country. We don't even have GameStop. I live in Eastern EU, thou next year I'm moving to Germany. Now I hope this was enough personal life... I mean internet tutorials because It's the only way I can start doing some serious programming, which is my dream for the future... I'm really sorry if I wasted your time reading this. Just wanna express my feelings about this... I'm really trying hard to learn C#. And yes, experience is path number 2 im on right now. I might be going too complicated at first... Maybe I should stick with path 1 a little more...


  • MODERATOR

    @Eyon Don't feel bad, you're still young and have plenty of time to learn. I started learning right here in this community, looking at examples and YouTube of course. It wasn't until I had a C# class at my Uni that I really began to understand. There are many academic books you can read; the book my class used was "Starting Out with Visual C# 2012" by Gaddis, Tony (you can find it with a bit of searching). It's just basics, nothing too advanced.

    If you need examples specifically for GTA V, this really helped me starting out: https://pastebin.com/u/Eddlm



  • @Eyon YouTube is a bad choice. Try to get a book either in paper (try at Amazon) or digital (PDF, eBook) about C# general programming, not game development. Programming is not only knowing commands but also about how and when to use them. For example, a try/catch block is meant to be used for handling exceptions only and your event handling is - well I can't find a polite way to tell you. Another important aspect is the art of structured programming (software architecture).
    I'd say your first task is to learn how to search for those information and find a good book for beginners (read the reviews!).
    Also I highly recommend https://stackoverflow.com/. This is the place where developers go when they get stuck.
    Learning is the most essential part of being a developer. Take your time, read, read, read and start with small sample codes to get your head around what you just learned. Then make the next step. It will take several months of intensive learning before you should even think about developing script mods.
    BTW your English is excellent. :slight_smile:



  • @Cyron43 @stillhere Thank you very much! I did think before about buying a book. I guess now would be the time for it. :)



  • @Eyon I started out in C# using this:
    http://www.homeandlearn.co.uk/csharp/csharp.html
    It's really good and explains a lot of C# functions thoroughly or at least enough to know what they do xD It does teach windows forms programming, but the general concept is the same.



  • @Eyon Soon you will stumble across the HelloWorld code.

    using System;
    
    namespace MyHelloWorld
    {
       internal class Program
       {
          internal static void Main()
          {
             Console.WriteLine("Hello world");
             Console.WriteLine("\nPress any key to terminate the program.");
             Console.ReadKey();
          }
       }
    }
    

    Lame huh? Not so fast! Can you explain each and every bit? I don't expect you to explain it here. Just think about it and you will see there is much more than meets the eye at first glance. Start with the very first line.



  • @Cyron43 having it internal makes it a bit more complicated than it should



  • @AHK1221 I know but the console template has no written access modifiers at all. I just made them visible. :slight_smile:
    .Net script mods need all classes which inherit from Script to be public. Sooner or later he has to deal with it.



  • Just going to chime in and say that there are many useful online resources (besides youtube) that can help you learn. It doesn't necessarily have to be a book. For example, www.udemy.com. They offer tons of courses on every language you could imagine, many of them free. A lot of them are done by well respected university professors and cover pretty much everything you would learn in first year CS. One of the first things I did when I was learning was follow this course from start to finish.


Log in to reply
 

Looks like your connection to GTA5-Mods.com Forums was lost, please wait while we try to reconnect.