Advertisement
MulleDK19

Neon Glow script for GTA IV

Jul 14th, 2011
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.63 KB | None | 0 0
  1. // -----------------------------------------------------------------------
  2. // <copyright file="NeonGlow.cs" company="Morten">
  3. // 2011 © Morten T. Pedersen aka MulleDK19 ® All rights reserved.
  4. // </copyright>
  5. // -----------------------------------------------------------------------
  6.  
  7. namespace NeonGlow
  8. {
  9.     using System;
  10.     using System.Collections.Generic;
  11.     using System.Drawing;
  12.     using System.Linq;
  13.     using System.Text;
  14.     using GTA;
  15.  
  16.     /// <summary>
  17.     /// Makes your car glow
  18.     /// </summary>
  19.     public class NeonGlow : Script
  20.     {
  21.         #region Private Fields
  22.         /// <summary>
  23.         /// The Light object.
  24.         /// </summary>
  25.         private Light light;
  26.  
  27.         /// <summary>
  28.         /// The available colors.
  29.         /// </summary>
  30.         private Color[] colors;
  31.  
  32.         /// <summary>
  33.         /// The index of the current color.
  34.         /// </summary>
  35.         private int currentColor;
  36.  
  37.         /// <summary>
  38.         /// The timer used to keep change the light.
  39.         /// </summary>
  40.         private GTA.Timer glowTimer;
  41.         #endregion
  42.  
  43.         #region Constructors
  44.         /// <summary>
  45.         /// Initializes a new instance of the <see cref="NeonGlow"/> class.
  46.         /// </summary>
  47.         public NeonGlow()
  48.         {
  49.             this.Interval = 10;
  50.             this.Light = new Light(Color.Lime, 3, 100.0f);
  51.  
  52.             this.Tick += new EventHandler(this.NeonGlow_Tick);
  53.  
  54.             List<Color> colors = new List<Color>();
  55.             colors.Add(Color.Lime);
  56.             colors.Add(Color.Cyan);
  57.             colors.Add(Color.Pink);
  58.             colors.Add(Color.LightYellow);
  59.             this.Colors = colors.ToArray();
  60.             this.CurrentColor = 0;
  61.  
  62.             this.GlowTimer = new Timer(1000);
  63.             this.GlowTimer.Tick += new EventHandler(this.GlowTimer_Tick);
  64.             this.GlowTimer.Start();
  65.         }
  66.         #endregion
  67.  
  68.         #region Properties
  69.         /// <summary>
  70.         /// Gets the light.
  71.         /// </summary>
  72.         internal Light Light
  73.         {
  74.             get { return this.light; }
  75.             private set { this.light = value; }
  76.         }
  77.  
  78.         /// <summary>
  79.         /// Gets the colors.
  80.         /// </summary>
  81.         internal Color[] Colors
  82.         {
  83.             get { return this.colors; }
  84.             private set { this.colors = value; }
  85.         }
  86.  
  87.         /// <summary>
  88.         /// Gets the index of the current color.
  89.         /// </summary>
  90.         /// <value>
  91.         /// The index of the current color.
  92.         /// </value>
  93.         internal int CurrentColor
  94.         {
  95.             get { return this.currentColor; }
  96.             private set { this.currentColor = value; }
  97.         }
  98.  
  99.         /// <summary>
  100.         /// Gets the glow timer.
  101.         /// </summary>
  102.         internal GTA.Timer GlowTimer
  103.         {
  104.             get { return this.glowTimer; }
  105.             private set { this.glowTimer = value; }
  106.         }
  107.         #endregion
  108.  
  109.         #region Private Methods
  110.         /// <summary>
  111.         /// Handles the Tick event of the GlowTimer control.
  112.         /// </summary>
  113.         /// <param name="sender">The source of the event.</param>
  114.         /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  115.         private void GlowTimer_Tick(object sender, EventArgs e)
  116.         {
  117.             if (this.CurrentColor < this.colors.Length - 1)
  118.             {
  119.                 ++this.CurrentColor;
  120.             }
  121.             else
  122.             {
  123.                 this.CurrentColor = 0;
  124.             }
  125.  
  126.             this.Light.Color = this.Colors[this.CurrentColor];
  127.         }
  128.  
  129.         /// <summary>
  130.         /// Handles the Tick event of the NeonGlow control.
  131.         /// </summary>
  132.         /// <param name="sender">The source of the event.</param>
  133.         /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
  134.         private void NeonGlow_Tick(object sender, EventArgs e)
  135.         {
  136.             if (!Player.Character.isInVehicle())
  137.             {
  138.                 if (this.Light.Enabled)
  139.                 {
  140.                     this.Light.Enabled = false;
  141.                 }
  142.  
  143.                 return;
  144.             }
  145.             else
  146.             {
  147.                 if (!this.Light.Enabled)
  148.                 {
  149.                     this.Light.Enabled = true;
  150.                 }
  151.             }
  152.  
  153.             Vector3 position = this.Player.Character.CurrentVehicle.Position;
  154.             position = position.ToGround();
  155.             position.Z += 0.1f;
  156.             this.Light.Position = position;
  157.         }
  158.         #endregion
  159.     }
  160. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement