Jump to content
    1. Welcome to GTAForums!

    1. GTANet.com

    1. GTA Online

      1. The Criminal Enterprises
      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. Support

    3. Suggestions

*DO NOT* SHARE MEDIA OR LINKS TO LEAKED COPYRIGHTED MATERIAL. Discussion is allowed.

Different ticks from different files


Noox
 Share

Recommended Posts

Is it possible to stop a tick and execute another one in a different file (still in the same project/dll)?

For example, I have Class1.cs and Class2.cs, just to keep things organized in Class1.cs in the main tick I do X and in Class2.cs I do Y.

At a certain point I want to stop X and start Y, is it possible?

Link to comment
Share on other sites

Make sure they are both public then do Class2.<ClassName>.<TickEventFunctionName>.Start() or .Stop()

Link to comment
Share on other sites

Something more tick related.

I'm doing a script. it's basically the GTA V rampage and everything is fine except for one thing.

I have one method which spawns the enemies with a for loop, the problem is that the tick stops while that method is being executed until the for loop is over and everything becomes glitched, I tried what you posted above but it doesn't work.

 

(Class1 is called Main and Class2 Functions in this case, the tick is named mainTick)

So I used Main.<mainTick>.Start();

 

This is the code if you need it

 

Main

 

 

namespace ClassLibrary1{    public class Main : Script    {        Functions functions = new Functions();        bool inRampage = false;        bool healthIsBeingAdded = false;        bool spawningEnemies = false;        int killCounter = 0;        Weapon weapon = Weapon.Rifle_AK47;        public Main()        {            Interval = 250;            this.Tick += new EventHandler(mainTick);            this.KeyDown += new GTA.KeyEventHandler(keyTick);        }        public void mainTick(object sender, EventArgs e)        {            Game.DisplayText(Convert.ToString(killCounter)); //DISAPPEARS WHEN END IS PRESSED            if(inRampage)            {                Player.Character.Weapons.FromType(weapon).Ammo = 500;                if (Player.Character.Weapons.Current != weapon) //DOESN'T WORK                    Player.Character.Weapons.Select(weapon);                if (Player.Character.Health <= 50 && !healthIsBeingAdded) //DOESN'T WORK                    functions.healthRegen(ref healthIsBeingAdded); //passed by reference and not by value                if (!spawningEnemies)                    functions.enemySpawn(ref spawningEnemies);                Player.WantedLevel--; //DOESN'T work, there was an if here and I removed it to see if it was the cause but it's the same                foreach(Ped peds in Functions.enemyGroup) //THIS FOREACH IS NOT BEING EXECUTED                {                    if (peds.Health < 1)                    {                        Game.DisplayText("One is dead!");                        Functions.enBlip.Delete();                        killCounter++;                    }                    if (Functions.enemyGroup.MemberCount < 1)                        Functions.enemyArray[0].Delete();                }            }        }        public void keyTick(object sender, GTA.KeyEventArgs e)        {            if(e.Key == Keys.End)            {                functions.rampageSettings();                inRampage = true;            }        }    }}

 

 

 

Functions

 

 

namespace ClassLibrary1{    class Functions : Script    {        static public Group enemyGroup;        public static Blip enBlip;        public static Ped[] enemyArray;        public void rampageSettings()        {            Player.Character.Health = 100;            Player.Character.Armor = 100;            World.CarDensity = 0;            World.PedDensity = 0;            //I need to delete cops and peds close to the player when this is executed        }        public void healthRegen(ref bool healthRegen)        {            Main main = new Main();            healthRegen = true;            for (int health = Player.Character.Health; health <= 100; health+=2)            {                Player.Character.Health = health;                Wait(500);            }            healthRegen = false;        }        public void enemySpawn(ref bool spawning) //WORKS        {   //Main.<mainTick>.Start();            spawning = true;            Random rnd = new Random();            int killsNeededToFinish = rnd.Next(50, 100);            enemyArray = new Ped[killsNeededToFinish];            for(int i = 0; i < killsNeededToFinish; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(100.0F));                enemyArray[i] = World.CreatePed("M_M_ENFORCER", playerPos, RelationshipGroup.Criminal);                if (i == 0)                    enemyGroup = new Group(enemyArray[i]);                else                    changeAI(enemyArray[i]);                Wait(rnd.Next(1500, 7000));                /*if (!Exists(enemyArray[oldLeader]))                {                    enemyGroup = new Group(enemyArray[i]);                    oldLeader = i;                }*/            }        }        public void changeAI(Ped e)        {            enBlip = e.AttachBlip();            e.SetPathfinding(true, true, true);            e.ChangeRelationship(RelationshipGroup.Player, Relationship.Hate);            e.AlwaysDiesOnLowHealth = true;            e.RandomizeOutfit();            e.CowerInsteadOfFleeing = true;            e.Task.FightAgainst(Player.Character);            Weapon weapon = Weapon.SMG_MP5;            e.Weapons.FromType(weapon).Ammo = 500;            e.Weapons.Select(weapon);            e.Task.GoTo(Player.Character);            enemyGroup.AddMember(e);        }    }}

 

 

Link to comment
Share on other sites

Something more tick related.

I'm doing a script. it's basically the GTA V rampage and everything is fine except for one thing.

I have one method which spawns the enemies with a for loop, the problem is that the tick stops while that method is being executed until the for loop is over and everything becomes glitched, I tried what you posted above but it doesn't work.

 

(Class1 is called Main and Class2 Functions in this case, the tick is named mainTick)

So I used Main.<mainTick>.Start();

 

This is the code if you need it

 

Main

 

 

namespace ClassLibrary1{    public class Main : Script    {        Functions functions = new Functions();        bool inRampage = false;        bool healthIsBeingAdded = false;        bool spawningEnemies = false;        int killCounter = 0;        Weapon weapon = Weapon.Rifle_AK47;        public Main()        {            Interval = 250;            this.Tick += new EventHandler(mainTick);            this.KeyDown += new GTA.KeyEventHandler(keyTick);        }        public void mainTick(object sender, EventArgs e)        {            Game.DisplayText(Convert.ToString(killCounter)); //DISAPPEARS WHEN END IS PRESSED            if(inRampage)            {                Player.Character.Weapons.FromType(weapon).Ammo = 500;                if (Player.Character.Weapons.Current != weapon) //DOESN'T WORK                    Player.Character.Weapons.Select(weapon);                if (Player.Character.Health <= 50 && !healthIsBeingAdded) //DOESN'T WORK                    functions.healthRegen(ref healthIsBeingAdded); //passed by reference and not by value                if (!spawningEnemies)                    functions.enemySpawn(ref spawningEnemies);                Player.WantedLevel--; //DOESN'T work, there was an if here and I removed it to see if it was the cause but it's the same                foreach(Ped peds in Functions.enemyGroup) //THIS FOREACH IS NOT BEING EXECUTED                {                    if (peds.Health < 1)                    {                        Game.DisplayText("One is dead!");                        Functions.enBlip.Delete();                        killCounter++;                    }                    if (Functions.enemyGroup.MemberCount < 1)                        Functions.enemyArray[0].Delete();                }            }        }        public void keyTick(object sender, GTA.KeyEventArgs e)        {            if(e.Key == Keys.End)            {                functions.rampageSettings();                inRampage = true;            }        }    }}

 

 

 

Functions

 

 

namespace ClassLibrary1{    class Functions : Script    {        static public Group enemyGroup;        public static Blip enBlip;        public static Ped[] enemyArray;        public void rampageSettings()        {            Player.Character.Health = 100;            Player.Character.Armor = 100;            World.CarDensity = 0;            World.PedDensity = 0;            //I need to delete cops and peds close to the player when this is executed        }        public void healthRegen(ref bool healthRegen)        {            Main main = new Main();            healthRegen = true;            for (int health = Player.Character.Health; health <= 100; health+=2)            {                Player.Character.Health = health;                Wait(500);            }            healthRegen = false;        }        public void enemySpawn(ref bool spawning) //WORKS        {   //Main.<mainTick>.Start();            spawning = true;            Random rnd = new Random();            int killsNeededToFinish = rnd.Next(50, 100);            enemyArray = new Ped[killsNeededToFinish];            for(int i = 0; i < killsNeededToFinish; i++)            {                Vector3 playerPos = World.GetNextPositionOnStreet(Player.Character.Position.Around(100.0F));                enemyArray[i] = World.CreatePed("M_M_ENFORCER", playerPos, RelationshipGroup.Criminal);                if (i == 0)                    enemyGroup = new Group(enemyArray[i]);                else                    changeAI(enemyArray[i]);                Wait(rnd.Next(1500, 7000));                /*if (!Exists(enemyArray[oldLeader]))                {                    enemyGroup = new Group(enemyArray[i]);                    oldLeader = i;                }*/            }        }        public void changeAI(Ped e)        {            enBlip = e.AttachBlip();            e.SetPathfinding(true, true, true);            e.ChangeRelationship(RelationshipGroup.Player, Relationship.Hate);            e.AlwaysDiesOnLowHealth = true;            e.RandomizeOutfit();            e.CowerInsteadOfFleeing = true;            e.Task.FightAgainst(Player.Character);            Weapon weapon = Weapon.SMG_MP5;            e.Weapons.FromType(weapon).Ammo = 500;            e.Weapons.Select(weapon);            e.Task.GoTo(Player.Character);            enemyGroup.AddMember(e);        }    }}

 

 

 

The ><'s where just an example to show that that is where you put the name of your tick event. Take those out so it looks like Main.mainTick.Start();.

If you don't want to stop the timer when something is happening within that said timer, then just set a boolean to true when it is processing stuff in the timer, and false when it gets to the end of the tick event. Then, when you are stopping the timer, just do if (!boolean)

Link to comment
Share on other sites

Uhm, I don't understand :/

Also, main.mainTick.Start(); doesn't work because it says it's not a valid construct.

Link to comment
Share on other sites

Uhm, I don't understand :/

Also, main.mainTick.Start(); doesn't work because it says it's not a valid construct.

 

The class has to be public and the variable has to be public and static. It should look like this:

public class ClassNameHere : Script{   public static GTA.Timer mainTick;} 

Just look at this: http://social.msdn.microsoft.com/Forums/en-US/a3bcf89f-2ce0-42b8-a6b5-d47e3ea63bd2/how-to-global-a-variable-in-c?forum=csharpgeneral

Edited by LetsPlayOrDy
Link to comment
Share on other sites

I tried to inform myself about GTA.Timer and found an old topic in this forum, I added a second timer but the game crashes when it's done loading :|

I don't know if this is what you meant

