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 


Multiply a value upon increase

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

Joined: 20 Dec 2018
Posts: 2
Location: Chicago, IL

PostPosted: Thu Dec 20, 2018 2:04 pm    Post subject: Multiply a value upon increase Reply with quote

Hey guys. I did an hour of googling before coming here so sorry if this has been asked before.

I'd like to set up a script that will increase the rate of experience gained in a game. Experience is stored as a 4 Byte variable.

Is there a way to compare the previous value with the new one, then multiply the difference, and add that to the new value? In this case, I would like to double the amount of experience gained, so I suppose simply being able to find the difference and adding it to the new value again would do the trick.

Thanks in advance.

P.S. I am not positive whether or not experience increments until it reaches the new value, or if the change in the variable is instantaneous. I would imagine this could cause complications if it did increment until the "gained" experience is depleted, especially if the script applies every time the experience value is changed. The change appears instant, but I'd have to play further into the game to see bigger experience values before I could really tell a difference.

---

I've used Cheat Engine for years now to do simple variable edits, but nothing too much more complicated than finding and editing values like money and experience. I haven't touched any scripting.

If there's a tutorial out there that will handle what I'm trying to accomplish, I'd be glad to take a look at that as well!
Back to top
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 140

Joined: 06 Jul 2014
Posts: 4289

PostPosted: Thu Dec 20, 2018 3:02 pm    Post subject: Reply with quote

Using AA to inject code would likely be best (see step 7 "Code Injection" of the CE tutorial), but Lua can do what you're asking.
Code:
local oldv = tonumber(AddressList.getMemoryRecordByDescription'My Experience'.Value)
local t = createTimer()

t.Interval = 200
t.OnTimer = function(t)
  local mr = AddressList.getMemoryRecordByDescription'My Experience'
  if not mr then t.destroy(); return end

  local v = tonumber(mr.Value)

  if v - oldv > 0 then  -- increased
    oldv = 2*v - oldv
    mr.Value = tostring(oldv)
  elseif v - oldv < 0 then -- decreased
    oldv = v
  end
end
edit: removed print
_________________
I don't know where I'm going, but I'll figure it out when I get there.


Last edited by ParkourPenguin on Thu Dec 20, 2018 5:33 pm; edited 1 time in total
Back to top
View user's profile Send private message
eXistensial Warlock
How do I cheat?
Reputation: 0

Joined: 20 Dec 2018
Posts: 2
Location: Chicago, IL

PostPosted: Thu Dec 20, 2018 4:56 pm    Post subject: Reply with quote

Hey, this looks like what I'm looking for. Thanks a bunch!
Back to top
View user's profile Send private message
u2l
How do I cheat?
Reputation: 0

Joined: 20 Jun 2020
Posts: 8

PostPosted: Mon Jun 22, 2020 3:32 am    Post subject: Reply with quote

ParkourPenguin wrote:
Using AA to inject code would likely be best (see step 7 "Code Injection" of the CE tutorial), but Lua can do what you're asking.
Code:
local oldv = tonumber(AddressList.getMemoryRecordByDescription'My Experience'.Value)
local t = createTimer()

t.Interval = 200
t.OnTimer = function(t)
  local mr = AddressList.getMemoryRecordByDescription'My Experience'
  if not mr then t.destroy(); return end

  local v = tonumber(mr.Value)

  if v - oldv > 0 then  -- increased
    oldv = 2*v - oldv
    mr.Value = tostring(oldv)
  elseif v - oldv < 0 then -- decreased
    oldv = v
  end
end
edit: removed print


I'm using your code and it works, but is there a way to do this for multiple characters?. I try messing around with the code and just create "My Experience2", "My Experience3" for my other characters but sometimes it would work for 2 of them, most of the time only 1 is getting the multiplied exp. if there is a better way, would you lay down the foundation so I can plug in the numbers?. I don't have any coding experience so plz be specific with the instruction if you can. thank you

right now my code looks something like this. it looks dumb since I'm just making it up by tripling everything base on your code


local oldv = tonumber(AddressList.getMemoryRecordByDescription'Brooklyn Luckfield x5 exp'.Value)
local oldvmain = tonumber(AddressList.getMemoryRecordByDescription'main char x5 exp'.Value)
local oldvcute = tonumber(AddressList.getMemoryRecordByDescription'cute chick xp x5'.Value)
local t = createTimer()


t.Interval = 200
t.OnTimer = function(t)
local mr = AddressList.getMemoryRecordByDescription'Brooklyn Luckfield x5 exp'
local mrmain = AddressList.getMemoryRecordByDescription'main char x5 exp'
local mrcute= AddressList.getMemoryRecordByDescription'cute chick xp x5'

