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 


Scripting a value relocation

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

Joined: 08 May 2017
Posts: 7
Location: I don't exist... Unfortunately

PostPosted: Wed May 10, 2017 11:40 pm    Post subject: Scripting a value relocation Reply with quote

I want to make a hot key that takes a value from an address I found, let's call it pos a and paste it into pos b which is another base address. But, I have to perform the mathematical function of dividing pos a by 32 before inserting it into pos b. Anyone able to help? Edit: I also would like the script to have the capability to add 1to the value before it enters it, but after the mutiplication. So as in move (mousY/32)+1 -> transient y
_________________
Um... Hello... Thanks for taking the time to read my pointless signature Smile
Back to top
View user's profile Send private message
FreeER
Expert Cheater
Reputation: 6

Joined: 09 Aug 2013
Posts: 115

PostPosted: Thu May 11, 2017 8:09 am    Post subject: Reply with quote

As far as I know you'll need to use lua to do that, it's not too difficult though. Here's an example on step 4 of the tutorial https://www.dropbox.com/s/yramdbtztonitiu/copy%20value%20-%20Tutorial-i386.CT?dl=0

Though the lua code is this:

Code:
-- get the address list object
al = getAddressList()
-- get the memory records for the two values
health = al.getMemoryRecordByID(4)
ammo = al.getMemoryRecordByID(5)

-- create the hotkey
HealthToAmmoHK = createHotkey(function()
  -- get the value of health
  value = tonumber(health.Value)
  -- divide by 32 and add 1
  value = value/32 + 1
  -- store the value in ammo
  ammo.Value = tostring(value)
end,
-- set the hotkey combo to 1, VK codes can be found in defines.lua
-- which is in CE's install directory, probably %programfiles%\Cheat Engine 6.6
-- or %programfiles(x86)%\cheat engine 6.6
{VK_1})
Back to top
View user's profile Send private message
SadrienHatesU
How do I cheat?
Reputation: 0

Joined: 08 May 2017
Posts: 7
Location: I don't exist... Unfortunately

PostPosted: Thu May 11, 2017 6:42 pm    Post subject: Setting Hotkey function Reply with quote

What do I use in define.lua to set the hotkey function?

I have -

- get the address list object
al = getAddressList()
-- get the memory records for the two values
MouseY = al.getMemoryRecordByID(11)
YEdit = al.getMemoryRecordByID(5)

-- create the hotkey
ClickToTeleportHK = createHotkey(function()
-- get the value of Mouse
value = tonumber (MouseY)
-- divide by 32 and add 1
value = value/32 + 1
-- store the value in Y Position
YEdit = tostring(value)
end,
{VK_1})

Set up but I do not know what you mean by setting the hotkey combo? I see
VK_1 = 49
VK_2 = 50
VK_3 = 51
VK_4 = 52
VK_5 = 53
VK_6 = 54
VK_7 = 55
VK_8 = 56
VK_9 = 57

But When I set it to 112 ( which is f1) f1 does nothing.

The entire Table's Script is

