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 


Following object x coord

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
microsoftv
Advanced Cheater
Reputation: 0

Joined: 07 Apr 2016
Posts: 82
Location: U.S

PostPosted: Sun Jul 31, 2016 2:13 pm    Post subject: Following object x coord Reply with quote

When trying to inject
Code:

[ENABLE]
{$lua}
if(t ~= nil) then -- if script is already running then
    timer_setEnabled(t, false) -- stop the script
    object_destroy(t)
    t = nil
end

tickrate = 1 -- 50ms is every 3 frames

function main ()
hitstun_countdown = readInteger(getAddress("[ballstate]+128"))/1092
if hitstun_countdown < 0 then hitstun_countdown = 0
bunted = readInteger(getAddress("[ballstate]+144"))
if bunted == 8 then hitstun_countdown = 0
bally = readInteger("[ballcoords]+1c")
ballx = readInteger("[ballcoords]+18")
p4y = readInteger("[p4coords]+1c")
p4x = readInteger("[p4coords]+18")
p3y = readInteger("[p3coords]+1c")
p3x = readInteger("[p3coords]+18")
p2y = readInteger("[p2coords]+1c")
p2x = readInteger("[p2coords]+18")
p1y = readInteger("[p1coords]+1c")
p1x = readInteger("[p1coords]+18")
distance = math.sqrt((ballx-p1x)*(ballx-p1x)+(bally-p1y)*(bally-p1y))
end
end
if hitstun_countdown > 120 then hitstun_countdown = 0
end
if isKeyPressed(VK_C) and hitstun_countdown >= 0 and hitstun_countdown <= 8 then
doKeyPress(VK_DOWN)
sleep(1)
if isKeyPressed(VK_C) and hitstun_countdown >= 0 and hitstun_countdown <= 8 then
doKeyPress(VK_SPACE)
end
end
if isKeyPressed(VK_B) and hitstun_countdown >= 1 and hitstun_countdown <= 5 then
doKeyPress(VK_X)
end
end
if isKeyPressed(VK_V) and hitstun_countdown >= 0 and hitstun_countdown <= 1 then
doKeyPress(VK_Z)
end
if isKeyPressed(VK_D) and ballx <= p1x then
doKeyPress(VK_LEFT)
end

if isKeyPressed(VK_D) and ballx >= p1x then
doKeyPress(VK_RIGHT)
end

if isKeyPressed(VK_S) and p1x <= 40900000 then
doKeyPress(VK_LEFT)

if isKeyPressed(VK_S) and p1x >= 40900000 then
doKeyPress(VK_RIGHT)
end
end

  createHotkey(function(hk)
    local dx = readInteger("[ballcoords]+18")-readInteger("[p1coords]+18")
    local dy = readInteger("[ballcoords]+1c")-readInteger("[p1coords]+1c")

    if math.sqrt(dx*dx+dy*dy) <= 9000000 and hitstun_countdown >= 0 and hitstun_countdown <= 1 then
      doKeyPress(VK_Z)
    end
  end, VK_D)

  createHotkey(function(hk)
    local dx = readInteger("[ballcoords]+18")-readInteger("[p2coords]+18")
    local dy = readInteger("[ballcoords]+1c")-readInteger("[p2coords]+1c")

    if math.sqrt(dx*dx+dy*dy) <= 9000000 and hitstun_countdown >= 0 and hitstun_countdown <= 1 then
      doKeyPress(VK_Z)
    end
  end, VK_F)

  createHotkey(function(hk)
    local dx = readInteger("[ballcoords]+18")-readInteger("[p3coords]+18")
    local dy = readInteger("[ballcoords]+1c")-readInteger("[p3coords]+1c")

    if math.sqrt(dx*dx+dy*dy) <= 9000000 and hitstun_countdown >= 0 and hitstun_countdown <= 1 then
      doKeyPress(VK_Z)
    end
  end, VK_G)

  createHotkey(function(hk)
    local dx = readInteger("[ballcoords]+18")-readInteger("[p4coords]+18")
    local dy = readInteger("[ballcoords]+1c")-readInteger("[p4coords]+1c")

    if math.sqrt(dx*dx+dy*dy) <= 9000000 and hitstun_countdown >= 0 and hitstun_countdown <= 1 then
      doKeyPress(VK_Z)
    end
  end, VK_H)

