0

I am working on a script for a game and I am running into an error "The type 'GTA.Graphics' has no constructors defined" Here is the code:

        GTA.Graphics graphics = new GTA.Graphics();


    public void showFPS()
    {
        string fps = Game.FPS.ToString();
        if (Player.Character.isAlive)
        {
         graphics.DrawText(fps, 0.9f, 0.1f);
        }
    }

Any help will be much appreciated. Thanks.

@DOOMDUDEMX

I done

public void showFPS(GTA.GraphicsEventArgs e)
    {

        string fps = Game.FPS.ToString();
         e.Graphics.DrawText(fps, 0.9f, 0.1f);
        }

which works but causes a problem with my code that toggles this, the error I get from that is "No overload for 'showFPS' matches delegate 'GTA.KeyPressDelegate'"

Here is the code for toggle: BindKey(Keys.F7, new KeyPressDelegate(showFPS));

LetsPlayOrDy at gtaforums.com gave me the solution:

1: When the BindKey takes a function, the function should have no parameters (like this: public void showFPS() )

2: If you want to draw something, you have to use a PerFrameDrawing.

and the code:

BindKey(Keys.F7, new KeyPressDelegate(showFPS));
        PerFrameDrawing += tehDrawingMaster;
    }

    bool drawFPS = false;

    public void showFPS()
    {
        drawFPS = !drawFPS;
    }

    public void tehDrawingMaster(object sender, GTA.GraphicsEventArgs e)
    {
        if (drawFPS) e.Graphics.DrawText(Game.FPS.ToString(), 20, 20, System.Drawing.Color.Black)

Thank you all so much.

YeetMaster69
  • 15
  • 1
  • 3

1 Answers1

0

You need to learn more about object orientation.

GTA.Graphics is probably an abstract class which means you cannot create an instance of it. What you would have to do is create a new class that inherits from GTA.Graphics (if that is possible in your case) and write something like GTA.Graphics = new InheritedGraphics();

if GTA.Graphics comes from a library there might even be other classes already inheriting from GTA.Graphics which you could create an instance of instead.

However, as i said, what you need to take a look on is object oriented programming. You should be able to find the concept of a constructor pretty easily in any book or article on the subject.

DOOMDUDEMX
  • 644
  • 1
  • 8
  • 24
  • What about an internal constructor? He wouldn't be able to call it either – Marco Sep 26 '14 at 08:53
  • That is true! However the bottom line is still that he needs to learn more about object orientation. It seems that he lacks knowledge of the concept. To mention an internal constructor will probably not tell him much. Unless i interpret the situation wrong ofcourse. – DOOMDUDEMX Sep 26 '14 at 08:56
  • Could you post the entire file? – DOOMDUDEMX Sep 26 '14 at 09:10
  • do you mean the actual project file or just the code I wrote? – YeetMaster69 Sep 26 '14 at 09:12
  • It just occurred to me that you are trying to make a mod for GTA San Andreas, right? Try changing the function so it takes a n object too like this: public void showFPS(object sender, GTA.GraphicsEventArgs e) { string fps = Game.FPS.ToString(); e.Graphics.DrawText(fps, 0.9f, 0.1f); } – DOOMDUDEMX Sep 26 '14 at 09:21
  • its for GTA4. I tried but when I do GTA.Graphics it doesn't show DrawText or anything like that, just Convert, ConvertX, ConvertY, Equals and ReferenceEquals. – YeetMaster69 Sep 26 '14 at 09:25
  • I realized that and changed the previous comment. – DOOMDUDEMX Sep 26 '14 at 09:27
  • Basically it should be enough to change the first row of the function to: public void showFPS(object sender, GTA.GraphicsEventArgs e) – DOOMDUDEMX Sep 26 '14 at 09:30
  • I tried that but it causes an error with the code to toggle it. I edited it into OP if you want to see the code for the toggle. – YeetMaster69 Sep 26 '14 at 09:30
  • I dont have much experience with GTA-Modding and dont have more time at the moment so i might try to solve this late but i think it would be easier to get your answer if you asked your question on gtaforums.com instead. – DOOMDUDEMX Sep 26 '14 at 09:34
  • Ok no worries, thanks for taking the time to help me out. I'll post my question on the forum you mentioned and see what happens. Cheers. – YeetMaster69 Sep 26 '14 at 09:41
  • No problem. And if you find your answer you can post it here so others can find their answer if they find this question too. – DOOMDUDEMX Sep 26 '14 at 09:58