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 


Pythagoras theorem in Lua Help

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
MikeNoey
How do I cheat?
Reputation: 0

Joined: 08 Jun 2018
Posts: 7

PostPosted: Fri Aug 10, 2018 1:24 am    Post subject: Pythagoras theorem in Lua Help Reply with quote

Hi guys. First of all I just want to admit that Math isn't my strong suit. I could use some help with this problem. Now I have the addresses for Z and X coordinates for my current location and the Z and X coordinates for the thing I have targeted in the game I'm playing and I want to be able to calculate the distance in meters between my own character and my target. I believe the way to do this is using Pythagoras Theorem.


local MyZCoords = ReadFloat("blablabla")
local MyXCoords = ReadFloat("blablabla")
local TargetZCoords = ReadFloat("blablabla")
local TargetXCoords = readFloat("blablabla")




If someone could help me fill in the part of the script involving the Pythagoras theorem I'd appreciate it. I meannnnn really appreciate it. Thanks in advance
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 357

Joined: 09 May 2003
Posts: 20894
Location: The netherlands

PostPosted: Fri Aug 10, 2018 2:37 am    Post subject: Reply with quote

Code:

(Target)
 |\
 | \
a|  \c
 |   \
 ------ (MyCoords)
   b

z
^
|
-->x


a=|TargetYCoords-MyYCoords|
b=|MyXCoords-TargetXCoords|
c=√(aČ+bČ)

In lua that'd be:
Code:

a=math.abs(TargetYCoords-MyYCoords) --abs is not really necessary but just to make things understandable)
b=math.abs(MyXCoords-TargetXCoords)
c=math.sqrt(a*a+b*b)

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.
Back to top
View user's profile Send private message MSN Messenger
Corroder
Grandmaster Cheater
Reputation: 17

Joined: 10 Apr 2015
Posts: 653

PostPosted: Fri Aug 10, 2018 6:13 am    Post subject: Reply with quote

into a function

Code:
function distanceFrom(x1,y1,x2,y2) return math.sqrt((x2 - x1) ^ 2 + (y2 - y1) ^ 2) end

_________________
Singapore Sling + Johnnie Walker + Some Peanuts....
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