View previous topic :: View next topic |
Author |
Message |
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Tue Dec 18, 2018 3:00 am Post subject: Working with Strings query |
|
|
Hi guys, I have a new idea for a script I want to write that involves a String address. In this game most enemy characters use the same attack skills and most of those skills inflict ailments that must be removed by using potions. I found a String Address that displays the latest Attack skill used on you but the problem is they aren't unique. I want to ask if there is a way to bypass this. For example
Raptor Shaman used Poison Shot
Goblin used Poison Shot
What im asking is can the names of the enemies be ignored so just the name of the skill remains. That way I can make the right potions activate from the corresponding skill used.
|
|
Back to top |
|
|
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1587
|
Posted: Tue Dec 18, 2018 4:23 am Post subject: |
|
|
parse it, until you find "used". (since "used" is not going to change)
_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
Last edited by OldCheatEngineUser on Tue Dec 18, 2018 5:57 am; edited 1 time in total |
|
Back to top |
|
|
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Tue Dec 18, 2018 4:33 am Post subject: |
|
|
Thank you. Do you or anyone else mind posting an example of parsing in Lua or a link to a page with that information. Would much appreciate it
|
|
Back to top |
|
|
OldCheatEngineUser Whateven rank Reputation: 20
Joined: 01 Feb 2016 Posts: 1587
|
Posted: Tue Dec 18, 2018 6:00 am Post subject: |
|
|
OldCheatEngineUser wrote: | parse it, until you find "used". (since "used" is not going to change) |
and then get the text after "used"
i dont know lua, only assembly.
some users here can provide examples, or even write a full code.
_________________
About Me;
I Use CE Since Version 1.X, And Still Learning How To Use It Well!
Jul 26, 2020
STN wrote: | i am a sweetheart. |
|
|
Back to top |
|
|
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Tue Dec 18, 2018 6:45 am Post subject: |
|
|
I believe I've found what I need courtesy of Dr.Disrespect and his code
words = {}
s = "This is a string"
for w in string.gmatch(s, "%a+") do
words[#words+1] = w
end
print(words[1])
print(words[2])
print(words[3])
print(words[4])
out will be:
This
is
a
string
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4289
|
Posted: Tue Dec 18, 2018 9:43 am Post subject: |
|
|
Alternatively:
Code: | local s = 'sdnke awerng used woker abeiutkn eij'
print(s:match'^.- used (.+)$') |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Mon May 27, 2019 7:23 am Post subject: |
|
|
Thanks for the alternative Parkour. I was wondering if you could tell me how to adjust that code.
I know that by removing "^.-" that everything before used gets printed but i'm wondering how I can skip a word. For example I want to print "woker eij" and skip "abeiutkn"
Also if possible the code has to be written so that I don't know what the 2nd word is. It could be any word. What matters is that the print result is the 1st and 3rd words after "used"
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4289
|
Posted: Mon May 27, 2019 8:51 am Post subject: |
|
|
Look up how pattern matching works in Lua.
https://www.lua.org/manual/5.3/manual.html#6.4.1
Code: | local s = 'sdnke awerng used woker abeiutkn eij'
print(s:match'^.- used%s+([^%s]+)%s+[^%s]+%s+([^%s]+)') |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Tue May 28, 2019 2:32 am Post subject: |
|
|
I'll take a look at that this weekend. Thanks Parkour. The example you gave me worked great but if I try and do it this way it doesn't work so well.
local s = 'sdnke awerng used woker abeiutkn eij'
local PrintIt = (s:match'^.- awerng%s+([^%s]+)%s+[^%s]+%s+([^%s]+)')
print(PrintIt)
It only prints the word after awerng "used" and not "abeiutkn".
|
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Tue May 28, 2019 4:54 am Post subject: |
|
|
Since you really care about the end of the line, you could just remove everything until you encounter 'used' keyword.
like this:
Code: | local s = 'Someone With A Name used a potion';
print((s:gsub('.-used (.-)$','%1'))) -- a potion
local s = 'goblin used a potion';
print((s:gsub('.-used (.-)$','%1'))) -- a potion
local s = 'used a potion';
print((s:gsub('.-used (.-)$','%1'))) -- a potion |
the (.-) captures anything after used (note there is space after used as we want also the space between used and next word/letter, if there is more than a single space you could also use %s+);
%1 is our captured string, so we basically replace the whole string the string after used keyword.
_________________
|
|
Back to top |
|
|
MikeNoey Advanced Cheater Reputation: 0
Joined: 08 Jun 2018 Posts: 64
|
Posted: Tue May 28, 2019 8:49 am Post subject: |
|
|
Thanks @ DaSpammer. I just tried your method and the explanations you added helped too.
Could you take a look at the post I made above yours ? I have a new problem I'm trying to figure out that you could help me with.
|
|
Back to top |
|
|
ParkourPenguin I post too much Reputation: 140
Joined: 06 Jul 2014 Posts: 4289
|
Posted: Tue May 28, 2019 8:55 am Post subject: |
|
|
There are two captures in the pattern (i.e. subpatterns surrounded by parenthesis), so match will return two values if it succeeds.
Code: | local s = 'sdnke awerng used woker abeiutkn eij'
local word1, word3 = s:match'^.- used%s+([^%s]+)%s+[^%s]+%s+([^%s]+)'
print(word1, word3) |
Also, if you put parenthesis around something that gives more than one value, it will only return one value.
Code: | function foo() return 1,2 end
print(foo()) -- prints 1 2
print((foo())) -- prints 1 |
_________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
|
DaSpamer Grandmaster Cheater Supreme Reputation: 52
Joined: 13 Sep 2011 Posts: 1578
|
Posted: Tue May 28, 2019 11:32 am Post subject: |
|
|
One way to capture all matches at once
Code: | function findMatch(s,pattern) -- small recuirsive function;
local function subroutine (routine)
local newMatch = routine();
if (newMatch) then
return newMatch,subroutine(routine);
end;
end
return subroutine(s:gfind(pattern)); -- returns all words;
end
local s = ('Someone With A Name used a potion with while shooting bikers and killing innocent people ran'):gsub('.-used (.-)$','%1'); -- strip down string;
words = {findMatch(s,'%a+')}; -- capture all words (all alphanumeric characters), and save in table.
-- word1,word2,word3,word4,word5,word6 = findMatch(s,'%a+'); -- captures only 6 words out of 11 actually
|
Now about your question to filter words, you could use gfind and check against a table if word should be skipped.
Example:
Code: | local s = 'Someone With A Name used a potion with while shooting bikers and killing innocent people ran';
s = s:gsub('.-used (.-)$','%1'); -- strip down everything before including used
-- set up badWords table and our words table;
badWords = {['killing']=true; ['shooting']=true;};
words = {}; -- you could also populate words table like this
for word in s:gfind('%a+') do
if (not badWords[word]) then -- if word does not exist in our badWords table
table.insert(words,word);
end
end
print('total words:',#words);
for index,word in pairs(words) do
print('id:',index,'\t word:',word);
end |
which would output this
Code: | total words: 9 -- 9 words out of 11;
id: 1 word: a
id: 2 word: potion
id: 3 word: with
id: 4 word: while
id: 5 word: bikers
id: 6 word: and
id: 7 word: innocent
id: 8 word: people
id: 9 word: ran |
_________________
|
|
Back to top |
|
|
|