Jump to content

Recommended Posts

Posted

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

Posted

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

 

  • Like 2

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...