Jump to content

Using Not in a toggle function.


Recommended Posts

Ok, I'm using auotit to make a trainer for a game (FFVII Ultima Edition), and I have the addresses I need stored in a file that I'm referring to as I code. What I need help with is I have the + on the numpad set as the hotkey for the "Unfreeze" function. I've seen people use Not with functions to toggle them on or off but I can't remember how. Here's the script so please point me in the right direction or post an example?

#Region;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_outfile=ffvii ultima trainer.exe
#AutoIt3Wrapper_Compression=4
#EndRegion;**** Directives created by AutoIt3Wrapper_GUI ****
#include <NomadMemory.au3>
#include <Array.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

Opt("TrayIconHide",1)

Dim $Cloud_HP[2],$Cloud_HP_Max[2], $Cloud_HP_Read[2], $Cloud_HP_Max_Read[2], $flag, $icolocation, $health[2]

$icolocation = RegRead("HKLM\Software\Square Soft, Inc.\Final Fantasy VII","AppPath") & "ff7.exe"
If @error <> 0 Then
    MsgBox(49,"Error","Error: You do not seem to have the Final Fantasy VII Ultima Edition game installed." & @CRLF & "You must have it installed to use this trainer.")
    Exit
EndIf

If Not FileExists(@TempDir & "\ffviiue.jpg") Then
    FileInstall("C:\Users\Owner\Desktop\ffviiue.jpg",@TempDir & "\ffviiue.jpg")
EndIf

HotKeySet("{NUMPADADD}","Unfreeze")

Do
    $PID = ProcessExists("ff7.exe")
    If $PID = 0 Then
        $flag = MsgBox(49,"Error","Please run Final Fantasy VII Ultima Edition before starting this trainer." & @CRLF & "Please start the program now to continue or click cancel to exit.")
    EndIf
Until $PID <> 0 Or $flag = 2

If $flag = 2 Then
    Exit
EndIf

#Region ### START Koda GUI section ### Form=C:\Users\Owner\Desktop\ffvii ultima trainer.kxf
$frmTrainer = GUICreate("FFVII Ultima Trainer", 625, 445, 193, 125)
GUICtrlCreatePic(@TempDir & "\ffviiue.jpg",0,0,625,445)
GUICtrlSetState(-1,$GUI_DISABLE)
GUICtrlSetResizing(-1,102)
$lblCH = GUICtrlCreateLabel("Cloud Health: ", 8, 10, 71, 17)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$txtCH = GUICtrlCreateInput("", 76, 10, 35, 17,$ES_NUMBER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$chkCHFreeze = GUICtrlCreateCheckbox("Freeze it!",115,10,73,17)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetLimit(-1,4,1)
$lblGil = GUICtrlCreateLabel("Gil: ", 190, 13, 25, 17)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
$txtGil = GUICtrlCreateInput("", 210, 13, 90, 17,$ES_NUMBER)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUICtrlSetLimit(-1,8)
$chkGilFreeze = GUICtrlCreateCheckbox("Freeze it!", 305,14,73,15)
GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT)
GUISetIcon($icolocation)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

$Mem_Handle = _MemoryOpen($PID)

$Cloud_HP[0] = "0x00DBFDB8"
$Cloud_HP[1] = "0x00DBA4A8"

$Cloud_HP_Read[0] = _MemoryRead("0x00DBFDB8",$Mem_Handle,"ushort")
$Cloud_HP_Read[1] = _MemoryRead("0x00DBA4A8",$Mem_Handle,"ushort")

$Cloud_HP_Max[0] = "0x00DBA4AA"
$Cloud_HP_Max[1] = "0x00DBFDBA"

$Cloud_HP_Max_Read[0] = _MemoryRead("0x00DBA4AA",$Mem_Handle,"ushort")
$Cloud_HP_Max_Read[1] = _MemoryRead("0x00DBFDBA",$Mem_Handle,"ushort")

$Gil = "0x00DC08B4"
$Gil_Read = _MemoryRead($Gil,$Mem_Handle)

GUICtrlSetData($txtCH,$Cloud_HP_Read[0])
GUICtrlSetData($txtGil,$Gil_Read)

While 1
    $nMsg = GUIGetMsg()
    If GUICtrlRead($chkCHFreeze) = $GUI_CHECKED Then
        $health[0] = _MemoryRead($Cloud_HP[0],$Mem_Handle,"ushort")
        $health[1] = _MemoryRead($Cloud_HP[1],$Mem_Handle,"ushort")
        If $health[0] <> GUICtrlRead($txtCH) Or $health[1] <> GUICtrlRead($txtCH) Then
            _MemoryWrite($Cloud_HP[0],$Mem_Handle,GUICtrlRead($txtCH),"ushort")
            _MemoryWrite($Cloud_HP[1],$Mem_Handle,GUICtrlRead($txtCH),"ushort")
        EndIf
    EndIf
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _MemoryClose($Mem_Handle)
            Exit
        Case $txtGil
            _MemoryWrite($Gil,$Mem_Handle,GUICtrlRead($txtGil))
        Case $txtCH
            _MemoryWrite($Cloud_HP[0],$Mem_Handle,GUICtrlRead($txtCH),"ushort")
            _MemoryWrite($Cloud_HP[1],$Mem_Handle,GUICtrlRead($txtCH),"ushort")
    EndSwitch
WEnd

Func Unfreeze()
    If GUICtrlRead($chkCHFreeze) = $GUI_CHECKED Then
        GUICtrlSetState($chkCHFreeze,$GUI_UNCHECKED)
    Else
        GUICtrlSetState($chkCHFreeze,$GUI_CHECKED)
    EndIf
EndFunc

As you can see I'm simply reading the state of the checkbox but when this is finished I'll need it to set all the checkboxes to frozen/unfrozen (checked/unchecked) at the same time. Is there a way to do this without coding massive If statements?

Edited by dbzfanatic
Link to comment
Share on other sites

Use arrays to create your checkboxes.

Global Const $NumOfChkBoxes = 6
Dim $ChkBox[$NumOfChkBoxes]

$ChkBox[0] = GuiCtrlCreatCheckBox(..............

Then you can toggle them all easily, perhaps like this

Func Unfreeze()
    Local $check = $GUI_UNCHECKED + $GUI_CHECKED
    Local $n
    For $n = 0 To $NumOfChkBoxes - 1
        GUICtrlSetState($ChkBox[$n], $check - GUICtrlRead($ChkBox[$n]))
    Next
EndFunc  ;==>Unfreeze
Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

I thought about doing it that way (except for the $check = part, thank you for that) but I was hoping to use Not, however this seems to work just as well so thank you.

Link to comment
Share on other sites

I thought about doing it that way (except for the $check = part, thank you for that) but I was hoping to use Not, however this seems to work just as well so thank you.

Yes, in some languages the state of being checked is boolean so you can toggle with

Chk1.Checked = not Chk1.Checked

but since the state $Gui_CHECKED is not the inverse of $GUIU_UNCHECKED you can't do that in AutoIt.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...