Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- #######################################
- -- ## Project: Playersync INACTIVE ##
- -- ## Name: Playersync.lua ##
- -- ## Author: Noneatme ##
- -- ## Version: 1.0 ##
- -- ## License: See top Folder ##
- -- #######################################
- -- FUNCTIONS / METHODS --
- local cFunc = {}; -- Local Functions
- local cSetting = {}; -- Local Settings
- Playersync = {};
- Playersync.__index = Playersync;
- --[[
- Playersync 2 - Stellt die Sycronisierung auf dem Server dar
- ]]
- -- ///////////////////////////////
- -- ///// New //////
- -- ///// Returns: Object //////
- -- ///////////////////////////////
- function Playersync:New(...)
- local obj = setmetatable({}, {__index = self});
- if obj.Constructor then
- obj:Constructor(...);
- end
- return obj;
- end
- -- ///////////////////////////////
- -- ///// CheckPlayerPeds //////
- -- ///// Returns: void //////
- -- ///////////////////////////////
- function Playersync:CheckPlayerPed(serial, row)
- if not(self.playerPeds[serial]) then
- self.playerPeds[serial] = createPed(60, 0, 0, 0);
- end
- local ped = self.playerPeds[serial];
- setElementInterior(ped, tonumber(row['Interior']));
- setElementDimension(ped, tonumber(row['Dimension']));
- setElementPosition(ped, tonumber(row['PX']), tonumber(row['PY']), tonumber(row['PZ']))
- setElementModel(ped, tonumber(row['Skin']))
- setElementData(ped, "syncer_ped", true)
- setElementAlpha(ped, 200)
- setPedRotation(ped, tonumber(row['Rotation']))
- if(self.lastPositions[ped]) then
- local x1, y1, z1 = tonumber(row['PX']), tonumber(row['PY']), tonumber(row['PZ'])
- local x2, y2, z2 = self.lastPositions[ped][1], self.lastPositions[ped][2], self.lastPositions[ped][3]
- setPedAnimation(ped)
- if(math.floor(x1) ~= math.floor(x2) and math.floor(y1) ~= math.floor(y2)) then
- if(getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2) < 2) then
- setPedAnimation(ped, "ped", "run_civi", -1, true, true, false);
- else
- setPedAnimation(ped, "ped", "sprint_civi", -1, true, true, false);
- end
- else
- setPedAnimation(ped)
- end
- end
- self.lastPositions[ped] = {tonumber(row['PX']), tonumber(row['PY']), tonumber(row['PZ'])}
- for index, data in pairs(row) do
- setElementData(ped, index, data);
- end
- end
- -- ///////////////////////////////
- -- ///// CheckDB //////
- -- ///// Returns: void //////
- -- ///////////////////////////////
- function Playersync:CheckDB()
- local result, numrows = connectionManager:Query("SELECT * FROM tblplayers;");
- if(result) then
- local currentSerials = {}
- for index, player in pairs(getElementsByType("player")) do
- currentSerials[getPlayerSerial(player)] = player;
- end
- for index, peds in pairs(self.playerPeds) do
- if(isElement(ped)) and (getElementData(ped, 'Serial')) then
- if not(currentSerials[getElementData(ped, 'Serial')]) then
- destroyElement(ped)
- outputDebugString("Destroying Ped: "..tostring(ped))
- end
- end
- end
- for index, row in pairs(result) do
- if not(currentSerials[row['Serial']]) then
- local serial = row['Serial'];
- self:CheckPlayerPed(serial, row);
- end
- end
- end
- end
- -- ///////////////////////////////
- -- ///// Constructor //////
- -- ///// Returns: void //////
- -- ///////////////////////////////
- function Playersync:Constructor(...)
- self.checkDBFunc = function(...) self:CheckDB(...) end;
- self.checkDatabaseTimer = setTimer(self.checkDBFunc, 500, -1)
- self.playerPeds = {}
- self.lastPositions = {}
- outputDebugString("[CALLING] Playersync: Constructor");
- end
- -- EVENT HANDLER --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement