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 


if string == then

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

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Mon Aug 23, 2021 4:01 am    Post subject: if string == then Reply with quote

I wanted to make a function with table were
Code:
if string == powerupname then

But when i type string, writeInteger applies for all powerup amount

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Mon Aug 23, 2021 4:09 am    Post subject: Reply with quote

You have to elaborate a little more. It's a little vague what it is you're exactly asking.
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Mon Aug 23, 2021 4:16 am    Post subject: Reply with quote

LeFiXER wrote:
You have to elaborate a little more. It's a little vague what it is you're exactly asking.

The table is
Code:
PowerupItems = {
Brocoli='+0x0',
Dumbell='+0x4',
Jetpack='+0x8',
OJ='+0xC',
PB='+0x10',
BP='+0x14',
RP='+0x18',
Sneaker='+0x1C',
RHH='+0x20',
SB='+0x24',
Bulldozer='+0x28',
Horseshoe='+0x2C',
DM='+0x30',
Piggybank='+0x34',
CD='+0x38',
Dracula='+0x3C',
JF='+0x40',
Juice='+0x44',
Adrenaline='+0x48',
Berserk='+0x4C',
CS='+0x50',
SS='+0x54',
KH='+0x58',
WOG='+0x5C',
Enforcer='+0x60',
}

Which includes all powerup name and offsets
Code:
PowerupItem = '[PowerInventory + 0x18] + 0x20' --Base address to table


I setted function:
Code:
setPowerupAmount(id,number)
for i,v in pairs(PowerupItems) do
if tostring(id) == tostring(i) then
writeInteger(PowerupItem+v,number)
else
print(i)
end
end
end
[/code]
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Birdi
Expert Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 122
Location: Migrating

PostPosted: Mon Aug 23, 2021 4:48 am    Post subject: Reply with quote

What exactly is the error? It's applying the number to all of the powerups, instead of the one denoted by id?
_________________
Trying to learn!

Add me on Discord if you want hands-on help: Birdi#0007
Back to top
View user's profile Send private message Visit poster's website
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Mon Aug 23, 2021 4:55 am    Post subject: Reply with quote

Birdi wrote:
What exactly is the error? It's applying the number to all of the powerups, instead of the one denoted by id?

Yeah

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Birdi
Expert Cheater
Reputation: 0

Joined: 08 Jun 2020
Posts: 122
Location: Migrating

PostPosted: Mon Aug 23, 2021 4:57 am    Post subject: Reply with quote

Can't really see an issue, try properly debugging it:

Code:

function setPowerupAmount(id,number)
  for i,v in pairs(PowerupItems) do
    if tostring(id) == tostring(i) then
      writeInteger(PowerupItem+v,number)
      print("Called ID: "..id.."\nRequested Number: "..number.."\nKey: "..i.."\nValue: "..v.."\n\nPowerupItem: "..PowerupItem)
    end
  end
end

setPowerupAmount('Juice',1) --Even with tostring(id) you need to call the key as a string

_________________
Trying to learn!

Add me on Discord if you want hands-on help: Birdi#0007
Back to top
View user's profile Send private message Visit poster's website
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Mon Aug 23, 2021 5:19 am    Post subject: Reply with quote

This is the correct syntax for a table with keys/values

Code:

PowerupItems = {
["Brocolli"] = "+0x0",
["Dumbell"] = "+0x4",
["Jetpack"] = "+0x8",
}


You can access the table by its key name like so

Code:

tablename["keyname"]


Code:

function findInTable(itemToFind)
    for k,v in pairs(PowerupItems) do
     if k == itemToFind then
        print("I found " .. k .. " and its value is " .. v)
     end
    end
end

findInTable("Jetpack")
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Mon Aug 23, 2021 5:26 am    Post subject: Reply with quote

Birdi wrote:
Can't really see an issue, try properly debugging it:

Code:

function setPowerupAmount(id,number)
  for i,v in pairs(PowerupItems) do
    if tostring(id) == tostring(i) then
      writeInteger(PowerupItem+v,number)
      print("Called ID: "..id.."\nRequested Number: "..number.."\nKey: "..i.."\nValue: "..v.."\n\nPowerupItem: "..PowerupItem)
    end
  end
end

setPowerupAmount('Juice',1) --Even with tostring(id) you need to call the key as a string


thx my mistake was that i'm wasn't correctly calling a function

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
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