Zed_Master Posted September 27, 2017 Share Posted September 27, 2017 Hey all ! I would like add some cheat code in my game Question is how can I catch the cheat code from keyboard ? I suppose it's the same way from the script for the fpsPlayer (W,A,S,D) but I need to catch more than 1 key Any idea ? Thx Quote Link to comment Share on other sites More sharing options...
GorzenDev Posted September 27, 2017 Share Posted September 27, 2017 in theorie you could check KeyHit() for each letter you need as you suggested then put each letter into a string and compare that string to your cheat. you obviously would want to put some kind of timer/delay in between each keypress to make sure the typing of the cheat is done in a certain time period else discard the string. pseudo code: self.godMode = false self.lastPress = 0 self.cheatstring = "" local maxPressTime = 5000 --assuming 1000 is 1 second if window:KeyHit(Key.G) then self.cheatstring = self.cheatstring + "g" self.lastPress = Time:GetCurrent() end if window:KeyHit(Key.O) then self.cheatstring = self.cheatstring + "o" self.lastPress = Time:GetCurrent() end if window:KeyHit(Key.D) then self.cheatstring = self.cheatstring + "d" self.lastPress = Time:GetCurrent() end if self.cheatstring.compare("god") then self.godMode = true; end local pressCheck = Time:Getcurrent() - self.lastPress if pressCheck > maxPressTime then self.cheatstring = "" self.lastPress = 0; end 2 Quote Link to comment Share on other sites More sharing options...
Zed_Master Posted September 28, 2017 Author Share Posted September 28, 2017 It look pretty good i'll try this ! Thx for the help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.