if not mr then t.destroy(); return end
if not mrmain then t.destroy(); return end
if not mrcute then t.destroy(); return end

......
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1247

PostPosted: Mon Jun 22, 2020 5:35 am    Post subject: Reply with quote

[quote="u2l"]
Quote:
I'm using your code and it works, but is there a way to do this for multiple characters?. I try messing around with the code and just create "My Experience2", "My Experience3" for my other characters but sometimes it would work for 2 of them, most of the time only 1 is getting the multiplied exp. if there is a better way, would you lay down the foundation so I can plug in the numbers?. I don't have any coding experience so plz be specific with the instruction if you can. thank you


Maybe something like this ..
Code:
function ExpHack(Name1, multiplier)
multiplier = tonumber(multiplier)
local oldv1 = AddressList.getMemoryRecordByDescription(Name1)
oldv = tonumber(oldv1.Value)
--print(oldv)
local t = createTimer()
t.Interval = 200
t.OnTimer = function(t)
  local mr = AddressList.getMemoryRecordByDescription(Name1) --'My Experience'
  if not mr then t.destroy(); return end

  local v = tonumber(mr.Value)

  if v - oldv > 0 then  -- increased
    oldv = multiplier * v - oldv
    mr.Value = tostring(oldv)
  --  print(v.." - "..oldv)
    t.destroy()
  elseif v - oldv < 0 then -- decreased
    oldv = v
  --  print(v.." - "..oldv)
    t.destroy()
  end
end
end

ExpHack("My Experience", 2)
ExpHack("My Experience1", 4)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
u2l
How do I cheat?
Reputation: 0

Joined: 20 Jun 2020
Posts: 8

PostPosted: Mon Jun 22, 2020 12:57 pm    Post subject: Reply with quote

thank you for taking your time to help me with the coding, I was wondering how to modify exp for player 2,3 .... from your code, do I repeat all the codes above for player 2 after the end function?

again, I apologize if the answer is something obvious, I'm pretty clueless with these stuff ^^!
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1247

PostPosted: Tue Jun 23, 2020 7:03 am    Post subject: Reply with quote

u2l wrote:
.... from your code, do I repeat all the codes above for player 2 after the end function?



I just saw the solution code assigned to the topic and provided by @ParkourPenguin.
I have arranged for more than one player.
For example, you can assign the same code to the "Button Click" event for 3 players.

Sample;
Code:
UDF1.CEButton1.OnClick=function()
ExpHack("My Experience", 2)
end

UDF1.CEButton2.OnClick=function()
ExpHack("My Experience1", 2)
end

UDF1.CEButton3.OnClick=function()
ExpHack("My Experience2", 2)
end


You can also give a follow-up and print the changes.
It has been added to the following code;

Code:
print("increased: "..v.." - "..oldv.." - "..Name1)


Code:
function ExpHack(Name1, multiplier)
multiplier = tonumber(multiplier)
local oldv1 = AddressList.getMemoryRecordByDescription(Name1)
oldv = tonumber(oldv1.Value)
--print(oldv)
local t = createTimer()
t.Interval = 200
t.OnTimer = function(t)
  local mr = AddressList.getMemoryRecordByDescription(Name1) --'My Experience'
  if not mr then t.destroy(); return end

  local v = tonumber(mr.Value)

  if v - oldv > 0 then  -- increased
    oldv = multiplier * v - oldv
    mr.Value = tostring(oldv)
    print("increased: "..v.." - "..oldv.." - "..Name1)
    t.destroy()
  elseif v - oldv < 0 then -- decreased
    oldv = v
    print("decreased: "..v.." - "..oldv.." - "..Name1)
    t.destroy()
  end
end
end

function Exp1()
ExpHack("My Experience", 2)
end

function Exp2()
ExpHack("My Experience1", 2)
end

htk1=createHotkey(Exp1, VK_F8)
htk2=createHotkey(Exp2, VK_F9)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
u2l
How do I cheat?
Reputation: 0

Joined: 20 Jun 2020
Posts: 8

PostPosted: Sat Jun 27, 2020 9:50 am    Post subject: Reply with quote

ty once again, I haven't tried using it but will do soon. Hopefully I'll get it to work!
Back to top
View user's profile Send private message
u2l
How do I cheat?
Reputation: 0

Joined: 20 Jun 2020
Posts: 8

PostPosted: Sun Jun 28, 2020 1:32 pm    Post subject: Reply with quote

