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 


Something related with directions

 
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 May 09, 2022 12:02 pm    Post subject: Something related with directions Reply with quote

Vectors
Code:
--[[
Use as api in your table or lua extension to make work easier with vectors

Made by Frouk
--]]

Vector = {}
Vector.__index = Vector

Vector2D = {}
Vector2D.__index = Vector2D

function Vector.new(x, y, z)
  return setmetatable({x = x or 0,  y = y or 0, z = z or 0},Vector)
end

function Vector2D.new(x, y, z)
  return setmetatable({x = x or 0, y = y or 0},Vector2D)
end

function Vector.__add(a, b)
  if type(a) == "number" then
    return Vector.new(b.x + a, b.y + a, b.z + a)
  elseif type(b) == "number" then
    return Vector.new(a.x + b, a.y + b, a.z + b)
  end
  return Vector.new(a.x + b.x, a.y + b.y, a.z + b.z)
end

function Vector.__sub(a, b)
  if type(a) == "number" then
    return Vector.new(b.x - a, b.y - a, b.z - a)
  elseif type(b) == "number" then
    return Vector.new(a.x - b, a.y - b, a.z - b)
  end
  return Vector.new(a.x - b.x, a.y - b.y, a.z - b.z)
end

function Vector.__mul(a, b)
  if type(a) == "number" then
    return Vector.new(b.x * a, b.y * a, b.z * a)
  elseif type(b) == "number" then
    return Vector.new(a.x * b, a.y * b, a.z * b)
  end
  return Vector.new(a.x * b.x, a.y * b.y, a.z * b.z)
end

function Vector.__div(a, b)
  if type(a) == "number" then
    return Vector.new(b.x / a, b.y / a, b.z / a)
  elseif type(b) == "number" then
    return Vector.new(a.x / b, a.y / b, a.z / b)
  end
  return Vector.new(a.x / b.x, a.y / b.y, a.z / b.z)
end

function Vector.__mod(a, b)
  if type(a) == "number" then
    return Vector.new(b.x % a, b.y % a, b.z % a)
  elseif type(b) == "number" then
    return Vector.new(a.x % b, a.y % b, a.z % b)
  end
  return Vector.new(a.x % b.x, a.y % b.y, a.z % b.z)
end

function Vector.__eq(a, b)
  if type(a) == "number" then
    return b.x == a and b.y == a and b.z == a
  elseif type(b) == "number" then
    return a.x == b and a.y == b and a.z == b
  end
  return a.x == b.x and a.y == b.y and a.z == b.z
end

function Vector.__unm(a)
  return Vector.new(-a.x, -a.y, -a.z)
end

function Vector.__lt(a, b)
  if type(a) == "number" then
    return b.x < a and b.y < a and b.z < a
  elseif type(b) == "number" then
    return a.x < b and a.y < b and a.z < b
  end
  return a.x < b.x and a.y < b.y and a.z < b.z
end

function Vector.__le(a, b)
  if type(a) == "number" then
    return b.x <= a and b.y <= a and b.z <= a
  elseif type(b) == "number" then
    return a.x <= b and a.y <= b and a.z <= b
  end
  return a.x <= b.x and a.y <= b.y and a.z <= b.z
end

function Vector.distance(a, b)
  return math.sqrt((a.x - b.x)^2 + (a.y + b.y)^2 + (a.z + b.z)^2)
end

function Vector:unpack()
  return self.x, self.y, self.z
end

function Vector:clone()
  return Vector.new(self.x, self.y, self.z)
end

function Vector:Magnitude()
  return math.sqrt(self.x * self.x + self.y * self.y + self.z * self.z)
end

function Vector:Normalize()
  return self / self:Magnitude()
end

function Vector2D.__add(a, b)
  if type(a) == "number" then
    return Vector2D.new(b.x + a, b.y + a)
  elseif type(b) == "number" then
    return Vector2D.new(a.x + b, a.y + b)
  end
  return Vector2D.new(a.x + b.x, a.y + b.y)
end

function Vector2D.__sub(a, b)
  if type(a) == "number" then
    return Vector2D.new(b.x - a, b.y - a)
  elseif type(b) == "number" then
    return Vector2D.new(a.x - b, a.y - b)
  end
  return Vector2D.new(a.x - b.x, a.y - b.y)
end

function Vector2D.__mul(a, b)
  if type(a) == "number" then
    return Vector2D.new(b.x * a, b.y * a)
  elseif type(b) == "number" then
    return Vector2D.new(a.x * b, a.y * b)
  end
  return Vector2D.new(a.x * b.x, a.y * b.y)
end

function Vector2D.__div(a, b)
  if type(a) == "number" then
    return Vector2D.new(b.x / a, b.y / a)
  elseif type(b) == "number" then
    return Vector2D.new(a.x / b, a.y / b)
  end
  return Vector2D.new(a.x / b.x, a.y / b.y)
end

function Vector2D.__mod(a, b)
  if type(a) == "number" then
    return Vector2D.new(b.x % a, b.y % a)
  elseif type(b) == "number" then
    return Vector2D.new(a.x % b, a.y % b)
  end
  return Vector2D.new(a.x % b.x, a.y % b.y)
end

function Vector2D.__eq(a, b)
  if type(a) == "number" then
    return b.x == a and b.y == a
  elseif type(b) == "number" then
    return a.x == b and a.y == b
  end
  return a.x == b.x and a.y == b.y
end

function Vector2D.__unm(a)
  return Vector2D.new(-a.x, -a.y)
end

function Vector2D.__lt(a, b)
  if type(a) == "number" then
    return b.x < a and b.y < a
  elseif type(b) == "number" then
    return a.x < b and a.y < b
  end
  return a.x < b.x and a.y < b.y
end

function Vector2D.__le(a, b)
  if type(a) == "number" then
    return b.x <= a and b.y <= a
  elseif type(b) == "number" then
    return a.x <= b and a.y <= b
  end
  return a.x <= b.x and a.y <= b.y
end

function Vector2D.distance(a, b)
  return math.sqrt((a.x - b.x)^2 + (a.y + b.y)^2)
end

function Vector2D:unpack()
  return self.x, self.y
end

function Vector2D:clone()
  return Vector2D.new(self.x, self.y)
end

function Vector2D:Magnitude()
  return math.sqrt(self.x * self.x + self.y * self.y)
end

function Vector2D:Normalize()
  return self / self:Magnitude()
end

setmetatable(Vector, { __call = function(_, ...) return Vector.new(...) end})
setmetatable(Vector2D, { __call = function(_, ...) return Vector2D.new(...) end})


i think you can use it, whenever you don't delete comment block

_________________
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