Jump to content

LUA scripting


Enyby
 Share

Recommended Posts

Looks like I've finally (kind of) figured it out. I think part of what I was doing wrong was not initializing a[2] as a table, and trying to do the math to change the address while defining it. I'm sure there's a far simpler way to achieve what I was trying to do, but having created my first successful GG script I feel pleased ?

 

if gg.isVisible() then gg.setVisible(false) end 
newgame = gg.alert('Have you restarted the level?', 'Yes', 'No') 
if newgame == 2 then
  gg.toast.('Start fresh and try again!'
  os.exit() 
end 

--initial search
gg.processPause() 
gg.searchNumber('0', gg.TYPE_DWORD, false, gg.SIGN_EQUAL) 
gg.toast('Results: '..gg.getResultCount()) 

gg.processResume() 

while gg.getResultCount() > 1 do 
   gg.toast('Cause an accident!') 
   gg.sleep(5000) 
   gg.processPause() 
   acc = gg.alert('Did you crash some vehichles?', 'Yes', 'No') 
   if acc == 2 then 
      gg.searchFuzzy() 
   else 
      gg.searchFuzzy('0', gg.SIGN_FUZZY_LESS) 
   end 
   gg.processResume() 
end 

--[[
if gg.getResultCount() <10 then 
   while gg.getResultCount() > 1 do 
      gg.searchNumber('0~-10000', gg.TYPE_DWORD, false, gg.SIGN_EQUAL)
   end 
end 
]]--
  
gg.toast('Results narrowed to: '.. gg.getResultCount()) 
a = gg.getResults(1) 
a[1].value = '0' 
a[1].freeze = true
cn = a[1].address - 4
rn = a[1].address + 4
c = {}
c[1] = {}
c[1].flags = gg.TYPE_DWORD
c[1].address = cn
c[1].value = '85'
c[1].freeze = true
c[1].freezeType = gg.FREEZE_MAY_INCREASE
c[2] = {}
c[2].flags = gg.TYPE_DWORD
c[2].address = rn
c[2].value = '0'
c[2].freeze = true
c[2].freezeType = gg.FREEZE_NORMAL
gg.addListItems(a)
gg.addListItems(c)
print('Cars: '..c[1].address)
print('Traffic: '..c[2].address)
--gg.clearResults()

One thing I can't figure out is how to filter results by value. I tried searching by number after the fuzzy search, for anything between 0 to -10000(like the searchNumber() examples show for positive numbers) using SIGN_EQUAL or SIGN_GREATER but it kept getting stuck in the while loop with two results, the desired one and one that was always around -1,000,000 which I was hoping to filter out. 

Thanks again for your help, and all of your dedication to this project, it's greatly appreciated!

Link to comment
Share on other sites

  • Administrators
8 hours ago, M_JuJu said:

I can simply create a new item in the table and do

Yes.

But if a[2] not exists - you need create it before assignment values:

a[2] = {}

 

_______________________________________________
added 1 minute later
6 hours ago, M_JuJu said:

I can't figure out is how to filter results by value

Proper refine or use loop over table with results and check value. Values which not fit your criteria - set to nil.

_______________________________________________
added 3 minutes later
6 hours ago, M_JuJu said:

0 to -10000

Wrong range.

Number can not be greater 0 and smaller negative. You need swap limits. First must be smaller then second.

Link to comment
Share on other sites

1 hour ago, SolarHacks said:

How to use string.dump command???

I guess that another question needs to be asked first.
Execute this example and try to determine which one.

local env = 1234
function f()
  if env == 1234 then
    print('How to use string.dump function?')
  else
    env.print('Do I really need to use string.dump function?')
  end
end

print('\n'..tostring(f))
f()

local chunk = string.dump(f)
local f_ = load(chunk)
print('\n'..tostring(f_))
f_()

 

Link to comment
Share on other sites

  • 2 weeks later...

I'm having troubles updating certain values.

Let's say i have address: BFEBF00C
with value: 198

which i got from using this:
gg.searchNumber('198',gg.TYPE_DWORD,false,gg.SIGN_EQUAL,0xBF000000,0xC1000000)
gg.getResults()

I have a fixed offset: 3BF7C
which points to: BFEFAF88

how can i modify the value of this address? (BFEFAF88)
from what I can tell, there is no function searchaddress() where I can input the offset as variable..

I tried:

local offset = tonumber('3BF7C',16)
local address = (address + offset)
t = {}
t[1].address = address

but this throws an error: table expected for set index ('address') value, got nil
if i alert the value of address, it shows a decimal number

Link to comment
Share on other sites

1 hour ago, Double_D said:

this throws an error: table expected for set index ('address') value, got nil

if i alert the value of address, it shows a decimal number

If you look a few post above for my script I'm pretty sure you can just copy part if it as that's the same mistake I was making. Basically after you've gotten the results and all, or if you know the specific address just do: 

...
t = gg.getResults(1)
addrs = t[1].address + 245628
t[2] = {}
t[2].address = addrs
t[2].flags = gg.TYPE_DWORD
t[2].value = 'new value'
...
-- then finish with
gg.addListItems(t)

You can add in the freeze and such if needed, then voila (or at least I think - I'm also a noob, but this should work).

Edited by M_JuJu
Correction
Link to comment
Share on other sites

1 hour ago, CmP said:

How to ask primitive questions without reading API help?

Please, do it in reverse order (first - check help pages, then ask question, if answer was not found there).

https://gameguardian.net/help/classgg.html#a7efd4ac7766e72688cb4a84a3915721e

thanks bro. i have read help,but change value random.i can't take

Link to comment
Share on other sites

  • 2 weeks later...

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.