|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
Razi Expert Cheater Reputation: 1
Joined: 17 Jan 2018 Posts: 202
|
Posted: Sun Mar 17, 2019 3:33 am Post subject: How to find out the sum of values and improve the code? |
|
|
How to find out the sum of values and improve the code? Character can equip 15 items with 6 stats parameters. The following code works, but it is too big.
Code: | s1 = matefftable[eqmattable[readBytes(0x009E8664+0*4)]][1]
s2 = matefftable[eqmattable[readBytes(0x009E8664+1*4)]][1]
s3 = matefftable[eqmattable[readBytes(0x009E8664+2*4)]][1]
...
s15 = matefftable[eqmattable[readBytes(0x009E8664+14*4)]][1]
UDF1['CELabel'..73].Caption = s1 + s2 + s3 + s4 + s5 + s6 + s7 + s8 +
s9 + s10 + s11 + s12 + s13 + s14 + s15
m1 = matefftable[eqmattable[readBytes(0x009E8664+0*4)]][2]
m2 = matefftable[eqmattable[readBytes(0x009E8664+1*4)]][2]
...
m14 = matefftable[eqmattable[readBytes(0x009E8664+13*4)]][2]
m15 = matefftable[eqmattable[readBytes(0x009E8664+14*4)]][2]
UDF1['CELabel'..74].Caption = m1 + m2 + m3 + m4 + m5 + m6 + m7 + m8 +
m9 + m10 + m11 + m12 + m13 + m14 + m15
v1 = matefftable[eqmattable[readBytes(0x009E8664+0*4)]][3]
v2 = matefftable[eqmattable[readBytes(0x009E8664+1*4)]][3]
...
v15 = matefftable[eqmattable[readBytes(0x009E8664+14*4)]][3]
UDF1['CELabel'..75].Caption = v1 + v2 + v3 + v4 + v5 + v6 + v7 + v8 +
v9 + v10 + v11 + v12 + v13 + v14 + v15
p1 = matefftable[eqmattable[readBytes(0x009E8664+0*4)]][4]
p2 = matefftable[eqmattable[readBytes(0x009E8664+1*4)]][4]
...
p15 = matefftable[eqmattable[readBytes(0x009E8664+14*4)]][4]
UDF1['CELabel'..76].Caption = p1 + p2 + p3 + p4 + p5 + p6 + p7 + p8 +
p9 + p10 + p11 + p12 + p13 + p14 + p15
d1 = matefftable[eqmattable[readBytes(0x009E8664+0*4)]][5]
...
d15 = matefftable[eqmattable[readBytes(0x009E8664+14*4)]][5]
UDF1['CELabel'..77].Caption = d1 + d2 + d3 + d4 + d5 + d6 + d7 + d8 +
d9 + d10 + d11 + d12 + d13 + d14 + d15
k1 = matefftable[eqmattable[readBytes(0x009E8664+0*4)]][6]
...
k15 = matefftable[eqmattable[readBytes(0x009E8664+14*4)]][6]
UDF1['CELabel'..78].Caption = k1 + k2 + k3 + k4 + k5 + k6 + k7 + k8 +
k9 + k10 + k11 + k12 + k13 + k14 + k15 |
Is it possible to shorten this code?
Or how to put sum of the values in label in the following code:
Code: | for x = 0, 2 do
m1 = mateff[equippmattbl[readBytes(0x009E8664+x*4)]][1]
UDF1['CELabel'..61].Caption = | The result is 4, 1, 1 , but I need to put the sum of these values (4+1+1=6) in the UDF1['CELabel'..61] . How to do this?
Last edited by Razi on Mon Mar 18, 2019 3:05 pm; edited 1 time in total |
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Sun Mar 17, 2019 6:58 pm Post subject: |
|
|
Anything you call more than once can be placed inside a function,
You could place matefftable[...] inside a function and only supply readbytes address.
Code: | function getV(rb,index)
return matefftable[eqmattable[readBytes(rb)]][index or 1]
end
S1 = getV(0x009E8664)
|
And since you hold 16 variables and offsets are pretty much static you could do
Code: | s={} -- similar to var names but you access it via table s[1],s[2]...s[15]
sum = 0
for i=0,14 do
local v = getV(0x009E8664+i*4)
s[i+1]= v
-- _G['s'..tostring(i+1)] = v -- a dirty way to set global variables ... s1,s2....s15 like in your example... better use tables as it much better than accessing global scope.
sum = sum + v
end
labelName = sum
|
Hope it helps, used phone so its not so clean but gives you the idea
_________________
|
|
Back to top |
|
|
Razi Expert Cheater Reputation: 1
Joined: 17 Jan 2018 Posts: 202
|
Posted: Mon Mar 18, 2019 3:07 pm Post subject: |
|
|
Thank you, these are helpful tips.
|
|
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
|
|