Advertisement
Noneatme

Untitled

Jul 9th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.55 KB | None | 0 0
  1. -- #######################################
  2. -- ## Project: Playersync INACTIVE      ##
  3. -- ## Name: Playersync.lua              ##
  4. -- ## Author: Noneatme                  ##
  5. -- ## Version: 1.0                      ##
  6. -- ## License: See top Folder           ##
  7. -- #######################################
  8.  
  9. -- FUNCTIONS / METHODS --
  10.  
  11. local cFunc = {};       -- Local Functions
  12. local cSetting = {};    -- Local Settings
  13.  
  14. Playersync = {};
  15. Playersync.__index = Playersync;
  16.  
  17. --[[
  18.     Playersync 2 - Stellt die Sycronisierung auf dem Server dar
  19. ]]
  20.  
  21. -- ///////////////////////////////
  22. -- ///// New                //////
  23. -- ///// Returns: Object    //////
  24. -- ///////////////////////////////
  25.  
  26. function Playersync:New(...)
  27.     local obj = setmetatable({}, {__index = self});
  28.     if obj.Constructor then
  29.         obj:Constructor(...);
  30.     end
  31.     return obj;
  32. end
  33.  
  34. -- ///////////////////////////////
  35. -- ///// CheckPlayerPeds    //////
  36. -- ///// Returns: void      //////
  37. -- ///////////////////////////////
  38.  
  39. function Playersync:CheckPlayerPed(serial, row)
  40.     if not(self.playerPeds[serial]) then
  41.         self.playerPeds[serial] = createPed(60, 0, 0, 0);
  42.     end
  43.     local ped = self.playerPeds[serial];
  44.    
  45.     setElementInterior(ped, tonumber(row['Interior']));
  46.     setElementDimension(ped, tonumber(row['Dimension']));
  47.    
  48.     setElementPosition(ped, tonumber(row['PX']), tonumber(row['PY']), tonumber(row['PZ']))
  49.  
  50.     setElementModel(ped, tonumber(row['Skin']))
  51.    
  52.     setElementData(ped, "syncer_ped", true)
  53.     setElementAlpha(ped, 200)
  54.    
  55.     setPedRotation(ped, tonumber(row['Rotation']))
  56.    
  57.     if(self.lastPositions[ped]) then
  58.         local x1, y1, z1 = tonumber(row['PX']), tonumber(row['PY']), tonumber(row['PZ'])
  59.         local x2, y2, z2 = self.lastPositions[ped][1], self.lastPositions[ped][2], self.lastPositions[ped][3]
  60.        
  61.         setPedAnimation(ped)
  62.         if(math.floor(x1) ~= math.floor(x2) and math.floor(y1) ~= math.floor(y2)) then
  63.             if(getDistanceBetweenPoints3D(x1, y1, z1, x2, y2, z2) < 2) then
  64.                 setPedAnimation(ped, "ped", "run_civi", -1, true, true, false);
  65.             else
  66.                 setPedAnimation(ped, "ped", "sprint_civi", -1, true, true, false);
  67.             end
  68.         else
  69.             setPedAnimation(ped)
  70.         end
  71.     end
  72.    
  73.     self.lastPositions[ped] = {tonumber(row['PX']), tonumber(row['PY']), tonumber(row['PZ'])}
  74.    
  75.    
  76.     for index, data in pairs(row) do
  77.         setElementData(ped, index, data);
  78.     end
  79. end
  80.  
  81. -- ///////////////////////////////
  82. -- ///// CheckDB            //////
  83. -- ///// Returns: void      //////
  84. -- ///////////////////////////////
  85.  
  86. function Playersync:CheckDB()
  87.     local result, numrows = connectionManager:Query("SELECT * FROM tblplayers;");
  88.    
  89.  
  90.     if(result) then
  91.         local currentSerials = {}
  92.         for index, player in pairs(getElementsByType("player")) do
  93.             currentSerials[getPlayerSerial(player)] = player;
  94.         end
  95.        
  96.         for index, peds in pairs(self.playerPeds) do
  97.             if(isElement(ped)) and (getElementData(ped, 'Serial')) then
  98.                 if not(currentSerials[getElementData(ped, 'Serial')]) then
  99.                     destroyElement(ped)
  100.                     outputDebugString("Destroying Ped: "..tostring(ped))
  101.                 end
  102.             end
  103.         end
  104.        
  105.         for index, row in pairs(result) do
  106.             if not(currentSerials[row['Serial']]) then
  107.                 local serial = row['Serial'];
  108.                 self:CheckPlayerPed(serial, row);
  109.             end
  110.         end
  111.     end
  112. end
  113.  
  114.  
  115. -- ///////////////////////////////
  116. -- ///// Constructor        //////
  117. -- ///// Returns: void      //////
  118. -- ///////////////////////////////
  119.  
  120. function Playersync:Constructor(...)
  121.     self.checkDBFunc = function(...) self:CheckDB(...) end;
  122.  
  123.     self.checkDatabaseTimer = setTimer(self.checkDBFunc, 500, -1)
  124.    
  125.     self.playerPeds = {}
  126.    
  127.     self.lastPositions = {}
  128.    
  129.     outputDebugString("[CALLING] Playersync: Constructor");
  130. end
  131.  
  132. -- EVENT HANDLER --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement