Jump to content

Help with a simple script


zmitchell

Recommended Posts

I'm TRYING to learn how to script but having issues getting the hang of it. Would anyone be willing to show me an example of a simple script to bind a key to turn the headlights on/off so I don't have to use the trainer for it? A full CS example or even a point in the right direction would be appreciated smile.gif

 

Also, where are some good example scripts and resources for getting started with scripting? I have some awesome ideas I'd love to make happen!

Link to comment
Share on other sites

Here's a fairly extensive tutorial on C# scripting: http://www.gtaforums.com/index.php?showtopic=401577

 

For more examples, get the .NET scripthook and look in the "Grand Theft Auto IV\scripts\for Developers" folder.

 

Here's how I would make the headlights script:

 

using System;using System.Windows.Forms;using GTA;public class ToggleHeadlights : Script {   // Initialization   public ToggleHeadlights() {       KeyDown += new GTA.KeyEventHandler(ToggleHeadlights_KeyDown);   }   // This runs when any key is pressed   public void ToggleHeadlights_KeyDown(object sender, GTA.KeyEventArgs e) {       // If the pressed key is F1 and player is in a vehicle       if (e.Key == Keys.F1 && Player.Character.isSittingInVehicle()) {           Vehicle v = Player.Character.CurrentVehicle;           if (v.LightsOn)               GTA.Native.Function.Call("FORCE_CAR_LIGHTS", v, 1); // force lights always off           else               GTA.Native.Function.Call("FORCE_CAR_LIGHTS", v, 2); // force lights always on       }   }}

 

I didn't test that, but it would probably work. Good luck! smile.gificon14.gif

Edited by AngryAmoeba
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
  • 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.