Need Help On Making A Timed Function

Posts 13 of 3 · Page 1 of 1
Need Help On Making A Timed Function
So I have this item magnet code that I learned from GTAPLayer2 kudos to him =), and I tried adding the UpdateItems function to a timer so it refreshes the item list automatically. However it crashes my program when it refreshes it. I also came up with an idea to use the item magnet program to find heli crashes, feel free to look at it. Here's my code =)

//Side Note, It doesnt refresh until you click the button for some odd reason.

Code:
  void UpdateItems()
        {
            listBox1.Items.Clear();
            if (Memdlols.CheckProcess())
            {
                Memdlols.StartProcess();

                int Base = Memdlols.ReadInt(0x0FAFFF0);
                int pLocal = Memdlols.ReadInt(Base + 0x1698);
                pLocal = Memdlols.ReadInt(pLocal + 0x4);
                int coordPtr = Memdlols.ReadInt(pLocal + 0x24);


                float LocX = Memdlols.ReadFloat(coordPtr + 0x28);
                float LocY = Memdlols.ReadFloat(coordPtr + 0x30);
                float LocZ = Memdlols.ReadFloat(coordPtr + 0x2C);


                int ItemTable = this.Memdlols.ReadInt(Base + 0x11B8);
                int DroppedItemTable = this.Memdlols.ReadInt(Base + 0x0FC0);
                int FarDroppedItemTable = this.Memdlols.ReadInt(Base + 0x1068);
                int FarDroppedItemTableOff = this.Memdlols.ReadInt(Base + 0x1064);
                int TableSize = this.Memdlols.ReadInt(Base + 0x11BC);
                int FarDroppedSize = this.Memdlols.ReadInt(Base + 0x106C);
                int FarTable = Memdlols.ReadInt(Base + 0x11B8);
                int FarTableSize = Memdlols.ReadInt(Base + 0x11BC);
                for (int i = 0; i < FarTableSize; i++)
                {
                    int FarTablePtr = Memdlols.ReadInt(FarTable + (i * 0x4));
                    int itemCoord = Memdlols.ReadInt(FarTablePtr + 0x24);
                    


                    int lfoibdusofItemNamePtr = Memdlols.ReadInt(FarTablePtr + 0x70);
                    lfoibdusofItemNamePtr = Memdlols.ReadInt(lfoibdusofItemNamePtr + 0x34);
                    int pSize = this.Memdlols.ReadInt(lfoibdusofItemNamePtr + 0x4);
                    int lfoibdusofItemNameSize = Memdlols.ReadInt(lfoibdusofItemNamePtr + 0x4);
                    string lfoibdusofItemName = Memdlols.ReadStringAscii(lfoibdusofItemNamePtr + 0x8, lfoibdusofItemNameSize);

                    if (lfoibdusofItemName != "Land_A_FuelStation_Feed" && lfoibdusofItemName != "Land_Mash")
                    {
                        if (textBox1.Text.Length > 0)
                        {
                            if (lfoibdusofItemName.Contains(textBox1.Text))
                            {
                                listBox1.Items.Add(i.ToString() + " " + lfoibdusofItemName);
                                if (mloejdfTeleportItems == true)
                                {
                                    Memdlols.WriteFloat(itemCoord + 0x28, LocX + (i * 0.1f));
                                    Memdlols.WriteFloat(itemCoord + 0x30, LocY + (i * 0.05f));
                                    Memdlols.WriteFloat(itemCoord + 0x2C, LocZ + 0.5f);
                                    mloejdfTeleportItems = false;
                                }
                            }
                        }
                        else
                        {
                            listBox1.Items.Add(i.ToString() + " " + lfoibdusofItemName);
                        }
                    }

                    var t = new Timer { Enabled = true, Interval = 40 * 1000 };
                    t.Tick += delegate 
                    {
                        UpdateItems();
                    };

                }
            }
        }

       

        private void button1_Click(object sender, EventArgs e)
        {

            UpdateItems();
            if (listBox1.Text == "Land_MH_60Wreck")
            {
                MessageBox.Show("HELICRASH OMG M4 PLOX");
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            mloejdfTeleportItems = true;
            UpdateItems();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            UpdateItems();
            if (listBox1.Text == "Land_MH_60Wreck")
            {
                MessageBox.Show("HELICRASH OMG M4 PLOX");
            }
        }
    }
}
The problem should be the listBox item you try to access. If it's a timer function you have to invoke it for the listBox thread.. it should look like this..

Code:
public void InvokeUpdateItems() {
     if (listBox.InvokeRequired) {
          listBox.Invoke(InvokeUpdateItems);
     } else {
          // call old UpdateItems method..
     }
}
You have to change the invoke method parameter to a delegate maybe if it shouldn't work instantly..
It doesn't refresh because you added the update items func to the button delegate. Find a way to extract the timer from the update func.

Edit: oh and you didn't start the timer.
Posts 13 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?