-- code to find the hotkeys
al = getAddressList()
mr = al.getMemoryRecordByDescription("Gravity (Edit)")
-- get hotkeys, based on position in list aka index not ID (at least fairly sure it's index)
hk = mr.Hotkey[0]

-- set a function to run the second hotkey after the first has run
-- and the first key has been released
hk.onPostHotKey = function(sender)
timer = createTimer()
timer.Interval = 100 -- check every 100 milliseconds
timer.OnTimer = function(timer)
if not isKeyPressed(hk.keys[1]) then
sender.Owner.Hotkey[1].doHotkey()
timer.destroy()
end
end
end

-- get the address list object
al = getAddressList()
-- get the memory records for the two values
MouseY = al.getMemoryRecordByID(11)
YEdit = al.getMemoryRecordByID(5)

-- create the hotkey
ClickToTeleportHK = createHotkey(function()
-- get the value of Mouse
value = tonumber (MouseY)
-- divide by 32 and add 1
value = value/32 + 1
-- store the value in Y Position
YEdit = tostring(value)
end,
{VK_112})

and there are no errors when I run it. But there is a yellow bar by the createHotkey(function() which I do not know how to use.

_________________
Um... Hello... Thanks for taking the time to read my pointless signature Smile
Back to top
View user's profile Send private message
FreeER
Expert Cheater
Reputation: 6

Joined: 09 Aug 2013
Posts: 115

PostPosted: Thu May 11, 2017 7:09 pm    Post subject: Reply with quote

Quote:
-- get the value of Mouse
value = tonumber (MouseY)

should be
Code:
-- get the value of Mouse
value = tonumber (MouseY.Value)


MouseY is the memory record object with the address, type, etc. Same with YEdit when you assign the value

and it shouldn't be VK_112 but either 112 or VK_F1 (defines.lua is just creating variables so that you have slightly nicer names for things instead of random numbers like 49 and 112, if you can't guess what the variable name is from the mostly standard format, eg. VK_key or vk_keyname, then you can look at the names and try to figure out which is what you want, like VK_ENTER doesn't exist but VK_RETURN does for the carriage return key, some aren't very obvious like VK_PRIOR for page up but you can google them and/or look them up here https://msdn.microsoft.com/en-us/library/windows/desktop/dd375731%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396)
Back to top
View user's profile Send private message
SadrienHatesU
How do I cheat?
Reputation: 0

Joined: 08 May 2017
Posts: 7
Location: I don't exist... Unfortunately

PostPosted: Thu May 11, 2017 8:07 pm    Post subject: Reply with quote

-- get the address list object
al = getAddressList()
-- get the memory records for the two values
MouseY = al.getMemoryRecordByID(11)
TransientY = al.getMemoryRecordByID(5)

-- create the hotkey
ClickToTeleportHK = createHotkey(function()
-- get the value of Mouse
value = tonumber (MouseY.Value)
-- divide by 32 and add 1
value = value/32 + 1
-- store the value in Y Position
TransientY.Value = tostring(value)
end,
{112})

Results in an arithmetic on nil value (global "value") error on Line 31.
value = value/32 + 1
and
TransientY.Value = tostring(value)
are both invalid

What should I replace to make that part of the code function properly?
For some reason, it also runs when I press 4... Even once I deleted the script

_________________
Um... Hello... Thanks for taking the time to read my pointless signature Smile
Back to top
View user's profile Send private message
FreeER
Expert Cheater
Reputation: 6

Joined: 09 Aug 2013
Posts: 115

PostPosted: Thu May 11, 2017 9:05 pm    Post subject: Reply with quote

Hm... that doesn't make sense to me unless the value couldn't be converted to a number for some reason (and thus tonumber returned nil (equivalent to Javascript's undefined) for value)...

if you do just

Code:
-- get the address list object
al = getAddressList()
-- get the memory records for the two values
MouseY = al.getMemoryRecordByID(11)
print(MouseY) -- should be a table or userdata
print(MouseY.Value) -- should be the value
print(tonumber(MouseY.Value) == nil) -- should be false but...


Do you get the expected results printed?

as for
Quote:
For some reason, it also runs when I press 4... Even once I deleted the script
Unless you destroy the hotkey object CE will keep it active and still run it, that's why in the CT example it has HealthToAmmoHK.destroy() in the disable section (and I don't think the disable section is run if you delete the script before disabling it). Closing CE will destroy any objects so it won't exist when you reopen CE (you'd have to re-run the script), so it's really only an issue while creating the script Smile
Back to top
View user's profile Send private message
SadrienHatesU
How do I cheat?
Reputation: 0

Joined: 08 May 2017
Posts: 7
Location: I don't exist... Unfortunately

PostPosted: Thu May 11, 2017 10:34 pm    Post subject: Reply with quote

I think that the address is pulling from the wrong place because my sorting is not the same as what it uses for the address ID, how do I find the address ID on the table. I have been counting down but I dragged them around during development so the formatting is different. That is the only reason I can think of for what is happening because it is pulling from the 15th address down.

Either that or can we try and use the get function by name command instead of by ID? It triggered an error at line 22 which is right on it when I tried, saying unfinished string.

I think it is sorting them in a different way than my address list. Because that is the only way I can find that they match up with the printed addresses I get. Probably another thing I should already know but I don't.

Edit: NVM I FIGURED IT OUT

_________________
Um... Hello... Thanks for taking the time to read my pointless signature Smile
Back to top
View user's profile Send private message
FreeER
Expert Cheater
Reputation: 6

Joined: 09 Aug 2013
Posts: 115

PostPosted: Fri May 12, 2017 6:04 am    Post subject: Reply with quote

(For future reference and anyone else who finds this)
To find the id you can either open the cheat table in a text editor (make sure to save first) or use this plugin http://forum.cheatengine.org/viewtopic.php?t=602420

You can use getMemoryRecordByDescription to get it based on the name (and just getMemoryRecord for the position/index), but like the position that can be changed easily so the ID is probably the most reliable method if you share the cheat table or are prone to changing the format yourself.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine 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