    public class Main : Script    {        Functions functions = new Functions();        bool inRampage = false;        bool healthIsBeingAdded = false;        bool spawningEnemies = false;        int killCounter = 0;        GTA.Timer secondTick;        Weapon weapon = Weapon.Rifle_AK47;        public Main()        {            Interval = 250;            this.Tick += new EventHandler(mainTick);            secondTick = new GTA.Timer(1000);            secondTick.Tick += secondaryTick;            secondTick.Start();            this.KeyDown += new GTA.KeyEventHandler(keyTick);        }        public void mainTick(object sender, EventArgs e)        {            Game.DisplayText(Convert.ToString(killCounter));            if(inRampage)            {                Player.Character.Weapons.FromType(weapon).Ammo = 500;                if (Player.Character.Weapons.Current != weapon)                     Player.Character.Weapons.Select(weapon);                if (Player.Character.Health <= 50 && !healthIsBeingAdded)                     functions.healthRegen(ref healthIsBeingAdded);                Player.WantedLevel--;                 foreach(Ped peds in Functions.enemyGroup)                {                    if (peds.Health < 1)                    {                        Game.DisplayText("One is dead!");                        Functions.enBlip.Delete();                        killCounter++;                    }                    if (Functions.enemyGroup.MemberCount < 1)                        Functions.enemyArray[0].Delete();                }            }        }        public void secondaryTick(object sender, EventArgs e)        {            if (!spawningEnemies)                functions.enemySpawn(ref spawningEnemies);        }        public void keyTick(object sender, GTA.KeyEventArgs e)        {            if(e.Key == Keys.End)            {                functions.rampageSettings();                inRampage = true;            }        }    }}
Link to comment
Share on other sites

 

I tried to inform myself about GTA.Timer and found an old topic in this forum, I added a second timer but the game crashes when it's done loading :|

I don't know if this is what you meant

