 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
Las0mbra Advanced Cheater
Reputation: 0
Joined: 18 Feb 2011 Posts: 69
|
Posted: Thu Dec 12, 2013 8:51 pm Post subject: Improving "minimum value" script, if you have time |
|
|
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 |
|
 |
Dark Byte Site Admin
Reputation: 471
Joined: 09 May 2003 Posts: 25819 Location: The netherlands
|
Posted: Fri Dec 13, 2013 2:45 am Post subject: |
|
|
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 |
|
 |
Las0mbra Advanced Cheater
Reputation: 0
Joined: 18 Feb 2011 Posts: 69
|
Posted: Fri Dec 13, 2013 7:58 am Post subject: |
|
|
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 |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Fri Dec 13, 2013 8:15 am Post subject: |
|
|
| 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 |
|
 |
Las0mbra Advanced Cheater
Reputation: 0
Joined: 18 Feb 2011 Posts: 69
|
Posted: Fri Dec 13, 2013 8:55 am Post subject: |
|
|
| Thank you very much DaSpamer. Works perfectly.
|
|
| Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
|
| Back to top |
|
 |
|
|
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
|
|