View previous topic :: View next topic |
Author |
Message |
Frouk Grandmaster Cheater
Reputation: 5
Joined: 22 Jun 2021 Posts: 510
|
Posted: Sun Sep 04, 2022 10:17 am Post subject: __eq fails |
|
|
Code: | function PVehicle.__eq(a, b)
if type(b) == "number" then
return tonumber(a:Get()) == tonumber(getAddress(b))
end
return a:Get() == b:Get()
end
return VehicleArray.GetPlayerVehicle() == getAddress(addr) <- false
return PVehicle.__eq(VehicleArray.GetPlayerVehicle(), getAddress(addr)) <- true |
i can't understand why it fails giving me false |
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25791 Location: The netherlands
|
Posted: Sun Sep 04, 2022 11:32 am Post subject: |
|
|
__eq must be part of the metatable of the object GetPlayerVehicle() returns
in doubt, you can always print out info _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping
Last edited by Dark Byte on Sun Sep 04, 2022 11:34 am; edited 1 time in total |
|
Back to top |
|
 |
Frouk Grandmaster Cheater
Reputation: 5
Joined: 22 Jun 2021 Posts: 510
|
Posted: Sun Sep 04, 2022 11:33 am Post subject: |
|
|
function returns PVehicle class
maybe something wrong with constructor
Code: | function PVehicle:new(addr)
local o = {}
o.addr = getAddress(addr)
self.__index = self
setmetatable(o, self)
return o
end |
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25791 Location: The netherlands
|
Posted: Sun Sep 04, 2022 11:35 am Post subject: |
|
|
does self.__eq exist at that point? _________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
Frouk Grandmaster Cheater
Reputation: 5
Joined: 22 Jun 2021 Posts: 510
|
Posted: Sun Sep 04, 2022 11:39 am Post subject: |
|
|
Dark Byte wrote: | does self.__eq exist at that point? |
yeah |
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4702
|
Posted: Sun Sep 04, 2022 12:05 pm Post subject: |
|
|
May you provide a better example? Preferably an SSCCE
example:
Code: | local t = {}
function t.__eq(lhs, rhs)
return lhs.x == rhs.x
end
function t:new(x)
self.__index = self
return setmetatable({x = x}, self)
end
print(tostring(t:new(1) == t:new(1))) -- prints "true"
print(tostring(t:new(1) == t:new(2))) -- prints "false" | This works fine for me. _________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Frouk Grandmaster Cheater
Reputation: 5
Joined: 22 Jun 2021 Posts: 510
|
Posted: Sun Sep 04, 2022 12:13 pm Post subject: |
|
|
Code: | PVehicle = {}
VehicleArray = {}
function PVehicle:new(addr)
local o = {}
o.addr = getAddress(addr)
self.__index = self
setmetatable(o, self)
return o
end
function PVehicle.__eq(a, b)
if type(b) == "number" then
return tonumber(getAddress(a.addr)) == tonumber(getAddress(b))
end
return a:Get() == b:Get()
end
function PVehicle:Get()
return getAddress(self.addr)
end
function VehicleArray.GetArray()
local maxCount = readInteger(0xA9F158 + 0x8)
local currentCount = readInteger(0xA9F158 + 0xC)
local array = {}
for i = 0, currentCount - 1 do
array[i] = readPointer(0xA9F158 + 0x10 + i * 4)
end
return array
end
function VehicleArray.GetPVehicle(index)
local arr = VehicleArray.GetArray()
return PVehicle:new(arr[index] - 0xB8)
end
function VehicleArray.GetPlayerVehicle()
return VehicleArray.GetPVehicle(0)
end |
i'm trying to compare object instance to address which fails
Code: | --[[
output:
local player = VehicleArray.GetPlayerVehicle()
--[0xA9F168] - 0xB8
local player1 = PVehicle:new("[0xA9F168] - 0xB8")
return player == getAddress("[0xA9F168] - 0xB8")
1:false // fails
local player = VehicleArray.GetPlayerVehicle()
--[0xA9F168] - 0xB8
local player1 = PVehicle:new("[0xA9F168] - 0xB8")
return player == player1
1:true // ?
--]] |
|
|
Back to top |
|
 |
Dark Byte Site Admin
Reputation: 470
Joined: 09 May 2003 Posts: 25791 Location: The netherlands
|
Posted: Sun Sep 04, 2022 12:41 pm Post subject: |
|
|
try replacing
Code: |
return tonumber(getAddress(a.addr)) == tonumber(getAddress(b))
|
with
Code: |
print("b==number")
return a.addr == b
|
_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Like my help? Join me on Patreon so i can keep helping |
|
Back to top |
|
 |
ParkourPenguin I post too much
Reputation: 152
Joined: 06 Jul 2014 Posts: 4702
|
Posted: Sun Sep 04, 2022 12:55 pm Post subject: |
|
|
Oh, now I see it.
Lua 5.3 reference manual:
Quote: | __eq: the equal (==) operation. Behavior similar to the addition operation, except that Lua will try a metamethod only when the values being compared are either both tables or both full userdata and they are not primitively equal. The result of the call is always converted to a boolean. | (added emphasis is mine)
So you can't use __eq to compare a table with an integer (getAddress returns an integer). _________________
I don't know where I'm going, but I'll figure it out when I get there. |
|
Back to top |
|
 |
Frouk Grandmaster Cheater
Reputation: 5
Joined: 22 Jun 2021 Posts: 510
|
Posted: Sun Sep 04, 2022 12:56 pm Post subject: |
|
|
^^^
edit:
well, can't seem do anything with this
edit 2:
i need to create function that compares the address |
|
Back to top |
|
 |
|