Page 1 of 1

locking a value at an address

PostPosted: Tue Apr 15, 2008 3:24 am
by liqmysaq
what is the LSS script i would use to lock a value at an address? im working on a trainer but i need to lock some values, not just poke them.
ive searched the helpfile and in the code editor but found nothing on locking. closest thing is the info on script locks, but everything i try with that fails and since its not in the function list in code editor i doubt it's usable in LSS anyway.

PostPosted: Tue Apr 15, 2008 4:47 am
by mezzo
Use the thread example from the helpfile to make a thread that sets the value of an extern every X amount of time.
Be sure to add a way for the thread to be stopped too, or it will run forever.
(till you close MHS)

PostPosted: Tue Apr 15, 2008 11:44 am
by liqmysaq
oh, ok. ill mess with it and see what happens. i have no clue what im doing and ill probably be asking for more detail when i get annoyed after hours of failure hehe. guess i should learn what a thread is first lol. its all still jibberish to me :P thx.

PostPosted: Tue Apr 15, 2008 3:10 pm
by mezzo
threads allow multiple functions to be run at the same time (concurrently).
Just try the example L.Spiro made for threads in the helpfile, you'll see what I mean.

PostPosted: Sat Apr 26, 2008 11:06 pm
by CoMPMStR
If the threading tutorial is too much for you to soak in, here's an example:

Code: Select all
BOOL bFreeze;

void On_HK_0( DWORD dw1, DWORD dw2 )
{
   bFreeze = !bFreeze;
   
   if (bFreeze == true)
   {
      HANDLE hNewThread = CreateThread("NewThread", 0);
      if (!hNewThread) { bFreeze = false; return; }
      CloseHandle(hNewThread);
   }
}

VOID NewThread(DWORD dwParam)
{
   while (bFreeze == true)
   {
      // put your code here to write the value.
      Sleep(1);
   }
}


In this snippet, When you press the hotkey it will toggle freezing. If bFreeze is FALSE then it will set it to TRUE, create the new thread, and execute the code in NewThread until bFreeze is FALSE again (which will happen if you press the hotkey again). Very simple, once you get the hang of it. The Sleep function is there so the constant looping doesn't lag or freeze MHS (or the game).