--[[ // Do not delete this comment block, respect others work! # CAN BE USED AS MODULE OR EXTENTION (extention for yourself of course, but if you will make table, functions won't apply into table) # Author: Frouk --]] Vector = {} Vector2D = {} function Vector.new(x, y, z) return setmetatable({x = x or 0, y = y or 0, z = z or 0},Vector) end function Vector.__add(a, b) return Vector.new(a.x + b.x, a.y + b.y, a.z + b.z) end function Vector.__sub(a, b) return Vector.new(a.x - b.x, a.y - b.y, a.z - b.z) end function Vector2D.new(x, y) return setmetatable({x = x or 0, y = y or 0},Vector) end function Vector2D.__add(a, b) return Vector2D.new(a.x + b.x, a.y + b.y) end function Vector2D.__sub(a, b) return Vector2D.new(a.x - b.x, a.y - b.y) end function writeBoolean(address,bool) address = getAddress(address) if address == nil or address == 0 or bool == nil then return nil --address is not valid or bool isn't declarated end if type(bool) == "number" then return false --we have number instead of boolean, so we won't write end return writeByte(address,bool and 1 or 0) end function readBoolean(address) address = getAddress(address) if address == nil or address == 0 then return nil --address is not valid end return readByte(address) == 1 end writeBool = writeBoolean readBool = readBoolean function writeVector(address,vector,isDouble,is2D) address = getAddress(address) if address == nil or address == 0 then return nil --address is not valid end if type(vector) ~= "table" then return false --vector isn't table end if vector.x == nil and vector.y == nil then return false --we don't have x and y end local success = false local offset = Vector.new(0x0, isDouble and 0x8 or 0x4, isDouble and 0x10 or 0x8) local writeVec = isDouble and writeDouble or writeFloat success = writeVec(address+offset.x,vector.x) and writeVec(address+offset.y,vector.y) if not is2D then success = success and writeVec(address+offset.z,vector.z) end return success --we need to know if writing vector will return true, otherwise it will return false end function readVector(address,isDouble,is2D) address = getAddress(address) if address == nil or address == 0 then return nil --address is not valid end local offset = Vector.new(0x0, isDouble and 0x8 or 0x4, isDouble and 0x10 or 0x8) local readVec = isDouble and readDouble or readFloat local result = Vector.new(readVec(address + offset.x), readVec(address + offset.y), readVec(address + offset.z)) if is2D then result = Vector2D.new(readVec(address + offset.x), readVec(address + offset.y)) end return result --returning a table that contains x,y,z , otherwise function will return nil end setmetatable(Vector, { __call = function(_, ...) return Vector.new(...) end}) setmetatable(Vector2D, { __call = function(_, ...) return Vector2D.new(...) end})