Guest User

Untitled

a guest
Apr 12th, 2016
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.41 KB | None | 0 0
  1. -- HOUSEMANAGER.lua
  2.  
  3. CHouseManager = inherit(cSingleton)
  4. FactionHouses = {}
  5. CorporationHouses  = {}
  6.  
  7. HousePickups= {}
  8.  
  9. function CHouseManager:constructor()
  10.     self.loadHousesFunc = function() self:loadHouses() end
  11.     self.thread= cThread:new("House_Loading_Thread", self.loadHousesFunc, 5)
  12.     self.m_iLastHouseID = 0;
  13.     self.m_iFreeHouses = 0;
  14.     self.thread:start(50);
  15. end
  16.  
  17.  
  18. function CHouseManager:createHouse(id, price, cost, owner, koords, locked, tblIntPos, distanz, fraktion, hausKey, corp, ...)
  19.  
  20.     self.m_iLastHouseID = id;
  21.  
  22.     local X = gettok(koords, 3, "|")
  23.     local Y = gettok(koords, 4, "|")
  24.     local Z = gettok(koords, 5, "|")
  25.     local Int = gettok(koords, 1, "|")
  26.     local Dim = gettok(koords, 2, "|")
  27.  
  28.     local theModel, blipID;
  29.  
  30.     outputDebugString(X)
  31.     outputDebugString(Y)
  32.     outputDebugString(Z)
  33.     outputDebugString(Int)
  34.     outputDebugString(Dim)
  35.  
  36.     if(tonumber(owner)) and (tonumber(owner) ~= 0) and (tonumber(fraktion) == 0) and (tonumber(corp) == 0) then
  37.         if not(cBasicFunctions:isOwnerInTheLastMonthsActive(tonumber(owner))) then
  38.             owner = 0;
  39.             self.m_iFreeHouses = self.m_iFreeHouses+1;
  40.         end
  41.     end
  42.  
  43.     if (owner == 0) and (fraktion == 0) and (corp == 0) then
  44.         theModel = 1273
  45.         blipID = 31
  46.     else
  47.         theModel = 1272
  48.         blipID = 32
  49.     end
  50.  
  51.     local thePickup = createPickup(X,Y,Z, 3, theModel, 1)
  52.     enew(thePickup, CHouse, id, price, cost, owner, koords, locked, tblIntPos, distanz, fraktion, hausKey, corp, ...)
  53.  
  54.     HousePickups[id] = thePickup;
  55.  
  56.     thePickup:setInterior(Int)
  57.     thePickup:setDimension(Dim)
  58.     cInformationWindowManager:getInstance():addInfoWindow({X, Y, Z+0.9}, "Haus", 30)
  59. end
  60.  
  61.  
  62. function CHouseManager:loadHouses()
  63.     local start = getTickCount()
  64.  
  65.     for k,v in pairs(Factions) do
  66.         FactionHouses[v:getID()] = {}
  67.     end
  68.     local keys = CDatabase:getInstance():query("SELECT HK.HID, U.Name FROM house_keys AS HK LEFT JOIN User AS U ON (U.ID = HK.UID);")
  69.     local houseKeys
  70.     if (#keys > 0) then
  71.         houseKeys = {}
  72.     for i, v in ipairs(keys) do
  73.         if (not houseKeys[v.HID]) then houseKeys[v.HID] = {} end
  74.             houseKeys[v.HID][v.Name] = true
  75.             table.insert(houseKeys[v.HID], v)
  76.         end
  77.     end
  78.  
  79.     local result = CDatabase:getInstance():query("SELECT H.ID, H.Cost, H.Owner, H.Koords, H.Locked, H.Interior, H.Objektdistanz, H.Faction, H.Corporation, HI.Int, HI.X, HI.Y, HI.Z, HI.Rotation, HI.Desc, HI.Price FROM houses AS H LEFT JOIN house_interiors AS HI ON (HI.ID = H.Interior)")
  80.         if (#result > 0) then
  81.         for key, value in pairs(result) do
  82.             --Koords --> Int|Dim|X|Y|Z
  83.             local Int = gettok(value["Koords"], 1, "|")
  84.             local Dim = gettok(value["Koords"], 2, "|")
  85.             local X = gettok(value["Koords"], 3, "|")
  86.             local Y = gettok(value["Koords"], 4, "|")
  87.             local Z = gettok(value["Koords"], 5, "|")
  88.  
  89.             if (value["Owner"] == 0) and (value["Faction"] == 0) then
  90.                 theModel = 1273
  91.                 blipID = 31
  92.             else
  93.                 theModel = 1272
  94.                 blipID = 32
  95.             end
  96.  
  97.             self:createHouse(value["ID"], (value["Price"] or 0), (value["Cost"] or 0), value["Owner"], value["Koords"], value["Locked"], {value['X'], value['Y'], value['Z'], value['Int']}, value["Objektdistanz"], value["Faction"], houseKeys[value['ID']], value["Corporation"])
  98.  
  99.  
  100.             --thePickup:setBlip(createBlip(X,Y,Z, blipID, 1, 0, 0, 0, 0,0,150, getRootElement()))
  101.             coroutine.yield(self.thread.thread);
  102.         end
  103.     end
  104.     outputDebugString("Es wurden "..tostring(#result).." Haueser gefunden! Entmachtet: "..self.m_iFreeHouses.." (Ende: " .. getTickCount() - start .. "ms)")
  105. end
Advertisement
Add Comment
Please, Sign In to add comment