View previous topic :: View next topic |
Author |
Message |
icsmoke+ Cheater Reputation: 0
Joined: 31 Aug 2020 Posts: 32
|
Posted: Mon Aug 23, 2021 9:59 pm Post subject: [Help] optimation script |
|
|
hello there,
i have script like bellow Code: |
b1 = ''
b1b = ''
bigK = ''
smallK = ''
n = ''
function integrated()
if mr('n1').getValue() == n and
tonumber(mr('b1').getValue()) == b1 and
tonumber(mr('b1').getValue()) == b1b and
tonumber(mr('k1').getValue()) > bigK and
tonumber(mr('k1').getValue()) < smallK
then
mr('p').setValue(mr('k1').getValue())
clickme()
elseif mr('n2').getValue() == n and
tonumber(mr('b2').getValue()) == b1 and
tonumber(mr('b2').getValue()) == b1b and
tonumber(mr('k2').getValue()) > bigK and
tonumber(mr('k2').getValue()) < smallK
then
mr('p').setValue(mr('k2').getValue())
clickme()
elseif mr('n3').getValue() == n and
tonumber(mr('b3').getValue()) == b1 and
tonumber(mr('b3').getValue()) == b1b and
tonumber(mr('k3').getValue()) > bigK and
tonumber(mr('k3').getValue()) < smallK
then
mr('p').setValue(mr('k3').getValue())
clickme()
elseif -------Have 25 else if
..........
end
end
|
can i use for do to my script? because i have 25 more elseif in it, then i put that function to another function that have timer on it.
any example script will be appreciate. thanks in advance
|
|
Back to top |
|
|
Birdi Expert Cheater Reputation: 0
Joined: 08 Jun 2020 Posts: 122 Location: Migrating
|
Posted: Mon Aug 23, 2021 10:20 pm Post subject: |
|
|
Code: |
for i=0,count do
local memrec = "n"..i+1 --n1, n2.. etc
If mr(memrec).getValue() == n
...
end
|
Concatenate a string with each iteration. You can also do the same for b and k.
Variable 'count' can be whatever number you need.
_________________
Trying to learn!
Add me on Discord if you want hands-on help: Birdi#0007 |
|
Back to top |
|
|
icsmoke+ Cheater Reputation: 0
Joined: 31 Aug 2020 Posts: 32
|
Posted: Mon Aug 23, 2021 10:36 pm Post subject: |
|
|
thank youuuu
upss sorry how about elseif? because the 1st one is if? and the n value is string?
|
|
Back to top |
|
|
Birdi Expert Cheater Reputation: 0
Joined: 08 Jun 2020 Posts: 122 Location: Migrating
|
Posted: Tue Aug 24, 2021 2:53 am Post subject: |
|
|
It covers every iteration from 0+1 to whatever end you set (counter).
It will do what you tell it to if the current iteration matches the condition, and will continue until that end or until you put a break to cancel the loop.
You can see how it works with a simpler For loop:
Code: |
for i=0,10 do
local myvar = "Number "..i
if i % 2 == 0 then
print(myvar.." is an even number.")
else
print(myvar.." is an odd number.")
end
end
|
This iterates from 0 to 10 and prints the even/odd state of the current iteration number.
In your example you're appending the current iteration number to the variables you want, so at first it'll be n1, b1 and k1. In the second iteration of the loop it'll be n2, b2 and k2, and so on until it reaches the end (counter in above post). You can insert a break anywhere, like in another if statement if you want, to cancel the loop earlier than at the end.
_________________
Trying to learn!
Add me on Discord if you want hands-on help: Birdi#0007 |
|
Back to top |
|
|
icsmoke+ Cheater Reputation: 0
Joined: 31 Aug 2020 Posts: 32
|
Posted: Tue Aug 24, 2021 5:40 pm Post subject: |
|
|
Thanks in advance, i'll figure it out, in my case the scrippt end up with error,even i use string format and other posibility
|
|
Back to top |
|
|
Birdi Expert Cheater Reputation: 0
Joined: 08 Jun 2020 Posts: 122 Location: Migrating
|
Posted: Tue Aug 24, 2021 6:20 pm Post subject: |
|
|
Maybe you didn't have the full script posted in the original post, but how is "mr" defined? It's not a function parameter so I can only assume you're pulling it from somewhere else? Also assuming that "mr('p')" is a specific address? Could mr(m) be another function to determine memory records? Being able to see the full situation would help me understand how to help you better.
Here's where I'm at:
Code: |
b1 = ''
b1b = ''
bigK = ''
smallK = ''
n = ''
function integrated()
local al = getAddressList() -- Store the entire table's address list
for i=0,al.Count-1 do -- Iterate through every memory record in the table
local mr = al[i] -- Store the current memory record by iteration as "mr"
local nC = "n"..i+1 -- nC = "n1" then "n2" then "n3", adding 1 for every iteration through each memrec
local bC = "b"..i+1 -- bC = ...
local kC = "k"..i+1 -- kC = ...
if mr(nC).getValue() == n and -- Your if check is what's confusing. What is >> mr(m)? As it is defined in this function it will not work.. what are you doing to get this?
tonumber(mr(bC).getValue()) == b1 and -- Why tonumber() on a value, when it should already be a number? Can the values be strings?
tonumber(mr(bC).getValue()) == b1b and -- ...
tonumber(mr(kC).getValue()) > bigK and -- ...
tonumber(mr(kC).getValue()) < smallK then -- ...
mr('p').setValue(mr(kC).getValue()) -- Again, how is mr('p') defined/useful? What memrec should this be setting..?
clickme() -- What is this external function call?
end
end
end
|
_________________
Trying to learn!
Add me on Discord if you want hands-on help: Birdi#0007 |
|
Back to top |
|
|
icsmoke+ Cheater Reputation: 0
Joined: 31 Aug 2020 Posts: 32
|
Posted: Wed Aug 25, 2021 12:52 am Post subject: |
|
|
ah sorry my bad
Code: |
al = getAddresslist
mr = al.getMemoryRecordByDescription()
b1 = '' --value get form editbox
b1b = '' --value get form editbox
bigK = '' --value get form editbox
smallK = '' --value get form editbox
n = '' --value get form editbox
--all address from table store with mr('address').getValue
function integrated()
if mr('n1').getValue() == n and --value from table (string value because its text
tonumber(mr('b1').getValue()) == b1 and --value from table (4bytes)
tonumber(mr('b1').getValue()) == b1b and -same as above
tonumber(mr('k1').getValue()) > bigK and -same as above
tonumber(mr('k1').getValue()) < smallK same as above
then
mr('p').setValue(mr('k1').getValue()) --set the a value when all conditionis true if not then next elseif
clickme()
elseif mr('n2').getValue() == n and
tonumber(mr('b2').getValue()) == b1 and
tonumber(mr('b2').getValue()) == b1b and
tonumber(mr('k2').getValue()) > bigK and
tonumber(mr('k2').getValue()) < smallK
then
mr('p').setValue(mr('k2').getValue())
clickme() --yes its external function
elseif mr('n3').getValue() == n and
tonumber(mr('b3').getValue()) == b1 and
tonumber(mr('b3').getValue()) == b1b and
tonumber(mr('k3').getValue()) > bigK and
tonumber(mr('k3').getValue()) < smallK
then
mr('p').setValue(mr('k3').getValue())
clickme() --yes its external function
elseif -------Have 25 else if
..........
end
end
|
that is the full function, and then i put that to another fuction that have loop, same like function integrated() with timer
|
|
Back to top |
|
|
Birdi Expert Cheater Reputation: 0
Joined: 08 Jun 2020 Posts: 122 Location: Migrating
|
Posted: Wed Aug 25, 2021 7:55 am Post subject: |
|
|
Sorry for the long wait, here you go:
Code: |
n = 45
b1 = 20
b1b = 20
bigK = 30
smallK = 50
_debug = false -- Change this to true if you want the debug prints
function integrated()
local al = getAddressList() -- Get Address List
for i=0,al.Count-1 do -- Iterate through the table's memrecs
local nC = 'n'..i+1 -- Local variable n1, n2, n3.. etc.
local bC = 'b'..i+1 -- Local variable b1, b2, b3.. etc.
local kC = 'k'..i+1 -- Local variable k1, k2, k3.. etc.
for g=0,al.Count-1 do -- Internal loop to set current memrecs
if al[g].Description == nC then -- If any memrec matches description of nC
nM = al[g] -- Set nM to host that memory record
end
if al[g].Description == bC then -- Same check for B
bM = al[g]
end
if al[g].Description == kC then -- and K...
kM = al[g]
end
if al[g].Description == 'p' then -- and P!
pM = al[g]
end
end -- End internal loop
if _debug == true then -- Check debug flag
print( -- Print a bunch of info per iteration of the main For loop
"\n\n\nN: "..n..
"\nB1: "..b1..
"\nB1B: "..b1b..
"\nBigK: "..bigK..
"\nSmallK: "..smallK..
"\n"..
"\nMemory Record: nM: "..
"\n Value: "..nM.Value..
"\n Description: "..nM.Description..
"\nMemory Record: bM: "..
"\n Value: "..bM.Value..
"\n Description: "..bM.Description..
"\nMemory Record: kM: "..
"\n Value: "..kM.Value..
"\n Description: "..kM.Description..
"\nMemory Record: pM: "..
"\n Value: "..pM.Value..
"\n Description: "..pM.Description
)
else -- Or just do what it's supposed to do
if tonumber(nM.Value) == tonumber(n) and -- if nM (n1, n2, etc..)'s value is = n
tonumber(bM.Value) == tonumber(b1) and -- and bM's value is = b1
tonumber(bM.Value) == tonumber(b1b) and -- ..and b1b
tonumber(kM.Value) > tonumber(bigK) and -- and kM's value is > bigK and < smallK
tonumber(kM.Value) < tonumber(smallK) then -- ...
if _debug == true then --debug print
print(" ~~~ Wow! ~~~ ")
end
pM.Value = kM.Value -- Set the value of pM to what the current kM iteration holds
--clickme() -- ClickMe?
end
end
end
end
|
The only messy part is where the memrecs get defined for use (nM, bM, kM).
For example, if you have n17 in your table but only up to b13 and k15, it will be out of sync and may not have the desired effect you want? Basically, it doesn't check if there's a "set" of them, but updates each as it finds them, up until the last one per letter.
I have no idea how you were using mr in your above script; it simply would not let me execute such a script... some error about indexing a userdata symbol.
_________________
Trying to learn!
Add me on Discord if you want hands-on help: Birdi#0007 |
|
Back to top |
|
|
icsmoke+ Cheater Reputation: 0
Joined: 31 Aug 2020 Posts: 32
|
Posted: Wed Aug 25, 2021 4:32 pm Post subject: |
|
|
Ok, last question, if i use al for getAddresslist i dont have to use mr=getMemoryByDescription to declare my address from table is that correct? Thanks in advance for your help.
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Wed Aug 25, 2021 4:55 pm Post subject: |
|
|
That is incorrect, the variable declared for the memory record (mr, doesn't have to be mr can be anything you want it to be, just something that the programmer (you) will know it is in reference to - The same with al).
al is used common because it's an abbreviation of addresslist, same for mr = memoryrecord.
You must declare a reference to the memory record you want to use. The same for any other object.
|
|
Back to top |
|
|
icsmoke+ Cheater Reputation: 0
Joined: 31 Aug 2020 Posts: 32
|
Posted: Wed Aug 25, 2021 5:13 pm Post subject: |
|
|
Oh i see that is why i use mr for
Local al=getAddresslist()
and local mr=al.getMemoryByDescription()
For variable mr('n'), mr('b') etc so i can easy to remember when i write the code
But then i a bit confused when i can see where is mr in birdi wrote. Than i suddenly learn that memrecs does the job
Thanks again to lefixer and birdi
|
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Wed Aug 25, 2021 5:15 pm Post subject: |
|
|
No problem if you're stuck with anything be sure to ask. There are many here willing to help.
|
|
Back to top |
|
|
Birdi Expert Cheater Reputation: 0
Joined: 08 Jun 2020 Posts: 122 Location: Migrating
|
Posted: Wed Aug 25, 2021 9:47 pm Post subject: |
|
|
I tried using what you had, and maybe it worked in older CE for some reason, but in 7.2 I could not use Code: | mr = al.getMemoryRecordByDescription() | in any capacity.. it would always throw an error, so I had to write it in a way that worked for me.
_________________
Trying to learn!
Add me on Discord if you want hands-on help: Birdi#0007 |
|
Back to top |
|
|
LeFiXER Grandmaster Cheater Supreme Reputation: 20
Joined: 02 Sep 2011 Posts: 1055 Location: 0x90
|
Posted: Thu Aug 26, 2021 4:10 am Post subject: |
|
|
I'm not sure what issue you're having but it works fine, see the image below.
|
|
Back to top |
|
|
icsmoke+ Cheater Reputation: 0
Joined: 31 Aug 2020 Posts: 32
|
Posted: Thu Aug 26, 2021 8:21 pm Post subject: |
|
|
I am using CE 7.2 and works fine to get value of the address, but when I tried with it failed me to get the value because its says attempt to index nil value, maybe because i dont know how to write the code correctly, pretty strange! on the other script that "for do" work perfect, here the example
Code: |
border= '' --Value get form editbox
function tBorder()
if mr('Border').getValue() == border then
for i=2, 24 do
mr('npc'..i).Value = '877400'
end
if mr('Border').getValue() == borderoff then
return
end
end
end
|
I new to lua, i didnt steal anyone script and use my own logic. I've been 3 days stuck and still get an error, i've change the script just because curiosity and try to learn LUA deeply by searching on Google, so at the end i used my old script, till get the correct answer. Thanks for your effort guys
|
|
Back to top |
|
|
|