09-10-2018, 06:33 AM
Since nobody is answering me, I decided to make an extra class for the GetSpeed() function that stores the current position and the position a second ago. So, for everyone having the same problem as me; here is the class.
and the 'class()' (skidded from here)
require "classes.class" rawPlayer = class( function(self, uuid, currPosX, currPosY, currPosZ) self.uuid = uuid self.currPosX = currPosX self.currPosY = currPosY self.currPosZ = currPosZ self.lastTime = os.clock() end ) function rawPlayer:setPos(posX, posY, posZ) if lastTime < os.clock then self.lastPosX = self.currPosX self.lastPosY = self.currPosY self.lastPosZ = self.currPosZ self.currPosX = posX self.currPosY = posY self.currPosZ = posZ end end function rawPlayer:GetSpeedX() speedX = self.currPosX - self.lastPosX if speedX < 0 then speedX = speedX * (-1) end return speedX end function rawPlayer:GetSpeedY() speedY = self.currPosY - self.lastPosY if speedY < 0 then speedY = speedY * (-1) end return speedY end function rawPlayer:GetSpeedZ() speedZ = self.currPosZ - self.lastPosZ if speedZ < 0 then speedZ = speedZ * (-1) end return speedZ end
and the 'class()' (skidded from here)
-- class.lua -- Compatible with Lua 5.1 (not 5.0). function class(base, init) local c = {} -- a new class instance if not init and type(base) == "function" then init = base base = nil elseif type(base) == "table" then -- our new class is a shallow copy of the base class! for i,v in pairs(base) do c[i] = v end c._base = base end -- the class will be the metatable for all its objects, -- and they will look up their methods in it. c.__index = c -- expose a constructor which can be called by <classname>(<args>) local mt = {} mt.__call = function(class_tbl, ...) local obj = {} setmetatable(obj,c) if init then init(obj,...) else -- make sure that any stuff from the base class is initialized! if base and base.init then base.init(obj, ...) end end return obj end c.init = init c.is_a = function(self, klass) local m = getmetatable(self) while m do if m == klass then return true end m = m._base end return false end setmetatable(c, mt) return c end