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 


Speedhack with gamepad trigger

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

Joined: 08 Jan 2020
Posts: 2

PostPosted: Wed Jan 08, 2020 1:35 pm    Post subject: Speedhack with gamepad trigger Reply with quote

Hello. I've tried various codes but couldn't find a solution. I'm no means a LUA expert but I have some programming background. Here's the code I wrote.

Code:
function checkKeys(timer)
  xboxState = getXBox360ControllerState()
  if (xboxState[LeftTrigger] == nil) then
    speedhack_setSpeed(1)
  elseif (50 < xboxState[LeftTrigger] <= 100) then
    speedhack_setSpeed(2)
  elseif (100 < xboxState[LeftTrigger] <= 150) then
    speedhack_setSpeed(3)
  elseif (150 < xboxState[LeftTrigger] <= 200) then
    speedhack_setSpeed(4)
  elseif (200 < xboxState[LeftTrigger] <= 255) then
    speedhack_setSpeed(8)
  else
    speedhack_setSpeed(1)
  end
end

t=createTimer(nil)
timer_setInterval(t, 100)
timer_onTimer(t, checkKeys)
timer_setEnabled(t, true)


I'm trying to make it go faster with the more I press. The thing is it doesn't ever detect a press. It always returns nil. I've tried another UI based joystick tester with Cheat Engine and it works perfectly.

I've tried xboxState.LeftTrigger and 1 or 0, says that I'm trying to compare bool to int.

How can I make this happen?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

Joined: 09 May 2003
Posts: 25827
Location: The netherlands

PostPosted: Wed Jan 08, 2020 1:55 pm    Post subject: Reply with quote

Because
Code:

elseif (50 < xboxState.LeftTrigger <= 100) then


gets parsed by lua into:
Code:

elseif (booleanresult <= 100) then


Also, xboxState.LeftTrigger will work

When in doubt, always test the code with something simple, and prints always help
(open lua engine, ctrl+alt+shift+l) and paste
Code:

function checkKeys(timer)
  xboxState = {} --getXBox360ControllerState()
  xboxState.LeftTrigger=154

  if (xboxState.LeftTrigger == nil) then
    print('1')
  elseif (50 < xboxState.LeftTrigger) and (xboxState.LeftTrigger <= 100) then
    print(2)
  elseif (100 < xboxState.LeftTrigger) and (xboxState.LeftTrigger <= 150) then
    print(3)
  elseif (150 < xboxState.LeftTrigger) and (xboxState.LeftTrigger <= 200) then
    print(4)
  elseif (200 < xboxState.LeftTrigger) and (xboxState.LeftTrigger <= 255) then
    print(8)
  else
    print(1)
  end
end

checkKeys()

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
gyunbie
How do I cheat?
Reputation: 0

Joined: 08 Jan 2020
Posts: 2

PostPosted: Wed Jan 08, 2020 2:27 pm    Post subject: Reply with quote

Dark Byte wrote:
Because
Code:

elseif (50 < xboxState.LeftTrigger <= 100) then


gets parsed by lua into:
Code:

elseif (booleanresult <= 100) then


Also, xboxState.LeftTrigger will work

When in doubt, always test the code with something simple, and prints always help
(open lua engine, ctrl+alt+shift+l) and paste
Code:

function checkKeys(timer)
  xboxState = {} --getXBox360ControllerState()
  xboxState.LeftTrigger=154

  if (xboxState.LeftTrigger == nil) then
    print('1')
  elseif (50 < xboxState.LeftTrigger) and (xboxState.LeftTrigger <= 100) then
    print(2)
  elseif (100 < xboxState.LeftTrigger) and (xboxState.LeftTrigger <= 150) then
    print(3)
  elseif (150 < xboxState.LeftTrigger) and (xboxState.LeftTrigger <= 200) then
    print(4)
  elseif (200 < xboxState.LeftTrigger) and (xboxState.LeftTrigger <= 255) then
    print(8)
  else
    print(1)
  end
end

checkKeys()


I understand now. Thank you so much!
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