Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Why lua script not working?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Fovoc37
How do I cheat?
Reputation: 0

Joined: 30 Sep 2018
Posts: 9

PostPosted: Sun Sep 30, 2018 9:27 am    Post subject: Why lua script not working? Reply with quote

Hello everyone, I'm just learning to write on lua Very Happy
I wrote a script, but when I press a key, nothing in the game changes Sad
Code:
{$lua}
[ENABLE]

function ChangeValue()

         Main = readInteger("[gta_sa.exe+00D91078]+2FC")
         Main2 = readInteger("[[[[gta_sa.exe+00DA8CC4]+C]+14]+F4]+4")

         if isKeyPressed(VK_F1) then
            getData()
            if (Main == 0) or (Main2 ==0) then
               writeInteger("[gta_sa.exe+00D91078]+2FC", 5)
               writeInteger("[[[[gta_sa.exe+00DA8CC4]+C]+14]+F4]+4",5)
            elseif (Main == 1) or (Main2 == 1) then
                writeInteger("[gta_sa.exe+00D91078]+2FC", 4)
                writeInteger("[[[[gta_sa.exe+00DA8CC4]+C]+14]+F4]+4", 4)
            end
         end
end

function getData()
         Main = readInteger("[gta_sa.exe+00D91078]+2FC")
         Main2 = readInteger("[[[[gta_sa.exe+00DA8CC4]+C]+14]+F4]+4")
end

[DISABLE]


Can you help me, where did I make a mistake? Question


Last edited by Fovoc37 on Sun Sep 30, 2018 4:16 pm; edited 1 time in total
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Sep 30, 2018 9:39 am    Post subject: Reply with quote

changeValue isn't called, let alone often enough to detect you pressing a key at exactly the same time that you are actually pressing it.

CE has a hotkey object for this purpose
Code:
{$lua}
[ENABLE]
global_main_hk = createHotkey(function()
  local mainAddr = "[gta_sa.exe+00D91078]+2FC"
  local mainAddr2 = "[[[[gta_sa.exe+00DA8CC4]+C]+14]+F4]+4"
  local Main = readInteger(mainAddr)
  local Main2 = readInteger(mainAddr2)
  print("Main/Main2 before: ", Main, "/", Main2)
  if (Main == 1) or (Main2 == 1) then
    writeInteger(mainAddr, 2)
    writeInteger(mainAddr2, 2)
  elseif (Main == 2) or (Main2 == 2) then
    writeInteger(mainAddr, 1)
    writeInteger(mainAddr2, 1)
  end
  print("Main/Main2 after: ", Main, "/", Main2)
end, VK_F1)
[DISABLE]
if global_main_hk then global_main_hk.destroy() end

_________________
https://github.com/FreeER/ has a few CE related repos
Back to top
View user's profile Send private message
Fovoc37
How do I cheat?
Reputation: 0

Joined: 30 Sep 2018
Posts: 9

PostPosted: Sun Sep 30, 2018 10:04 am    Post subject: Reply with quote

FreeER wrote:
changeValue isn't called, let alone often enough to detect you pressing a key at exactly the same time that you are actually pressing it.

CE has a hotkey object for this purpose
Code:
{$lua}
[ENABLE]
global_main_hk = createHotkey(function()
  local mainAddr = "[gta_sa.exe+00D91078]+2FC"
  local mainAddr2 = "[[[[gta_sa.exe+00DA8CC4]+C]+14]+F4]+4"
  local Main = readInteger(mainAddr)
  local Main2 = readInteger(mainAddr2)
  print("Main/Main2 before: ", Main, "/", Main2)
  if (Main == 1) or (Main2 == 1) then
    writeInteger(mainAddr, 2)
    writeInteger(mainAddr2, 2)
  elseif (Main == 2) or (Main2 == 2) then
    writeInteger(mainAddr, 1)
    writeInteger(mainAddr2, 1)
  end
  print("Main/Main2 after: ", Main, "/", Main2)
end, VK_F1)
[DISABLE]
if global_main_hk then global_main_hk.destroy() end


Thank you, you really helped me! Mr. Green
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites