Jump to content
  • 0

How to know if gg.prompt is nil before his features are executed


Platonic
 Share

Question

Having some issue. I have a gg.prompt menu. 

function mappedMemoryRangesJump(scatteredExecutable, compactExecutable)
  if #memoryMap == 3 then
    mainAddressPoint = {address = memoryMap[1]["start"] + startPointer[1]["value"] + compactExecutable}
  elseif #memoryMap >= 4 then
    mainAddressPoint = {address = memoryMap[1]["start"] + startPointer[1]["value"] + scatteredExecutable}
  end
end

function nonFoundValues()
  gg.toast("the values are not found yet, trying again in 10 sec")
  gg.sleep(1000)
end

function filterSettings(set, offset_0, offset_1, offset_2, dataTye_0, dataType_1, dataType_2)
  local resultTable = gg.getResults(gg.getResultsCount())
  filterTable = {}
  for i, v in ipairs(resultTable) do
    local filter = {{address = resultTable[i]["address"] + offset_0, flags = dataTye_0}}
    local filter_1 = {{address = resultTable[i]["address"] + offset_1, flags = dataType_1}}
    filter = gg.getValues(filter)
    filter_1 = gg.getValues(filter_1)
    if set == 2 then
      if filter[1]["value"] == "2" and filter_1[1]["value"] ~= "0" then
        filterTable[#filterTable + 1] = {address = resultTable[i]["address"] + offset_2, flags = dataType_2}
      end
    end
    if set == 3 then
      if filter[1]["value"] == "2" then
        filterTable[#filterTable + 1] = {address = resultTable[i]["address"] + offset_2, flags = dataType_2}
      end
    end
    if set == 4 then
      if filter[1]["value"] == "1031127695" and filter_1[1]["value"] ~= "0" then
        filterTable[#filterTable + 1] = {address = resultTable[i]["address"] + offset_2, flags = dataType_2}
      end
    end
  end
end

local old = gg.getRanges()

function jumpCounter() --features
  mappedMemoryRangesJump(0x269F60, 0x26A0D8)
  gg.setRanges(gg.REGION_ANONYMOUS)
  gg.searchNumber(mainAddressPoint["address"], gg.TYPE_QWORD)
  jumpPointerCheck = mainAddressPoint["address"]
  local startPointerJump = gg.getResults(20)
  jumpCount = {}
  jumpPointer = {}
  gg.clearResults()
  for i, v in ipairs(startPointerJump) do
    local filter = {{address = startPointerJump[i]["address"] + 0x8, flags = gg.TYPE_DWORD}}
    filter = gg.getValues(filter)
    if filter[1]["value"] == "8" then
      jumpCount[#jumpCount + 1] = {address = startPointerJump[i]["address"] + 0x358, flags = gg.TYPE_DWORD}
      jumpPointer[#jumpPointer + 1] = {address = startPointerJump[i]["address"], flags = gg.TYPE_QWORD}
    end
  end
  jumpCount = gg.getValues(jumpCount)
  jumpPointer = gg.getValues(jumpPointer)
  if #jumpCount == 0 then
    nonFoundValues()
    jumpCounter()
  end
  gg.addListItems(jumpCount)
end
jumpCounter()

function characterAnim() --features
  mappedMemoryRangesJump(0xCC64D8 ,0xCC6010)
  gg.setRanges(gg.REGION_ANONYMOUS)
  gg.searchNumber(mainAddressPoint["address"], gg.TYPE_QWORD)
  filterSettings(2, 0x74, 0xB0, 0x8E0, gg.TYPE_DWORD, gg.TYPE_DWORD, gg.TYPE_FLOAT)
  gg.clearResults()
  characterAnimation = gg.getValues(filterTable)
  if #characterAnimation == 0 then
    nonFoundValues()
    characterAnim()
  end
  gg.addListItems(characterAnimation)
end
characterAnim()

function fullGameSpeed() --features
  mappedMemoryRangesJump(0x27B548, 0x27B660)
  gg.setRanges(gg.REGION_ANONYMOUS)
  gg.searchNumber(mainAddressPoint["address"], gg.TYPE_QWORD)
  filterSettings(3, 0x33, 0x0, 0x300, gg.TYPE_BYTE, gg.TYPE_BYTE, gg.TYPE_FLOAT)
  gg.clearResults()
  gameSpeedFull = gg.getValues(filterTable)
  if #gameSpeedFull == 0 then
    nonFoundValues()
    fullGameSpeed()
  end
  gg.addListItems(gameSpeedFull)
end
fullGameSpeed()

function charsObjectSpeed() --features
  mappedMemoryRangesJump(0xC82268, 0xC81DA0)
  gg.setRanges(gg.REGION_ANONYMOUS)
  gg.searchNumber(mainAddressPoint["address"], gg.TYPE_QWORD)
  filterSettings(4, 0x40, 0x58, 0x1640, gg.TYPE_DWORD, gg.TYPE_QWORD, gg.TYPE_FLOAT)
  gg.clearResults()
  characterObjectSpeed = gg.getValues(filterTable)
  if #characterObjectSpeed == 0 then
    nonFoundValues()
    charsObjectSpeed()
  end
  gg.addListItems(characterObjectSpeed)
end
charsObjectSpeed()

function valueCheck() --features
  if jumpPointer[1]["value"] ~= jumpPointerCheck then -- all values have changed address
    gg.toast("Values have changed address, Script will auto search values again in 10 sec.")
    gg.sleep(10000)
    jumpCount[1]["freeze"] = false -- unfreeze to prevent crash
    gg.addListItems(jumpCount)
    jumpCounter()
    characterAnim()
    fullGameSpeed()
    charsObjectSpeed()
    gg.toast("Script ready")
  end
end

function START() --menu
  speed = gg.prompt
  (
    {'Animation Speed | default value = 1 | [0.1; 10.0]', 'Game Speed | default value = 1  [0.1; 10.0]', 'Playerobject Speed | default value = 1  [0.1; 10.0]', 'Jump hack'},
    {[1]='1', [2]='1', [3]='1'},
    {'number', 'number', 'number', 'checkbox'}
  )
  
  if speed == nil then
    noselect()
  else
    
    if speed[1] then
      for i = 1, #characterAnimation do
        characterAnimation[i]["value"] = speed[1]
      end
      gg.setValues(characterAnimation)
    end
    
    if speed[2] then
      for i = 1, #gameSpeedFull do
        gameSpeedFull[i]["value"] = speed[2]
      end
      gg.setValues(gameSpeedFull)
    end
    
    if speed[3] then
      for i = 1, #characterObjectSpeed do
        characterObjectSpeed[i]["value"] = speed[3]
      end
      gg.setValues(characterObjectSpeed)
    end
    
    if speed[4] then
      for i = 1, #jumpCount do
        jumpCount[i]["value"] = "0"
        jumpCount[i]["freeze"] = true
        gg.addListItems(jumpCount)
      end
    end
    
  end
end


function noselect()
  gg.toast('You not select anything')
end

START()
while (true) do
  if gg.isVisible() then
    gg.setVisible(false)
    START()
  else --should only execute when user used a feature for first time. 
    jumpPointer = gg.getValues(jumpPointer)
    valueCheck()
  end
  gg.sleep(200) 
end

Currently the script executes the features first before it uses gg.prompt. i want the gg.prompt to run first and then make the features only run once, and then let the while loop take care of it. However the while loop as has issues.

If the gg.prompt menu equals nil for the first time of opening it then it should not execute this else part in the while loop Untill the user has pressed his first feature in the menu, pressing "Ok" is also a feature. When user pressed a feature it won't matter anymore if menu was nil or not and the code after the else statement is then allowed to be executed:

START()
while (true) do
  if gg.isVisible() then
    gg.setVisible(false)
    START()
  else -- action after else should not be executed aslong user has used its first feature
    jumpPointer = gg.getValues(jumpPointer)
    valueCheck()
  end
  gg.sleep(200) 
end

How to proceed?

Edited by Platonic
Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

gg.prompt return nil when the user dismiss the dialog. So a simple condition check on the variable will do it 

local prompt = gg.prompt({"Enter number"})
if not prompt then 
  gg.alert("You dismissed the dialog")
else 
  gg.alert(("The number is: %s"):format(prompt[1]))
end

 

Link to comment
Share on other sites

  • 0
31 minutes ago, MAARS said:

gg.prompt return nil when the user dismiss the dialog. So a simple condition check on the variable will do it 

local prompt = gg.prompt({"Enter number"})
if not prompt then 
  gg.alert("You dismissed the dialog")
else 
  gg.alert(("The number is: %s"):format(prompt[1]))
end

 

There are issues because of the functionality of the script. 

"if gg.prompt == nil" was included in the script.

If the script is designed to open the prompt menu first before executing the  functions based on user input, i must know if the user presses nil or not untill the user used one of the features for the first time. That is my question. How can i put some check so that i know that the user has not used any feature yet, and only pressed nil instead. As long that situation is happening the script is not allowed to execute this code:

jumpPointer = gg.getValues(jumpPointer)
valueCheck()

because it will lead to a function that has a variable that only exist in the jumpCounter() function, a function that hasn't been used yet because the user pressed nil.

Also this check is needed because imagen the user used some feature in the promp but afterwards he presses nil. Then this:

jumpPointer = gg.getValues(jumpPointer)
    valueCheck()

Would not be executed because you only set a flag that it should not be executed when nil, since what i want is that it only doesn't execute untill a feature has be used.

Link to comment
Share on other sites

  • 0
1 hour ago, Platonic said:

must know if the user presses nil or not untill the user used one of the features for the first time

I am a little bit lost here can you explain a little please.

1 hour ago, Platonic said:

How can i put some check so that i know that the user has not used any feature yet

For me the simple way to solve this is using state, for example on top of your script you put 

local isUsed = false

And after the first use of your function you just set it to true 

Edited by MAARS
Link to comment
Share on other sites

  • 0

My general idea was this

local debug
local hasRedeem = false
local function main()
  debug= false 
  if not hasRedeem then
    local prompt = gg.prompt({"Enter amount to redeem:"}, nil, {'number'})
    if not prompt or not tonumber(prompt[1]) then
      gg.alert("Can not redeem")
      os.exit(1)
    end
    gg.alert(("The amount of : $%s has been redeem !"):format(prompt[1]))
    hasRedeem = true
  else
    gg.alert("You have already received a credit")
  end
end
while true do
  if gg.isVisible() then
    debug= true
    gg.setVisible(false)
  end
  if (debug) then main() end
end 

 

Edited by MAARS
Link to comment
Share on other sites

  • 0
On 9/1/2022 at 4:01 PM, MAARS said:

I am a little bit lost here can you explain a little please.

For me the simple way to solve this is using state, for example on top of your script you put 

local isUsed = false

And after the first use of your function you just set it to true 

Working great 👌🏾

Link to comment
Share on other sites

  • 0

Glad this was fixed, but I just want to say that while@MAARS's solution works, it is not very clean. This is because if not will also be true if the value is false, not just if it is nil. if not works, but it is not clean code because it is not clear whether a boolean value is expected or not. You should also try to make your code as clean and understandable as possible. For example, look at this code:

variable = false
if not variable then
alert("Variable is nil!")
else
alert("Variable is not nill!")
end

 

Link to comment
Share on other sites

  • 0
5 hours ago, HorridModz said:

Glad this was fixed, but I just want to say that while@MAARS's solution works, it is not very clean. This is because if not will also be true if the value is false, not just if it is nil. if not works, but it is not clean code because it is not clear whether a boolean value is expected or not. You should also try to make your code as clean and understandable as possible. For example, look at this code:

variable = false
if not variable then
alert("Variable is nil!")
else
alert("Variable is not nill!")
end

 

Based on my objective Maars solution is great because what i needed was for the script to execute a specific action when the condition was met. That condition was, using a feature of the prompt, if feature has been used for the first time then condition is met. Which was resolved using boolean values true/false. He gave me the idea with the expectation i implemented it. Which i did. I placed the bool at each feature. You can see it here.

Its named "menuHasBeenUsed", and its set true only when a feature from the prompt is used. For example here:

function boolCheck()
  menuHasBeenUsed = false
  loopMenu = 0
end
boolCheck()

And then in the prompt:

if speed == nil then
    noselect()
  else
    
    if speed[1] then
      menuHasBeenUsed = true
      charLoop = charLoop + 1
      if charLoop <= 1 then
        characterAnim()
      end
      for i = 1, #characterAnimation do
        characterAnimation[i]["value"] = speed[1]
      end
      gg.setValues(characterAnimation)
    end

I do not use it for nill because i dont want that "menuHasBeenUsed" becomes true if nill. So i don't see a issue.

Link to comment
Share on other sites

  • 0
9 hours ago, HorridModz said:

You should also try to make your code as clean and understandable as possible. For example, look at this code:

variable = false
if not variable then
alert("Variable is nil!")
else
alert("Variable is not nill!")
end

 

I believe the script is understandable if you understand the game a bit. I just try to avoid group searches and repeating behaviour which slows down the script or increases its size or makes me spend more time writhing. For load all cheats with group search it takes one minute. By making this script with offsets it only takes 10 sec. Then checks are also there to alert if values changed or things like that. Everything has purpose. Its also more easy for me to update as i don't need to change much things.

Edited by Platonic
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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.