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

[BETA] GTAIV .Net ScriptHook


HazardX
 Share

Recommended Posts

I'm still learning this stuff and need a little help

I want to convert my lua code to C#

But I want to be able to use multiply keys for one function

For example in alice i do this

 

if (IsKeyPressed(15) == 1) and (IsKeyPressed(192) == 1) then

 

 

And I'm using this at the moment in my C# script

 

if (e.Key != Keys.Shift)

 

 

So how would I make it so I have to press 2 keys in order to do the next function

Link to comment
Share on other sites

So how would I make it so I have to press 2 keys in order to do the next function

There are several ways to do it.

 

Here are two ways if you want to use the KeyDown event:

 

private void BasicKeyExample_KeyDown(object sender, GTA.KeyEventArgs e) { if ((e.Key == Keys.M) && e.Shift) {   // do your stuff here } if (e.KeyWithModifiers == (Keys.M | Keys.Shift)) {   // do your stuff here }}

 

 

and here is another (the best IMO) using BindKey:

 

public class BasicKeyExample : Script { public BasicKeyExample() {   BindKey(Keys.M | Keys.Shift, new KeyPressDelegate(MyFunction)); } private void MyFunction() {   // do your stuff here }}

 

Link to comment
Share on other sites

 

So how would I make it so I have to press 2 keys in order to do the next function

There are several ways to do it.

 

Here are two ways if you want to use the KeyDown event:

 

private void BasicKeyExample_KeyDown(object sender, GTA.KeyEventArgs e) { if ((e.Key == Keys.M) && e.Shift) {   // do your stuff here } if (e.KeyWithModifiers == (Keys.M | Keys.Shift)) {   // do your stuff here }}

 

 

and here is another (the best IMO) using BindKey:

 

public class BasicKeyExample : Script { public BasicKeyExample() {   BindKey(Keys.M | Keys.Shift, new KeyPressDelegate(MyFunction)); } private void MyFunction() {   // do your stuff here }}

 

Thanks Hazardx

 

Yay! Its working!

Edited by lilmcnessy
Link to comment
Share on other sites

 

I'm still learning this stuff and need a little help

I want to convert my lua code to C#

But I want to be able to use multiply keys for one function

For example in alice i do this

 

...

 

 

So how would I make it so I have to press 2 keys in order to do the next function

You could do something like this for the keydown event:

 

 

if (e.Key == Keys.A)   {       if (isKeyPressed(Keys.Shift))       {            //code goes here, will run when SHIFT+A is pressed.       }   }

 

 

Or if you want to do it in the tick event for some reason:

 

 

if (isKeyPressed(Keys.A) && isKeyPressed(Keys.Shift)) { ...

 

Link to comment
Share on other sites

Now i need help with a random code

This is what I did in alice

 

BagColour = math.random(3) -- randomly select one of the 3 specified bags.if BagColour == 1 thenSET_CHAR_COMPONENT_VARIATION(PLAYER_CHAR, 3, 3, 0) Wait(100) end -- Small bag Brownif BagColour == 2 thenSET_CHAR_COMPONENT_VARIATION(PLAYER_CHAR, 3, 3, 1) Wait(100) end -- Small bag Blueif BagColour == 3 thenSET_CHAR_COMPONENT_VARIATION(PLAYER_CHAR, 3, 3, 2) Wait(100) end -- Small bag Green

 

 

And i need a way to get the playindex please biggrin.gif

Link to comment
Share on other sites

 

Now i need help with a random code

This is what I did in alice

 

BagColour = math.random(3) -- randomly select one of the 3 specified bags.if BagColour == 1 thenSET_CHAR_COMPONENT_VARIATION(PLAYER_CHAR, 3, 3, 0) Wait(100) end -- Small bag Brownif BagColour == 2 thenSET_CHAR_COMPONENT_VARIATION(PLAYER_CHAR, 3, 3, 1) Wait(100) end -- Small bag Blueif BagColour == 3 thenSET_CHAR_COMPONENT_VARIATION(PLAYER_CHAR, 3, 3, 2) Wait(100) end -- Small bag Green

 

 

And i need a way to get the playindex please  biggrin.gif

No need for a native call, there is a .Net function for it already:

 

in VB:

 

Player.Skin.SetComponent(3, 3, 1)

 

or in C#:

 

Player.Skin.SetComponent((PedComponent)3, 3, 1)

 

 

smile.gif

Link to comment
Share on other sites

 

Now i need help with a random code

This is what I did in alice

 

BagColour = math.random(3) -- randomly select one of the 3 specified bags.if BagColour == 1 thenSET_CHAR_COMPONENT_VARIATION(PLAYER_CHAR, 3, 3, 0) Wait(100) end -- Small bag Brownif BagColour == 2 thenSET_CHAR_COMPONENT_VARIATION(PLAYER_CHAR, 3, 3, 1) Wait(100) end -- Small bag Blueif BagColour == 3 thenSET_CHAR_COMPONENT_VARIATION(PLAYER_CHAR, 3, 3, 2) Wait(100) end -- Small bag Green

 

 

And i need a way to get the playindex please  biggrin.gif

No need for a native call, there is a .Net function for it already:

 

in VB:

 

Player.Skin.SetComponent(3, 3, 1)

 

or in C#:

 

Player.Skin.SetComponent((PedComponent)3, 3, 1)

 

 

smile.gif

Thank you so much! I couldn't figure out how to get that working

Now I have the props working aswell

Now how could I get it to randomise between 3 different components

 

I copied these from one of your example scripts

 

SkinTemplate SavedSkinSavedSkin = Player.SkinPlayer.Skin.Template = SavedSkin

 

But when I use it and restore to my previous skin it takes away my armour mercie_blink.gif

It also sets my heading north but i do not have a problem with this

Edited by lilmcnessy
Link to comment
Share on other sites

Hm found something wierd. When i declare a Timer in my Private, and assign it in my constructor along with the Tick event handler and the Interval, it start automaticly without me calling the Start method (thats under a KeyDown)... When i commend out the Interval it does not start. Is this intended? kinda rules out the Start() method?

Link to comment
Share on other sites

Hm found something wierd. When i declare a Timer in my Private, and assign it in my constructor along with the Tick event handler and the Interval, it start automaticly without me calling the Start method (thats under a KeyDown)... When i commend out the Interval it does not start. Is this intended? kinda rules out the Start() method?

Yes, this is intended. The Tick event will always fire when Interval is > 0. The Start method is just meant to reset the "ElapsedTime" value back to 0. This is a a relict from times where the Timer had no Interval or Tick event. The whole thing is pretty confusing right now TBH. I'll change the behavior in the next version and add descriptions to all methods of the Timer class.

Link to comment
Share on other sites

 

Hm found something wierd. When i declare a Timer in my Private, and assign it in my constructor along with the Tick event handler and the Interval, it start automaticly without me calling the Start method (thats under a KeyDown)... When i commend out the Interval it does not start. Is this intended? kinda rules out the Start() method?

Yes, this is intended. The Tick event will always fire when Interval is > 0. The Start method is just meant to reset the "ElapsedTime" value back to 0. This is a a relict from times where the Timer had no Interval or Tick event. The whole thing is pretty confusing right now TBH. I'll change the behavior in the next version and add descriptions to all methods of the Timer class.

Its indeed confusing...

 

Btw, is it somehow possible to make a separate file that contains description of all the methods in the scripthook? That If so i would love to help out 'documenting' the methods. And when its 'finished' you can compile it into the hook?

 

Btw2: Did ya see my sweet Task function i cleaned up? Or is it already in? Couldnt find it.

Link to comment
Share on other sites

Btw, is it somehow possible to make a separate file that contains description of all the methods in the scripthook? That If so i would love to help out 'documenting' the methods. And when its 'finished' you can compile it into the hook?

 

Btw2: Did ya see my sweet Task function i cleaned up? Or is it already in? Couldnt find it.

I don't know a way to extract all method information into an external file, but there surely is. I'll take a look...

 

Yes, i've seen your Task function. Very cool, indeed. smile.gif I'll include it in the next release.

Link to comment
Share on other sites

Is there anyway to stop these from stealing your body armour and weapons?

 

SkinTemplate SavedSkinSavedSkin = Player.SkinPlayer.Skin.Template = SavedSkin

 

Link to comment
Share on other sites

Is there anyway to stop these from stealing your body armour and weapons?

 

SkinTemplate SavedSkinSavedSkin = Player.SkinPlayer.Skin.Template = SavedSkin

 

Yes, the next version of the hook will store and reassign all health, armor, weapons and the wanted level on a skin change. They disappear because a skin change results in the whole character being removed and a new one being generated.

Link to comment
Share on other sites

Is there anyway to stop these from stealing your body armour and weapons?

 

SkinTemplate SavedSkinSavedSkin = Player.SkinPlayer.Skin.Template = SavedSkin

 

Yes, the next version of the hook will store and reassign all health, armor, weapons and the wanted level on a skin change. They disappear because a skin change results in the whole character being removed and a new one being generated.

Of course, everything changes when you change the player model.

 

I went so far, that I transfer, health, ammo, weapons, ammo for weapons, wanted level and some things I probably fortet now smile.gif

Link to comment
Share on other sites

NEW VERSION:

 

GTAIV .Net Script Hook v0.892 BETA

 

Changes in Version 0.892 BETA:

- Added Texture class and Graphics.DrawSprite methods

- Added TextureDrawingExample which draws a simple RPM gauge next to the radar while driving

- Added GTA.Forms.Imagebox control

- Improved drawing performance of windows generated with GTA.Forms

- Integrated Vector2, Vector3, Vector4, Quaternion and Matrix classes from SlimDX for advanced vector operations

- Fixed ApplyForce to take world vectors and added ApplyRelativeForce for object vectors

- Added Model.GetDimensions functions to retrieve the size of a model

- The player keeps weapons, armor, health and wanted level on a model change now

- Revamped the Timer class to be more convenient

- Several Font properties can now only be assigned on Font creation. This prevents a potential memory leak.

- A bunch of new functions in several classes (thanks CoMPMStR and Intosia)

- Yet again some breaking changes. Check your scripts!

 

Screenshot of the RPM gauge:

user posted image

Link to comment
Share on other sites

Black Patriot

The new version has much better performance with the forms, thanks Hazard. Used to get 10-15FPS drop, now its only 5-6, which is much better. Also that texture stuff is awesome, I've already integrated the RPM meter with the speedometer in my Trainer. Keep up the good work. biggrin.gif

Edited by Black Patriot
Link to comment
Share on other sites

OMG thanks for the advanced vector operations. Now I can put some of my XNA knowledge to use with this. Creating matricies never felt so good. lol.gif

 

As for the Model.GetDimensions method; the one that takes 2 arguments, not the new function; should we not use that one or does it matter anymore? Before when I used it, the ByRef vectors always returned 0 for each property, just wondering if that's still likely to happen.

Link to comment
Share on other sites

I've been waiting for this version, fantasic work hazard!

 

@ComMPMSt, same with me. Although I disagree on it feeling good creating matrices, lol.

Link to comment
Share on other sites

OMG thanks for the advanced vector operations. Now I can put some of my XNA knowledge to use with this. Creating matricies never felt so good. lol.gif

 

As for the Model.GetDimensions method; the one that takes 2 arguments, not the new function; should we not use that one or does it matter anymore? Before when I used it, the ByRef vectors always returned 0 for each property, just wondering if that's still likely to happen.

The Model.GetDimensions with two vectors works correctly now. It is rquired because the point 0,0,0 in an model is not always the center and thus pure length/width/height information isn't enough to determine the boundaries.

 

For the vector math classes: Those fully managed matrices of MDX/XNA/SlimDX really are pure sexyness. lol.gif

But i left out several methods to keep the classes simple. Please tell me if you are missing something important because i was overzealous and removed too much.

Link to comment
Share on other sites

BTW: You can use the following code to get the exact location where the user clicked on a GTA.Forms control:

 

   Private Sub Imagebox1_Click(ByVal sender As Object, ByVal e As GTA.MouseEventArgs) Handles Imagebox1.Click     Game.DisplayText("Clicked image at " & Imagebox1.PointToClient(e.PixelLocation).ToString)  End Sub

 

 

Control.PointToClient takes screen coordinates (as supplied by the MouseEventArgs) and returns the position inside the control. This is especially handy if you want to have an Imagebox with clickable areas and stuff like that.

Link to comment
Share on other sites

thaCURSEDpie

WOOOHOOO biggrin.gif. Came back from my holiday today. Checked my mail 'n stuff. Decided to check the GtaForums ("probably nothing new, but oh well...") and then I find... THIS! A new version of the script-hook?

 

Thank you!

 

(or... not tounge.gif. Now I have to spend a lot of time in my holiday on modding GTA biggrin.gif)

Link to comment
Share on other sites

Did you remove the drawLight method from Graphics?

Yes, DrawLight didn't work very well anymore because PerFrameDrawing is Driect3D now and runs AFTER the game has drawn the full scene. Instead there is a Light class now which works like any other object with Position property and stuff.

 

@thaCURSEDpie: I can feel your pain... i also spent alot more time on it (again) than i wanted to. wink.gif

Link to comment
Share on other sites

thaCURSEDpie

It's awesome that we now can get the ped the player is aiming at smile.gif. Opens up very sadistic possibilities devil.gif (Kill ped player aims at, for example. OR, set that ped on fire)

 

Tiny side-question:

Everytime I press L the camera changes to something high above the player (GTA 2 style). Is this standard in the new .net hook? Or is it a normal option in GTA:IV? lol.

Link to comment
Share on other sites

It's awesome that we now can get the ped the player is aiming at smile.gif. Opens up very sadistic possibilities devil.gif (Kill ped player aims at, for example. OR, set that ped on fire)

 

Tiny side-question:

Everytime I press L the camera changes to something high above the player (GTA 2 style). Is this standard in the new .net hook? Or is it a normal option in GTA:IV? lol.

LOL, I have the same problem, but then again I use C06alt's first person mod smile.gif

 

 

Link to comment
Share on other sites

Outstanding work HazardX biggrin.gif Texture stuff is just awesome.

But I still have problem with changing from any model back to niko's (PLAYER) - when I enter a bike, and niko tries to put on his helmet hame crashes. I know this is not .net scripthook falut, but is there ANY possibility to get it working? I tried everything but it keeps crashing. Is it possible to, for example, store player's ped pointer somewhere in memory and then load it back (since on player model change new ped is created and that "original, working" is lost)? Can it be done using memory adresses, etc?

Link to comment
Share on other sites

Outstanding work HazardX biggrin.gif Texture stuff is just awesome.

But I still have problem with changing from any model back to niko's (PLAYER) - when I enter a bike, and niko tries to put on his helmet hame crashes. I know this is not .net scripthook falut, but is there ANY possibility to get it working? I tried everything but it keeps crashing. Is it possible to, for example, store player's ped pointer somewhere in memory and then load it back (since on player model change new ped is created and that "original, working" is lost)? Can it be done using memory adresses, etc?

Store the original player skin before changing it and afterwards write it back (as shown in the included example). I guess you will not get any crashes this way. If you just set the model to "PLAYER" there may be components active that are not valid for the player skin and thus lead to a crash. If you store the skin, all components and stuff will be fully restored.

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.