t = createTimer(nil, false)  -- create a Timer object and assign it to variable t
timer_onTimer(t, main)   -- When the timer ticks, call the function main
timer_setInterval(t, tickrate) -- Sets the tickrate of the timer in milliseconds
timer_setEnabled(t, true) -- Turns the timer on -- Lua code here
{$asm}
// other assembly code
[DISABLE]
// etc...

It simply doesn't do anything when trying to do the key press S and D (not the one below "createHotkey" )
Any help is very appreciated, not many people would sit on here moderating for nothing.


Last edited by microsoftv on Sun Jul 31, 2016 3:32 pm; edited 2 times in total
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Jul 31, 2016 3:21 pm    Post subject: Reply with quote

You have two values which are nil and you are attempting to compare them. It's on line 32.

Your posted code is completely invalid.

Good luck.
Back to top
View user's profile Send private message
microsoftv
Advanced Cheater
Reputation: 0

Joined: 07 Apr 2016
Posts: 82
Location: U.S

PostPosted: Sun Jul 31, 2016 3:32 pm    Post subject: Reply with quote

Zanzer wrote:
You have two values which are nil and you are attempting to compare them. It's on line 32.

Your posted code is completely invalid.

Good luck.

Edited post
Didn't have full code.
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Jul 31, 2016 5:29 pm    Post subject: Reply with quote

Your code injects just fine for me. No error until I try pressing these hotkeys (because I don't have game).

You may want to indent your code so that you can actually see where your function and if-statements end.

Half of your code isn't in the function, which I assume you wanted it to be.
Back to top
View user's profile Send private message
microsoftv
Advanced Cheater
Reputation: 0

Joined: 07 Apr 2016
Posts: 82
Location: U.S

PostPosted: Sun Jul 31, 2016 6:42 pm    Post subject: Reply with quote

Zanzer wrote:
Your code injects just fine for me. No error until I try pressing these hotkeys (because I don't have game).

You may want to indent your code so that you can actually see where your function and if-statements end.

Half of your code isn't in the function, which I assume you wanted it to be.

Which half isn't in the function?
Back to top
View user's profile Send private message
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Sun Jul 31, 2016 7:52 pm    Post subject: Reply with quote

Below is the top half of your code with proper indentation.
Just because you put an instruction after "then" on the same line, doesn't mean that's the end of the if statement.
Everything after it until it reaches an "end" is included within that block.
Code:
function main ()
  hitstun_countdown = readInteger(getAddress("[ballstate]+128"))/1092
  if hitstun_countdown < 0 then hitstun_countdown = 0
    bunted = readInteger(getAddress("[ballstate]+144"))
    if bunted == 8 then hitstun_countdown = 0
      bally = readInteger("[ballcoords]+1c")
      ballx = readInteger("[ballcoords]+18")
      p4y = readInteger("[p4coords]+1c")
      p4x = readInteger("[p4coords]+18")
      p3y = readInteger("[p3coords]+1c")
      p3x = readInteger("[p3coords]+18")
      p2y = readInteger("[p2coords]+1c")
      p2x = readInteger("[p2coords]+18")
      p1y = readInteger("[p1coords]+1c")
      p1x = readInteger("[p1coords]+18")
      distance = math.sqrt((ballx-p1x)*(ballx-p1x)+(bally-p1y)*(bally-p1y))
    end
  end
  if hitstun_countdown > 120 then hitstun_countdown = 0
  end
  if isKeyPressed(VK_C) and hitstun_countdown >= 0 and hitstun_countdown <= 8 then
    doKeyPress(VK_DOWN)
    sleep(1)
    if isKeyPressed(VK_C) and hitstun_countdown >= 0 and hitstun_countdown <= 8 then
      doKeyPress(VK_SPACE)
    end
  end
  if isKeyPressed(VK_B) and hitstun_countdown >= 1 and hitstun_countdown <= 5 then
    doKeyPress(VK_X)
  end
end -- END OF MAIN FUNCTION HERE

if isKeyPressed(VK_V) and hitstun_countdown >= 0 and hitstun_countdown <= 1 then
  doKeyPress(VK_Z)
end
if isKeyPressed(VK_D) and ballx <= p1x then
  doKeyPress(VK_LEFT)
end

if isKeyPressed(VK_D) and ballx >= p1x then
  doKeyPress(VK_RIGHT)
end

if isKeyPressed(VK_S) and p1x <= 40900000 then
  doKeyPress(VK_LEFT)
  if isKeyPressed(VK_S) and p1x >= 40900000 then
   doKeyPress(VK_RIGHT)
  end
end
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