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 


Improving "minimum value" script, if you have time

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

Joined: 18 Feb 2011
Posts: 69

PostPosted: Thu Dec 12, 2013 8:51 pm    Post subject: Improving "minimum value" script, if you have time Reply with quote

Hi everyone.

I wrote this script with close to no knowledge of LUA, just scavenging parts from other topics.
It works as intended. Just one thing is annoying. When I close the game before CE I get a message every quarter second because it understandably can't write to memory.

It doesn't really matter but if someone has the time:
Can the repeat function be stopped when the process closes?
Any improvements to the script you could recommend?


Code:
function readShortint(address)
  local b1,b2 = readBytes(address,2)
  return b2*256+b1
end

function writeShortint(address, value)
  local b1 = value % 256
  local b2 = value / 256
  writeBytes(address, b1, b2)
  return nil
end


char1MaxHpAd = "FF8_EN.exe+018FF344"
char1CurHpAd = "FF8_EN.exe+018FF342"

char2MaxHpAd = "FF8_EN.exe+018FF174"
char2CurHpAd = "FF8_EN.exe+018FF172"


function GodMode(sender)

  char1MaxHp = readShortint(char1MaxHpAd)
  char1CurHp = readShortint(char1CurHpAd)

  if char1CurHp < (char1MaxHp / 4 - 1)
    then writeShortint(char1CurHpAd, char1MaxHp / 4 - 1)
  end

  char2MaxHp = readShortint(char2MaxHpAd)
  char2CurHp = readShortint(char2CurHpAd)

  if char2CurHp < (char2MaxHp / 4 - 1)
    then writeShortint(char2CurHpAd, char2MaxHp / 4 - 1)
  end

end


RepeatTimer = createTimer(nil,true)
timer_setInterval(RepeatTimer, 250)
timer_onTimer(RepeatTimer, GodMode)


DFTBA

Las0mbra
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 471

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

PostPosted: Fri Dec 13, 2013 2:45 am    Post subject: Reply with quote

add errorOnLookupFailure(false)
_________________
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
Las0mbra
Advanced Cheater
Reputation: 0

Joined: 18 Feb 2011
Posts: 69

PostPosted: Fri Dec 13, 2013 7:58 am    Post subject: Reply with quote

Thanks Dark Byte, but it didn't work. Or I'm using it wrong.

Anyway I'm an idiot I should have read and posted the error message in the first place: "attempt to perform arithmetic on local 'b2' (a nil value)"

So I've tried making the function "timer_onTimer(RepeatTimer, GodMode)" conditional upon a valid value. I tried something along this line:

Code:
If readInteger(charMidMaxHpAd) ~= nil
  then timer_onTimer(RepeatTimer, GodMode)
end


But I have no luck with that.
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Fri Dec 13, 2013 8:15 am    Post subject: Reply with quote

Quote:
errorOnLookupFailure(false); --> No errors if couldn't read memory.
function readShortint(address)
local b1,b2 = readBytes(address,2)
if (b1 and b2) then --> Checking values are not nil (successful reading).. else error trying to perform math. operation on the values..
return b2*256+b1
end
return nil --> we don't need it to be honest, because the vars will stay Nil.
end

function writeShortint(address, value)
local b1 = value % 256
local b2 = value / 256
writeBytes(address, b1, b2)
return nil
end


char1MaxHpAd = "FF8_EN.exe+018FF344"
char1CurHpAd = "FF8_EN.exe+018FF342"

char2MaxHpAd = "FF8_EN.exe+018FF174"
char2CurHpAd = "FF8_EN.exe+018FF172"


function GodMode(sender)

char1MaxHp = readShortint(char1MaxHpAd)
char1CurHp = readShortint(char1CurHpAd)
if ( char1MaxHp and char1CurHp ) --> if values are not nil.. else error trying to perform math. operation on the values..
if char1CurHp < (char1MaxHp / 4 - 1)
then writeShortint(char1CurHpAd, char1MaxHp / 4 - 1)
end
end
char2MaxHp = readShortint(char2MaxHpAd)
char2CurHp = readShortint(char2CurHpAd)
if ( char2MaxHp and char2CurHp ) --> if values are not nil.. else error trying to perform math. operation on the values..
if char2CurHp < (char2MaxHp / 4 - 1)
then writeShortint(char2CurHpAd, char2MaxHp / 4 - 1)
end
end
end


RepeatTimer = createTimer(nil,true)
timer_setInterval(RepeatTimer, 250)
timer_onTimer(RepeatTimer, GodMode)


It seems that quote removes spaces (and /t) in beginning of the line..
Here's the script (No highlighting).

Code:
errorOnLookupFailure(false); --> No errors if couldn't read memory.
function readShortint(address)
   local b1,b2 = readBytes(address,2)
   if (b1 and b2) then --> Checking values are not nil (successful reading).. else error trying to perform math. operation on the values..
      return b2*256+b1
   end
   return nil --> we don't need it to be honest, because the vars will stay Nil.
end

function writeShortint(address, value)
   local b1 = value % 256
   local b2 = value / 256
   writeBytes(address, b1, b2)
   return nil
end


char1MaxHpAd = "FF8_EN.exe+018FF344"
char1CurHpAd = "FF8_EN.exe+018FF342"

char2MaxHpAd = "FF8_EN.exe+018FF174"
char2CurHpAd = "FF8_EN.exe+018FF172"


function GodMode(sender)

   char1MaxHp = readShortint(char1MaxHpAd)
   char1CurHp = readShortint(char1CurHpAd)
   if ( char1MaxHp and char1CurHp ) --> if values are not nil.. else error trying to perform math. operation on the values..
      if char1CurHp < (char1MaxHp / 4 - 1)
         then writeShortint(char1CurHpAd, char1MaxHp / 4 - 1)
      end
   end
   char2MaxHp = readShortint(char2MaxHpAd)
   char2CurHp = readShortint(char2CurHpAd)
   if ( char2MaxHp and char2CurHp ) --> if values are not nil.. else error trying to perform math. operation on the values..
      if char2CurHp < (char2MaxHp / 4 - 1)
         then writeShortint(char2CurHpAd, char2MaxHp / 4 - 1)
      end
   end
end


RepeatTimer = createTimer(nil,true)
timer_setInterval(RepeatTimer, 250)
timer_onTimer(RepeatTimer, GodMode)

_________________
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
Las0mbra
Advanced Cheater
Reputation: 0

Joined: 18 Feb 2011
Posts: 69

PostPosted: Fri Dec 13, 2013 8:55 am    Post subject: Reply with quote

Thank you very much DaSpamer. Works perfectly.
Back to top
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Fri Dec 13, 2013 9:02 am    Post subject: Reply with quote

Las0mbra wrote:
Thank you very much DaSpamer. Works perfectly.

Great.
Let me know if you want to accomplish something and don't know what to do Wink.

_________________
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
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