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 


Part of Script does Nothing

 
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 Aug 14, 2016 2:31 pm    Post subject: Part of Script does Nothing Reply with quote

When injecting the code, the set keys E, R, T, Y do nothing not sure if they arent even working, or if the p1animstate is changing too fast.
This is the code in it's "lua" entirety:

Code:
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
if bunted == 3 then hitstun_countdown = 20
bally = readInteger("[ballcoords]+1c")
ballx = readInteger("[ballcoords]+18")
p1animstate = readInteger("[p1state]+138")
p2animstate = readInteger("[p2state]+138")
p3animstate = readInteger("[p3state]+138")
p4animstate = readInteger("[p4state]+138")
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
end
if hitstun_countdown > 120 then hitstun_countdown = 0
end

if isKeyPressed(VK_E) and p1animstate == 16 then
doKeyPress(VK_X)
end

if isKeyPressed(VK_R) and p2animstate == 16 then
doKeyPress(VK_X)
end

if isKeyPressed(VK_T) and p3animstate == 16 then
doKeyPress(VK_X)
end

if isKeyPressed(VK_Y) and p4animstate == 16 then
doKeyPress(VK_X)
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
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Mon Aug 15, 2016 12:45 am    Post subject: Reply with quote

Try using
Code:

keyDown(VK_Z)
sleep(50)
keyUp(VK_Z)

Or use sendMessage

_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
Zanzer
I post too much
Reputation: 126

Joined: 09 Jun 2013
Posts: 3278

PostPosted: Mon Aug 15, 2016 4:58 pm    Post subject: Reply with quote

Here's what your code looks like when it's properly indented.
Hopefully this makes it obvious to you where you screwed up.
Hint: You probably didn't want nested if statements.
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
      if bunted == 3 then
        hitstun_countdown = 20
        bally = readInteger("[ballcoords]+1c")
        ballx = readInteger("[ballcoords]+18")
        p1animstate = readInteger("[p1state]+138")
        p2animstate = readInteger("[p2state]+138")
        p3animstate = readInteger("[p3state]+138")
        p4animstate = readInteger("[p4state]+138")
        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
  end
  if hitstun_countdown > 120 then
    hitstun_countdown = 0
  end

  if isKeyPressed(VK_E) and p1animstate == 16 then
    doKeyPress(VK_X)
  end

  if isKeyPressed(VK_R) and p2animstate == 16 then
    doKeyPress(VK_X)
  end

  if isKeyPressed(VK_T) and p3animstate == 16 then
    doKeyPress(VK_X)
  end

  if isKeyPressed(VK_Y) and p4animstate == 16 then
    doKeyPress(VK_X)
  end
end
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: Mon Aug 15, 2016 5:02 pm    Post subject: Reply with quote

DaSpamer wrote:
Try using
Code:

keyDown(VK_Z)
sleep(50)
keyUp(VK_Z)

Or use sendMessage

Thanks dude, I appreciate it, the keyDown keyUp worked.
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