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 


Working with Strings query

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
MikeNoey
Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 35

PostPosted: Tue Dec 18, 2018 3:00 am    Post subject: Working with Strings query Reply with quote

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
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 17

Joined: 01 Feb 2016
Posts: 1480

PostPosted: Tue Dec 18, 2018 4:23 am    Post subject: Reply with quote

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!
patched cheat engine tutorials


Last edited by OldCheatEngineUser on Tue Dec 18, 2018 5:57 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
MikeNoey
Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 35

PostPosted: Tue Dec 18, 2018 4:33 am    Post subject: Reply with quote

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
View user's profile Send private message
OldCheatEngineUser
Whateven rank
Reputation: 17

Joined: 01 Feb 2016
Posts: 1480

PostPosted: Tue Dec 18, 2018 6:00 am    Post subject: Reply with quote

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!
patched cheat engine tutorials
Back to top
View user's profile Send private message Visit poster's website
MikeNoey
Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 35

PostPosted: Tue Dec 18, 2018 6:45 am    Post subject: Reply with quote

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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 68

Joined: 06 Jul 2014
Posts: 2238

PostPosted: Tue Dec 18, 2018 9:43 am    Post subject: Reply with quote

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
View user's profile Send private message
MikeNoey
Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 35

PostPosted: Mon May 27, 2019 7:23 am    Post subject: Reply with quote

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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 68

Joined: 06 Jul 2014
Posts: 2238

PostPosted: Mon May 27, 2019 8:51 am    Post subject: Reply with quote

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
View user's profile Send private message
MikeNoey
Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 35

PostPosted: Tue May 28, 2019 2:32 am    Post subject: Reply with quote

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
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 28

Joined: 13 Sep 2011
Posts: 1456

PostPosted: Tue May 28, 2019 4:54 am    Post subject: Reply with quote

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.

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
Back to top
View user's profile Send private message
MikeNoey
Cheater
Reputation: 0

Joined: 08 Jun 2018
Posts: 35

PostPosted: Tue May 28, 2019 8:49 am    Post subject: Reply with quote

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
View user's profile Send private message
ParkourPenguin
I post too much
Reputation: 68

Joined: 06 Jul 2014
Posts: 2238

PostPosted: Tue May 28, 2019 8:55 am    Post subject: Reply with quote

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
View user's profile Send private message
DaSpamer
Grandmaster Cheater Supreme
Reputation: 28

Joined: 13 Sep 2011
Posts: 1456

PostPosted: Tue May 28, 2019 11:32 am    Post subject: Reply with quote

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

_________________
HEY Hitler
Do you get lazy when making trainers?
Well no more!
My CETrainer will generate it for you in seconds, so you won't get lazy! Very Happy

http://forum.cheatengine.org/viewtopic.php?t=564919
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 Lua Scripting 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