I can't get your code to work after playing around with it, it's most probably my fault for not knowing how to use it properly. I'm not sure what's suppose to go in the "..." of the "..v.." , if anything at all.

I suppose the fastest way you could help me out is this:
Let's say I'v found 2 addresses, I name them "main character" and "boss"

Could you plug in the names in the above code, give main character x2 exp and boss x4 exp?

I guess it's gotta be that specific for me to replicate it for other games ><
again, thank you for your trouble.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1247

PostPosted: Sun Jun 28, 2020 4:20 pm    Post subject: Reply with quote

u2l wrote:
I name them "main character" and "boss"

Could you plug in the names in the above code, give main character x2 exp and boss x4 exp?



Code:
ExpHack("main character", 2)

ExpHack("boss", 4)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
u2l
How do I cheat?
Reputation: 0

Joined: 20 Jun 2020
Posts: 8

PostPosted: Sun Jun 28, 2020 10:10 pm    Post subject: Reply with quote

I get this error when trying to execute the script, could there be something wrong with the code?

EDIT: I tried your earlier code and it works, however it seems only the first player get the multiplier but not second player, I have changed the value in the address manually to confirm that it's the right one. so in the attached picture (but applied for earlier code), Marica doesn't get the multiplier, only Pan.



Screen Shot 2020-06-29 at 11.08.18.png
 Description:
 Filesize:  546.36 KB
 Viewed:  8800 Time(s)

Screen Shot 2020-06-29 at 11.08.18.png


Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1247

PostPosted: Mon Jun 29, 2020 3:49 am    Post subject: Reply with quote

I think you are right.
For multiple players, it uses focus.
The code below focuses on the player you want to follow and upgrade.
Sample; Click "F8" to follow and upgrade the "Pan" player.
To return to the "Marica" player, click "F9".

Code:
function ExpHack(Name1, multiplier)
multiplier = tonumber(multiplier)
local oldv1 = AddressList.getMemoryRecordByDescription(Name1)
oldv = tonumber(oldv1.Value)
print(Name1.." - "..oldv)
local t = createTimer()
t.Interval = 200
t.OnTimer = function(t)
  local mr = AddressList.getMemoryRecordByDescription(Name1) --'My Experience'
  if not mr then t.destroy(); return end

  local v = tonumber(mr.Value)

  if v - oldv > 0 then  -- increased
    oldv = multiplier * v - oldv
    mr.Value = tostring(oldv)
    print("increased: "..v.." - "..oldv.." - "..Name1)
    t.destroy()
    Name1=""
  elseif v - oldv < 0 then -- decreased
    oldv = v
    print("decreased: "..v.." - "..oldv.." - "..Name1)
    --t.destroy()
    Name1=""
  end
end
end


--ExpHack("Pan", 2)
--ExpHack("Marica", 2)

function Exp1()
ExpHack("Pan", 2)
end

function Exp2()
ExpHack("Marica", 2)
end

if htk1 then htk1.destroy() end
if htk1 then htk2.destroy() end
htk1=createHotkey(Exp1, VK_F8)
htk2=createHotkey(Exp2, VK_F9)

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
u2l
How do I cheat?
Reputation: 0

Joined: 20 Jun 2020
Posts: 8

PostPosted: Thu Jul 02, 2020 5:24 am    Post subject: Reply with quote

hey just wanna say thank you for the prompt replies and help, exp multiplier for 1 character is fine. I have this really weird way of wanting to play any new games on highest difficulty but not having to do the grind. giving some of my characters 3x exp usually does the trick for me. it probably makes the game unbalance for sure but that's just how I like to play lol.
Back to top
View user's profile Send private message
AylinCE
Grandmaster Cheater Supreme
Reputation: 31

Joined: 16 Feb 2017
Posts: 1247

PostPosted: Thu Jul 02, 2020 7:49 am    Post subject: Reply with quote

u2l wrote:
hey just wanna say thank you for the prompt replies and help, exp multiplier for 1 character is fine. I have this really weird way of wanting to play any new games on highest difficulty but not having to do the grind. giving some of my characters 3x exp usually does the trick for me. it probably makes the game unbalance for sure but that's just how I like to play lol.



Nice idea @u2l .. Cool
Don't stop cheating.
You will probably spend more time with codes while cheating.
This will familiarize you with the codes.
In fact, CE is a fun tool to bring you closer to these codes.

_________________
Hi Hitler Different Trainer forms for you!
https://forum.cheatengine.org/viewtopic.php?t=619279
Enthusiastic people: Always one step ahead
Do not underestimate me Master: You were a beginner in the past
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
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