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 


Assign a random value to an address from its dropdown list

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine
View previous topic :: View next topic  
Author Message
yoduk
Newbie cheater
Reputation: 0

Joined: 19 Jul 2014
Posts: 22

PostPosted: Sun Jan 14, 2018 11:14 am    Post subject: Assign a random value to an address from its dropdown list Reply with quote

Say I have an address with dropdown selection options 1, 100, 1000 and I want to assign the address one of those 3 values randomly. Is this possible?
Back to top
View user's profile Send private message
FreeER
Grandmaster Cheater Supreme
Reputation: 53

Joined: 09 Aug 2013
Posts: 1091

PostPosted: Sun Jan 14, 2018 1:43 pm    Post subject: Reply with quote

Should be with some lua code, give me a few minutes (~20 total lol) to play around

Code:
-- http://lua-users.org/wiki/SplitJoin
function split(str, sep)
   local sep, fields = sep or ":", {}
   local pattern = string.format("([^%s]+)", sep)
   str:gsub(pattern, function(c) fields[#fields+1] = c end)
   return fields
end

-- get first memrec
al = getAddressList()
mr = al.getMemoryRecord(0)

local random = math.random(mr.DropDownList.Count)-1
local value, name = unpack(split(mr.DropDownList[random], ':'))
mr.Value = value



so you could create a script and have it randomize anything below it like so:
Code:
{$lua}
[ENABLE]
function split(str, sep)
   local sep, fields = sep or ":", {}
   local pattern = string.format("([^%s]+)", sep)
   str:gsub(pattern, function(c) fields[#fields+1] = c end)
   return fields
end

if syntaxcheck then return end -- don't run rest if editing

-- memrec exists in CE6.7+
for i=0,memrec.Count-1 do
  local mr = memrec.Child[i]
  if mr.DropDownList.Count > 0 then
    local random = math.random(mr.DropDownList.Count)-1
    local value, name = unpack(split(mr.DropDownList[random], ':'))
    mr.Value = value
  end
end

-- autodisable this script
local t = createTimer()
t.Interval = 100
t.OnTimer = function(t)
  t.destroy()
  memrec.Active = false
end

[DISABLE]

And yes, it works with linked dropdown lists where instead of a list you use the name of another memory record with a dropdown list eg. (spellType)

edit: based on github it should be possible to simplify this a bit with mr.DropDownValue (so split wouldn't be needed) but in testing it doesn't work in CE 6.7
Back to top
View user's profile Send private message
yoduk
Newbie cheater
Reputation: 0

Joined: 19 Jul 2014
Posts: 22

PostPosted: Sun Jan 14, 2018 2:41 pm    Post subject: Reply with quote

This is exactly what I was looking for, thanks a ton!
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