    public class Main : Script    {        Functions functions = new Functions();        bool inRampage = false;        bool healthIsBeingAdded = false;        bool spawningEnemies = false;        int killCounter = 0;        GTA.Timer secondTick;        Weapon weapon = Weapon.Rifle_AK47;        public Main()        {            Interval = 250;            this.Tick += new EventHandler(mainTick);            secondTick = new GTA.Timer(1000);            secondTick.Tick += secondaryTick;            secondTick.Start();            this.KeyDown += new GTA.KeyEventHandler(keyTick);        }        public void mainTick(object sender, EventArgs e)        {            Game.DisplayText(Convert.ToString(killCounter));            if(inRampage)            {                Player.Character.Weapons.FromType(weapon).Ammo = 500;                if (Player.Character.Weapons.Current != weapon)                     Player.Character.Weapons.Select(weapon);                if (Player.Character.Health <= 50 && !healthIsBeingAdded)                     functions.healthRegen(ref healthIsBeingAdded);                Player.WantedLevel--;                 foreach(Ped peds in Functions.enemyGroup)                {                    if (peds.Health < 1)                    {                        Game.DisplayText("One is dead!");                        Functions.enBlip.Delete();                        killCounter++;                    }                    if (Functions.enemyGroup.MemberCount < 1)                        Functions.enemyArray[0].Delete();                }            }        }        public void secondaryTick(object sender, EventArgs e)        {            if (!spawningEnemies)                functions.enemySpawn(ref spawningEnemies);        }        public void keyTick(object sender, GTA.KeyEventArgs e)        {            if(e.Key == Keys.End)            {                functions.rampageSettings();                inRampage = true;            }        }    }}

 

I don't think you can access

Interval = 250;this.Tick += new EventHandler(mainTick);

this timer from another file, but you can access

GTA.Timer secondTick;

this one from another file if you change it to

public static GTA.Timer secondTick;
Edited by LetsPlayOrDy
Link to comment
Share on other sites

Sorry I made confusion.

I found the problem of my script, why the lines after the enemySpawn method is called are not being executed, since when a method is called the CPU jumps to that code the tick is "paused" if we can say it that way and I want to add a second one so the enemies keep spawning and the main tick is not paused and it checks everything that needs to be checked but if I use that second timer/tick the game crashes as soon as it's done loading.

I tried the windows forms timer and it's the same thing :(

Link to comment
Share on other sites

Sorry I made confusion.

I found the problem of my script, why the lines after the enemySpawn method is called are not being executed, since when a method is called the CPU jumps to that code the tick is "paused" if we can say it that way and I want to add a second one so the enemies keep spawning and the main tick is not paused and it checks everything that needs to be checked but if I use that second timer/tick the game crashes as soon as it's done loading.

I tried the windows forms timer and it's the same thing :(

I don't know what the problem is :/

Link to comment
Share on other sites

Aww, I will keep playing around with the timer then.

Link to comment
Share on other sites

There was an error in the second class that I managed to fix, that's why it was crashing :)

Anyway, are timers performance eaters?

EDIT: Woops, double post, sorry!

Edited by Noox
Link to comment
Share on other sites

There was an error in the second class that I managed to fix, that's why it was crashing :)

Anyway, are timers performance eaters?

EDIT: Woops, double post, sorry!

Are timers performance eaters? Depends on what's in the tick event I guess.

Link to comment
Share on other sites

Anyway the first tick stops even if there is the second one, are there any ways to execute part of a script in a second thread?

Edited by Noox
Link to comment
Share on other sites

Anyway the first tick stops even if there is the second one, are there any ways to execute part of a script in a second thread?

I don't think that is possible. Just change the one timer to a GTA.Timer and then you can access it from anywhere.

Edited by LetsPlayOrDy
Link to comment
Share on other sites

Even if I use Main.mainTick.Start() inside the method when it's called the main tick stops being executed, I have to start another mod I guess :|

Link to comment
Share on other sites

LordOfTheBongs

Noox im trying to read what ur doing but this conversation is going all over... paste your code on pastebin using c# syntax highlighter (make sure u have Visual studio format it first, u can do this by going to the end of the file... deleting the last } and then typing it again... unless u disabled this of course)

 

Then tell me in english, not code talk what u need to happen... and ill tell u how to fix.

Link to comment
Share on other sites

Noox im trying to read what ur doing but this conversation is going all over... paste your code on pastebin using c# syntax highlighter (make sure u have Visual studio format it first, u can do this by going to the end of the file... deleting the last } and then typing it again... unless u disabled this of course)

 

Then tell me in english, not code talk what u need to happen... and ill tell u how to fix.

Sorry but I'm not good at explaining :p

Anyway I managed to fix by putting everything in the main tick, the code itself is a mess and hard to read but it works.

Thanks anyway.

Link to comment
Share on other sites

LordOfTheBongs

if it works it works, that's all that matters... ur not writing a book for someone to read :D

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.