Jump to content

Neon c#


YossiBz

Recommended Posts

i try to do neon to vehicle this is my function:

private void DrawLight(Vehicle v,Vector3 Offset,Single Radius)        {            Vector3 pos = FZ(v.GetOffsetPosition(Offset));            Light light = new Light();            light.Color = ColorIndex.Blue;            light.Position = pos;            light.Range = Radius;            light.Intensity = 40;            light.Enabled = true;        }private Vector3 FZ(Vector3 Position)        {            float Ground = World.GetGroundZ(Position + Z1000) + ZOffset;            if (Position.Z < Ground)                Position.Z = Ground;            return Position;        }

and this is on drawing

Vehicle v = Player.Character.CurrentVehicle;                DrawLight(v, Offset1, 3.0F);                DrawLight(v, Offset2, 3.0F);                DrawLight(v, Offset3, 1.5F);                DrawLight(v, Offset4, 1.5F);

its show the light but it spreads the light on ground

Edited by YossiBz
Link to comment
https://gtaforums.com/topic/764788-neon-c/
Share on other sites

Really ?

        GTA.Timer timer = new GTA.Timer(); // global        Light light = new Light(); // global        public Main()        {            this.Interval = 10;            timer.Interval = 10;            timer.Tick += timer_Tick;            timer.Start();        }        void timer_Tick(object sender, EventArgs e)        {                        if(light != null && light.Enabled)            {                Vector3 pos = FZ(v.GetOffsetPosition(Offset));                light.Position = pos;            }        }

Best wishes,

Paul.

  • Like 2
Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066904028
Share on other sites

Really ?

        GTA.Timer timer = new GTA.Timer(); // global        Light light = new Light(); // global        public Main()        {            this.Interval = 10;            timer.Interval = 10;            timer.Tick += timer_Tick;            timer.Start();        }        void timer_Tick(object sender, EventArgs e)        {                        if(light != null && light.Enabled)            {                Vector3 pos = FZ(v.GetOffsetPosition(Offset));                light.Position = pos;            }        }

Best wishes,

Paul.

its give me error when i add Light light = new Light();:

Error in constructor of script 'Seller.Seller':                      System.Exception: Unable to determine the owning Script for this object!                         at GTA.ScriptThread.LoadScriptNow()
Edited by YossiBz
Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066904257
Share on other sites

        public Main()        {            this.Interval = 10;        }

"this.Interval = 10;" is useless because it is never used :)

 

its give me error when i add Light light = new Light();:

Error in constructor of script 'Seller.Seller':                      System.Exception: Unable to determine the owning Script for this object!                         at GTA.ScriptThread.LoadScriptNow()

Are you sure it is "Light light = new Light();" that is causing the error?

Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066904351
Share on other sites

 

        public Main()        {            this.Interval = 10;        }

"this.Interval = 10;" is useless because it is never used :)

 

its give me error when i add Light light = new Light();:

Error in constructor of script 'Seller.Seller':                      System.Exception: Unable to determine the owning Script for this object!                         at GTA.ScriptThread.LoadScriptNow()

Are you sure it is "Light light = new Light();" that is causing the error?

 

Yes i try to put just this and its give me the error

Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066904423
Share on other sites

... what if constructors are called prior to the script hook being initialized fully? Try invoking the code on the first Tick.

Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066904535
Share on other sites

 

Yes i try to put just this and its give me the error

And when you remove that line of code the script works again?

Yes

... what if constructors are called prior to the script hook being initialized fully? Try invoking the code on the first Tick.

i dont have a tick in my program

Edited by YossiBz
Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066904702
Share on other sites

 

LetsPlayOrDy,

I haven't used c# in a while. So I everything wrote in VS and used my old project and just accidentally copied that :)

 

YossiBz,

Can you show you ctor ?

 

Best regards,

Paul.

what its ctor?

"a constructor (abbreviation: ctor) in a class is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables."

Example:

public class MyClass{    private int a;    private string b;     // Constructor (ctor)    public MyClass() : this(42, "string")     {    }     // Overloading a constructor    public MyClass(int a, string b)    {        this.a = a;        this.b = b;    }}
Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066905039
Share on other sites

 

 

LetsPlayOrDy,

I haven't used c# in a while. So I everything wrote in VS and used my old project and just accidentally copied that :)

 

YossiBz,

Can you show you ctor ?

 

Best regards,

Paul.

what its ctor?

"a constructor (abbreviation: ctor) in a class is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables."

Example:

public class MyClass{    private int a;    private string b;     // Constructor (ctor)    public MyClass() : this(42, "string")     {    }     // Overloading a constructor    public MyClass(int a, string b)    {        this.a = a;        this.b = b;    }}

 

Constructor - in this case, public Main ()

 

 

Best wishes,

Paul.

    {private bool Menu;        Light light = new Light();        private bool Neon;        private SelectionMenu g_SelectionM;        private GTA.Font Font;        private Size res = Game.Resolution;        private int NormalPrice = 50000;        private int BoatPrice = 75000;        private int BikePrice = 25000;        private int PlanePrice = 125000;        public Vector3 Offset1 = new Vector3(-0.5f, 0f, -1f);        public float ZOffset = 0.25f;        public Vector3 Z1000 = new Vector3(0f, 0f, 5f);        public Seller()        {            CheckIniExists();            base.BindKey(Keys.F3, new KeyPressDelegate(this.ToggleMenu));            base.BindKey(Keys.F5, new KeyPressDelegate(this.ToggleNeon));            base.BindKey(Keys.NumPad2, new KeyPressDelegate(this.GoDown));            base.BindKey(Keys.NumPad5, new KeyPressDelegate(this.DoTask));            base.BindKey(Keys.NumPad8, new KeyPressDelegate(this.GoUp));            this.Font = new GTA.Font("Pricedown", 15f, FontScaling.Pixel);            base.PerFrameDrawing += new GraphicsEventHandler(Seller_PerFrameDrawing);            base.Interval = 0x9c4;            base.Tick += new EventHandler(this.Lights_Tick);        }
Edited by YossiBz
Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066905052
Share on other sites

Why did you use "0x9c4" instead of just "2500"? :lol:

probably from some CIL decompiler :p

Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066905119
Share on other sites

Then move lights, to intiliaze in timer or ctor... but that's strange.

 

Best regards,

Paul.

how this is what i have in function:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using GTA;using GTA.Forms;using GTA.Native;using System.Windows.Forms;using System.Drawing;using System.IO;namespace Seller{    public class Seller : Script    {        private bool Menu;        private bool Neon;        private SelectionMenu g_SelectionM;        private GTA.Font Font;        private Size res = Game.Resolution;        private int NormalPrice = 50000;        private int BoatPrice = 75000;        private int BikePrice = 25000;        private int PlanePrice = 125000;        public Vector3 Offset1 = new Vector3(-0.5f, 0f, -1f);        public float ZOffset = 0.25f;        public Vector3 Z1000 = new Vector3(0f, 0f, 5f);        private Model[] lamps = new Model[] {             "BM_NYtrafflite_11", "BM_NYtraflite10", "BM_NYtraflite2b", "BM_NYtraflite3a", "BM_NYtraflite3b", "BM_NYtraflite3c", "BM_NYtraflite6c", "BM_NYtraflite6c2", "BM_NYtraflite6d", "BM_NYtraflite6d2", "BM_NYtraflite8", "BM_NYlamp1", "BM_NYlamp1_italy", "BM_NYlamp10", "BM_NYlamp110b", "BM_NYlamp12",             "BM_NYlamp1a", "BM_NYlamp1b", "BM_NYlamp1c", "BM_NYlamp2a", "BM_NYlamp2b", "BM_NYlamp3", "BM_NYlamp4", "BM_NYlamp5", "BM_NYlamp6", "BM_NYlamp6a", "BM_NYlamp6c", "BM_NYlamp7", "BM_NYlamp7_b", "BM_NYlamp7_c", "BM_NYlamp8a", "BM_NYlamp9",             "cj_nylamp1", "cj_nylamp2", "cj_nylamp2b"         };        public Seller()        {            CheckIniExists();            base.BindKey(Keys.F3, new KeyPressDelegate(this.ToggleMenu));            base.BindKey(Keys.F5, new KeyPressDelegate(this.ToggleNeon));            base.BindKey(Keys.NumPad2, new KeyPressDelegate(this.GoDown));            base.BindKey(Keys.NumPad5, new KeyPressDelegate(this.DoTask));            base.BindKey(Keys.NumPad8, new KeyPressDelegate(this.GoUp));            this.Font = new GTA.Font("Pricedown", 15f, FontScaling.Pixel);            base.PerFrameDrawing += new GraphicsEventHandler(Seller_PerFrameDrawing);            Interval = 2500;            Tick += new EventHandler(this.TrafficLights_Tick);        }        public void TrafficLights_Tick(object sender, EventArgs e)        {            GTA.Object[] allObjects = World.GetAllObjects();            foreach (GTA.Object obj2 in allObjects)            {                foreach (Model model in this.lamps)                {                    if (base.Exists((GTA.Object) obj2) && (obj2.Model == model))                    {                        obj2.FreezePosition = true;                    }                }            }            Light light = new Light();            GTA.Timer timer = new GTA.Timer();            Vehicle v = Player.Character.CurrentVehicle;            if (light != null && light.Enabled)            {                Vector3 pos = FixZ(v.GetOffsetPosition(Offset1));                light.Position = pos;            }        }        private void ToggleMenu()        {            this.Menu = !this.Menu;            if (!this.Menu)            {                this.g_SelectionM = SelectionMenu.CarInfo;            }        }        private void ToggleNeon()        {            this.Neon = !this.Neon;            if (Neon)            {                msg("Neon on", 4);            }        }        private void GoDown()        {            while (base.isKeyPressed(Keys.NumPad2))            {                base.Wait(100);                if (this.Menu)                {                    if (this.g_SelectionM < SelectionMenu.ColorCar)                    {                        this.g_SelectionM += 1;                    }                    else                    {                        this.g_SelectionM = SelectionMenu.CarInfo;                    }                }            }        }        private void DoTask()        {            while (isKeyPressed(Keys.NumPad5))            {                Wait(100);                string car = "";                string price = "";                if (this.Menu)                {                    switch (this.g_SelectionM)                    {                        case SelectionMenu.CarInfo:                            if (!Player.Character.isInVehicle())                            {                                msg("You must be in vehicle", 3);                            }                            else                            {                                if (Player.Character.CurrentVehicle.Model.isBoat)                                {                                    msg("Name: " + Player.Character.CurrentVehicle.Name.ToString() + " Health: " + Player.Character.CurrentVehicle.Health.ToString() + " Price: " + BoatPrice, 3);                                }                                else if (Player.Character.CurrentVehicle.Model.isBike)                                {                                    msg("Name: " + Player.Character.CurrentVehicle.Name.ToString() + " Health: " + Player.Character.CurrentVehicle.Health.ToString() + " Price: " + BikePrice, 3);                                }                                else if (Player.Character.CurrentVehicle.Model.isHelicopter)                                {                                    msg("Name: " + Player.Character.CurrentVehicle.Name.ToString() + " Health: " + Player.Character.CurrentVehicle.Health.ToString() + " Price: " + PlanePrice, 3);                                }                                else if (Player.Character.CurrentVehicle.Model.isPlane)                                {                                    msg("Name: " + Player.Character.CurrentVehicle.Name.ToString() + " Health: " + Player.Character.CurrentVehicle.Health.ToString() + " Price: " + PlanePrice, 3);                                }                                else if (Player.Character.CurrentVehicle.Model.isCar)                                {                                    msg("Name: " + Player.Character.CurrentVehicle.Name.ToString() + " Health: " + Player.Character.CurrentVehicle.Health.ToString() + " Price: " + NormalPrice, 3);                                }                            }                            return;                        case SelectionMenu.BuyCar:                            if (Settings.GetValueString("Vehicle") != "")                            {                                msg("You have a vehicle", 3);                            }                            else                            {                                if (!Player.Character.isInVehicle())                                {                                    msg("You must be in vehicle", 3);                                }                                else                                {                                    if (Player.Character.CurrentVehicle.Model.isBoat)                                    {                                        if (Player.Money >= BoatPrice)                                        {                                            msg("You buy a " + Player.Character.CurrentVehicle.Name.ToString(), 3);                                            Player.Money -= BoatPrice;                                            car = Player.Character.CurrentVehicle.Name.ToString();                                            price = "37500";                                        }                                        else                                        {                                            msg("You dont have money to buy " + Player.Character.CurrentVehicle.Name.ToString(), 3);                                        }                                    }                                    else if (Player.Character.CurrentVehicle.Model.isBike)                                    {                                        if (Player.Money >= BikePrice)                                        {                                            msg("You buy a " + Player.Character.CurrentVehicle.Name.ToString(), 3);                                            Player.Money -= BikePrice;                                            car = Player.Character.CurrentVehicle.Name.ToString();                                            price = "12500";                                        }                                        else                                        {                                            msg("You dont have money to buy " + Player.Character.CurrentVehicle.Name.ToString(), 3);                                        }                                    }                                    else if (Player.Character.CurrentVehicle.Model.isHelicopter)                                    {                                        if (Player.Money >= PlanePrice)                                        {                                            msg("You buy a " + Player.Character.CurrentVehicle.Name.ToString(), 3);                                            Player.Money -= PlanePrice;                                            car = Player.Character.CurrentVehicle.Name.ToString();                                            price = "62500";                                        }                                        else                                        {                                            msg("You dont have money to buy " + Player.Character.CurrentVehicle.Name.ToString(), 3);                                        }                                    }                                    else if (Player.Character.CurrentVehicle.Model.isPlane)                                    {                                        if (Player.Money >= PlanePrice)                                        {                                            msg("You buy a " + Player.Character.CurrentVehicle.Name.ToString(), 3);                                            Player.Money -= PlanePrice;                                            car = Player.Character.CurrentVehicle.Name.ToString();                                            price = "62500";                                        }                                        else                                        {                                            msg("You dont have money to buy " + Player.Character.CurrentVehicle.Name.ToString(), 3);                                        }                                    }                                    else if (Player.Character.CurrentVehicle.Model.isCar)                                    {                                        if (Player.Money >= NormalPrice)                                        {                                            msg("You buy a " + Player.Character.CurrentVehicle.Name.ToString(), 3);                                            Player.Money -= NormalPrice;                                            car = Player.Character.CurrentVehicle.Name.ToString();                                            price = "25000";                                        }                                        else                                        {                                            msg("You dont have money to buy " + Player.Character.CurrentVehicle.Name.ToString(), 3);                                        }                                    }                                    Settings.SetValue("Vehicle", car);                                    Settings.SetValue("Price", price);                                    Settings.Save();                                }                            }                            return;                        case SelectionMenu.SellCar:                            if (Settings.GetValueString("Vehicle") == "")                            {                                msg("You dont have a vehicle", 3);                            }                            else                            {                                msg("You sell " + Settings.GetValueString("Vehicle"), 3);                                Player.Money += Settings.GetValueInteger("Price",25000);                                Settings.SetValue("Vehicle", "");                                Settings.SetValue("Price", "");                            }                            return;                        case SelectionMenu.CallCar:                            if (Settings.GetValueString("Vehicle") == "")                            {                                msg("You dont have a vehicle", 3);                            }                            else                            {                                string cars = Settings.GetValueString("Vehicle");                                if (!Player.Character.isInVehicle())                                {                                    Spawn(cars);                                }                                else                                {                                    msg("your in vehicle", 3);                                }                            }                            return;                        case SelectionMenu.ColorCar:                            GTA.Forms.ColorDialog cd = new GTA.Forms.ColorDialog();                            cd.AllowScrollbars = false;                            Vehicle veh = Game.LocalPlayer.Character.CurrentVehicle;                            if (veh != null)                            {                                if (Settings.GetValueString("Vehicle") == veh.Name.ToString())                                {                                    cd.SelectedColorGTA = veh.Color;                                    if (cd.ShowDialog() == DialogResult.OK)                                    {                                        veh.Color = cd.SelectedColorGTA;                                        Player.Money -= 1000;                                        Settings.SetValue("Color", cd.SelectedColorGTA.Index);                                        Settings.Save();                                    }                                    cd.Close();                                }                            }                            return;                    }                }            }        }        private void GoUp()        {            while (base.isKeyPressed(Keys.NumPad8))            {                base.Wait(100);                if (this.Menu)                {                    if (this.g_SelectionM > SelectionMenu.CarInfo)                    {                        this.g_SelectionM -= 1;                    }                    else                    {                        this.g_SelectionM = SelectionMenu.ColorCar;                    }                }            }        }        private void Seller_PerFrameDrawing(object sender, GraphicsEventArgs e)        {            float x = (float)(this.res.Width * 0.017);            float num2 = (float)(this.res.Width * 0.15);            float num3 = (float)(this.res.Width * 0.25);            float num4 = (float)(this.res.Width * 0.17);            float num5 = (float)(this.res.Width * 0.3);            if (Neon)            {                if (!Player.Character.isSittingInVehicle()) return;                Vehicle v = Player.Character.CurrentVehicle;                if (v == null) return;                DrawLight(v, 1.5F);            }            if (this.Menu)            {                e.Graphics.DrawText("Car System", x, 12f, Color.White, this.Font);                e.Graphics.DrawText("__________", x, 12f, Color.White, this.Font);                e.Graphics.DrawText("Car Info", x, 32f, Color.White, this.Font);                e.Graphics.DrawText("Buy Car", x, 52f, Color.White, this.Font);                e.Graphics.DrawText("Sell Car", x, 72f, Color.White, this.Font);                e.Graphics.DrawText("Call Car", x, 92f, Color.White, this.Font);                e.Graphics.DrawText("Car Color", x, 112f, Color.White, this.Font);                switch (this.g_SelectionM)                {                    case SelectionMenu.CarInfo:                        e.Graphics.DrawText("Car Info", x, 32f, Color.YellowGreen, this.Font);                        break;                    case SelectionMenu.BuyCar:                        e.Graphics.DrawText("Buy Car", x, 52f, Color.YellowGreen, this.Font);                        break;                    case SelectionMenu.SellCar:                        e.Graphics.DrawText("Sell Car", x, 72f, Color.YellowGreen, this.Font);                        break;                    case SelectionMenu.CallCar:                        e.Graphics.DrawText("Call Car", x, 92f, Color.YellowGreen, this.Font);                        break;                    case SelectionMenu.ColorCar:                        e.Graphics.DrawText("Car Color", x, 112f, Color.YellowGreen, this.Font);                        break;                }            }        }        public void msg(string message, int seconds)        {            Function.Call("PRINT_STRING_WITH_LITERAL_STRING_NOW", new Parameter[] { "STRING", message, seconds * 0x3e8, 1 });        }        public void CheckIniExists()        {            if (!File.Exists("scripts/Seller.ini"))            {                File.Create("scripts/Seller.ini");                Settings.SetValue("Vehicle", "");                Settings.SetValue("Price", "");                Settings.SetValue("Color", "");                Settings.Save();                Wait(100);            }        }        private void DrawLight(Vehicle v,Single Radius)        {            Light light = new Light();            Vector3 pos = FixZ(v.GetOffsetPosition(Offset1));            light.Color = Color.Cyan;            light.Position = pos;            light.Range = Radius;            light.Intensity = 10;            light.Enabled = true;            if (!Neon)            {                light.Disable();            }        }        private Vector3 FixZ(Vector3 Position)        {            float G = World.GetGroundZ(Position + Z1000) + ZOffset;            if (Position.Z < G)                Position.Z = G;            return Position;        }        public void Spawn(string car)        {            Vehicle veh = World.CreateVehicle(car, Player.Character.Position.Around(5f));            ColorIndex color = (ColorIndex)Settings.GetValueInteger("Color",1);            veh.Color = color;            veh.NoLongerNeeded();            Player.Character.WarpIntoVehicle(veh, VehicleSeat.Driver);            msg("Your car " + car + " is called", 3);        }        private enum SelectionMenu        {            CarInfo,            BuyCar,            SellCar,            CallCar,            ColorCar        }    }}
Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066905159
Share on other sites

Sorry, went to sleep after my last post.

So you doing memory leak in tick, thanks to GC, your light and timer variables are deleted.

Do a Initialize variable, in which tick would look if everything initialize if not then initialize

bool firstRun;Light light;GTA.Timer timer = new GTA.Timer();public Seller(){   timer.Interval = 10;   timer.Tick += timer_Tick;   timer.Start();}public void timer_Tick(object sender, EventArgs e){    if(firstRun)    {       CheckIniExists();       light = new Light();                 }    Vehicle v = Player.Character.CurrentVehicle;    if (light != null && light.Enabled)    {        light.Position = FixZ(v.GetOffsetPosition(Offset1));    }}private void DrawLight(Vehicle v,Single Radius){          light.Color = Color.Cyan;     light.Position = FixZ(v.GetOffsetPosition(Offset1));;     light.Range = Radius;     light.Intensity = 10;     light.Enabled = true;     if (!Neon)     {        light.Disable();     }}

Okay, why in your DrawLight, you initialize same variable ?

 

Tip: Try to use less global variables. And sometimes when you don't need anything more(if you do all your checks in function like FixZ, then you don't need another variable :)

 

 

Best regards,

Paul.

Link to comment
https://gtaforums.com/topic/764788-neon-c/#findComment-1066907153
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
  • 0 User Currently Viewing
    0 members, 0 Anonymous, 0 Guests

×
×
  • Create New...

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.