Nelsonnn

Login.lua

Nov 11th, 2018
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.38 KB | None | 0 0
  1. addEventHandler("onResourceStart", resourceRoot,
  2. function()
  3.     database = dbConnect( "sqlite", "database.db" )
  4.     if auto_load == true then
  5.         loadDataBase()
  6.     end
  7. end)
  8.  
  9. adm_group = "Admin" -- Naleznosc do Grupy.
  10. backTime = 72000000 --  Raz w ile miliseund robi beckup i namiotow .Teraz kosztuje 20
  11. auto_load = true -- Automatyczny załadunek danych przy włączeniu Srv
  12. auto_save = true -- Automatyczne zapisywanie danych
  13. spawnPositions = {
  14.     {-278.6669921875,-2882.1572265625,32.104232788086},
  15.     {-958.5595703125,-2887.9912109375,64.82421875},
  16.     {-1816.9375,-2748.18359375,1.7327127456665},
  17.     {-2816.166015625,-2439.0546875,2.4004096984863},
  18.     {-2941.5673828125,-1206.2373046875,2.7848854064941},
  19.     {-2911.51171875,-895.22265625,2.4013109207153},
  20.     {-2185.6669921875,2957.380859375,11.474840164185},
  21.     {272.2265625,2928.505859375,1.3713493347168},
  22.     {2803.943359375,595.9365234375,7.7612648010254},
  23.     {2883.7509765625,-178.4658203125,3.2714653015137},
  24.     {-233.46484375,-1735.8173828125,1.5520644187927},
  25.     {-1056.8720703125,2939.068359375,42.311294555664},
  26. }
  27.  
  28. local class_settings = {
  29.     {"VIP:NOCOMMAND",0},
  30.     {"VIP:TIME",0},
  31. }
  32.  
  33. playerDataTable = {
  34.     {"bandit",false},
  35.     {"smeltery",false},
  36.     {"currentweapon_1",false},
  37.     {"currentweapon_2",false},
  38.     {"currentweapon_3",false},
  39.     {"clothBody",false},
  40.     {"clothHead",false},
  41.     {"clothHeadN",false},
  42.     {"pain",false},
  43.     {"cold",false},
  44.     {"infection",false},
  45.     {"brokenbone",false},
  46.     {"alivetime",0},
  47.     {"skin",0},
  48.     {"MAX_Slots",8},
  49.     {"blood",12000},
  50.     {"food",math.random(50,100)},
  51.     {"thirst",math.random(50,100)},
  52.     {"temperature",36},
  53.     {"bleeding",0},
  54.     {"Shirt",0},
  55.     {"Head",0},
  56.     {"Trousers",0},
  57.     {"Shoes",0},
  58.     {"humanity",2500},
  59.     {"zombieskilled",0},
  60.     {"headshots",0},
  61.     {"murders",0},
  62.     {"banditskilled",0},
  63.     ---
  64.     {"Tools",0},
  65.     {"WoodPile",0},
  66.     {"Bandage",1},
  67.     {"Water Bootle",0},
  68.     {"Pasta Can",0},
  69.     {"Beans Can",0},
  70.     {"Hamburger",0},
  71.     {"Box Of Matches",0},
  72.     {"MAG:M1911 ",0},
  73.     {"MAG:M9 SD",0},
  74.     {"MAG:Rewolwer",0},
  75.     {"Pistol:M1911",0},
  76.     {"Pistol:M9 SD",0},
  77.     {"Winchester 1866",0},
  78.     {"Pistol:PDW",0},
  79.     {"Battle Knife",0},
  80.     {"Battle Axe",0},
  81.     {"Pizza",0},
  82.     {"Morphine",0},
  83.     {"Water Bootle",0},
  84.     {"Empty Gas Carnister",0},
  85.     {"Full Gas Carnister",0},
  86.     {"Fire",0},
  87.     {"Milk",0},
  88.     {"MAG:PDW",0},
  89.     {"MAG::MP5A5 ",0},
  90.     {"MAG:G36 ",0},
  91.     {"BELT MAG:PKP ",0},
  92.     {"BELT MAG:PKM ",0},
  93.     {"MAG:AUG ",0},
  94.     {"BELT MAG:M240",0},
  95.     {"BELT MAG:RPK",0},
  96.     {"BELT MAG:MK48 ",0},
  97.     {"BELT MAG:M249",0},
  98.     {"MAG:AS50 ",0},
  99.     {"MAG:M24 ",0},
  100.     {"MAG:DMR ",0},
  101.     {"MAG:KSVK ",0},
  102.     {"MAG:M107 ",0},
  103.     {"MAG:SVD",0},
  104.     {"BELT MAG:MG36",0},
  105.     {"BELT MAG:L85A2 ",0},
  106.     {"MAG:SCAR",0},
  107.     {"MAG:M200",0},
  108.     {"MAG:VSS",0},
  109.     {"MAG:DSR",0},
  110.     {"BELT MAG:PCA ",0},
  111.     {"MAGS:AK",0},
  112.     {"MAGS:M4A1",0},
  113.     {"Automat:M4A1 HWS M203",0},
  114.     {"Automat:AKM",0},
  115.     {"Automat:AKS-74 PSO",0},
  116.     {"Automat:AK-107 GL",0},
  117.     {"Automat:G36 Camo",0},
  118.     {"Automat:AKS Gold",0},
  119.     {"Automat:AKS-74UN Kobra",0},
  120.     {"Automat:G36",0},
  121.     {"Automat:G36C-SD",0},
  122.     {"Heavy:PKP",0},
  123.     {"Heavy:PKM",0},
  124.     {"Automat:AUG",0},
  125.     {"Heavy:M240",0},
  126.     {"Heavy:RPK",0},
  127.     {"Heavy:MK48",0},
  128.     {"Heavy:M249 SAW",0},
  129.     {"Sniper-Rifle:AS50",0},
  130.     {"Sniper-Rifle:M24",0},
  131.     {"Sniper-Rifle:DMR",0},
  132.     {"Sniper-Rifle:KSVK",0},
  133.     {"Sniper-Rifle:M107",0},
  134.     {"Sniper-Rifle:SVD Camo",0},
  135.     {"Heavy:MG36",0},
  136.     {"Automat:L85A2 Holo",0},
  137.     {"Automat:M4A1 CCO SD",0},
  138.     {"Automat:L85A2",0},
  139.     {"Automat:L85A2 ACOG GL",0},
  140.     {"Automat:SCAR-SD",0},
  141.     {"Automat:SCAR",0},
  142.     {"Sniper-Rifle:M200",0},
  143.     {"Sniper-Rifle:VSS",0},
  144.     {"Sniper-Rifleа:DSR50",0},
  145.     {"Heavy:PCA",0},
  146.     {"Pepper Gas",0},
  147.     {"Granade:Hand:Granade",0},
  148.     {"Rewolwer",0},
  149.     {"Sawn-Off Shotgun",0},
  150.     {"Shotgun:SPAZ-12",0},
  151.     {"MP5A5",0},
  152.     {"HOURS",0},
  153.     {"Med Kit",0},
  154.     {"Heat Pack",0},
  155.     {"Rifle:Lee Enfield",0},
  156.     {"Pistol:PDW",0},
  157.     {"Automat AK-74",0},
  158.     {"Blood Bag",0},
  159.     {"GPS",0},
  160.     {"Cart",0},
  161.     {"Tools",0},
  162.     {"Wire Fence",0},
  163.     {"Tire",0},
  164.     {"Engine",0},
  165.     {"Tank Parts",0},
  166.     {"M136 Rocket",0},
  167.     {"MAG:CZ550 ",0},
  168.     {"MAG:Lee Enfield ",0},
  169.     {"Automat:М4А1 CCO",0},
  170.     {"MAG:CZ550",0},
  171.     {"Satchel",0},
  172.     {"Тепловизор",0},
  173.     {"PNW",0},
  174.     {"Tent (Small)",0},
  175.     {"Tent (Military)",0},
  176.     {"Tent (Big)",0},
  177.     {"Cooked Meat",0},
  178.     {"Raw Meat",0},
  179.     {"Painkiller",1},
  180.     {"Binoculars",0},
  181.     {"Empty Water Bootle",0},
  182.     {"Empty Can",0},
  183.     {"Scraffy Burgers",0},
  184.     {"Pack:1866 Slug",0},
  185.     {"Pack:2Rnd. Slug",0},
  186.     {"Pack:SPAZ-12 Pellet",0},
  187.     {"Radio",0},
  188.     {"Battle Axe",0},
  189.     {"Shovel Of Justice",0},
  190.     {"Golf Club",0},
  191.     {"Radio Device",0},
  192.     {"Automat:AK-101",0},
  193.     {"Karambit",0},
  194.     {"Automat:M4A1",0},
  195.     {"Automat:M416",0},
  196.     {"Automat:M16A1",0},
  197.     {"Automat:M16A2",0},
  198.     {"Automat:M16A2 M203",0},
  199.     ---
  200.     {"Battle Kevlar (%.50)",0},
  201.     {"Sniper Kevlarт (%.30)",0},
  202.     {"Kevlar (%.40)",0},
  203.     {"Light Kevlar (%.20)",0},
  204.     {"Heavy Kevlar (%.60)",0},
  205.     {"Sniper Cap",0},
  206.     {"Heavy Helmet (%.80)",0},
  207.     {"Berserker Helmet (%.90)",0},
  208.     {"Striker Helmet (%.70)",0},
  209.     {"Helmet (%.60)",0},
  210.     {"Sniper Helmet (%.50)",0},
  211.     ---
  212.     {"Small Backpack (14)",0},
  213.     {"Tourist Backpack (20)",0},
  214.     {"British Assault Backpack (36)",0},
  215.     {"Coyote Backpack  (40)",0},
  216.     {"Military Backpack  (48)",0},
  217.     {"Polish Backpack (55)",0},
  218.     {"Moutain Backpack  (69)",0},
  219.     {"C.M.R.A Backpack  (82)",0},
  220.     ---
  221.     {"Poor Clothing",0},
  222.     {"Police Clothing",0},
  223.     {"Civilian Clothing (4)",0},
  224.     {"G.R.O.M Clothing",0},
  225.     {"Civilian Clothing 2 (3)",0},
  226.     {"Hunter Clothing",0},
  227.     {"Civlian CLothing 3 (2)",0},
  228.     {"Szachid Clothing ",0},
  229.     {"Civilian Clothing 4",0},
  230.     {"Cammo Clithing",0},
  231.     {"Radio",0},
  232. }
  233.  
  234. serverData = {
  235.     ["vehicle"] = {
  236.         {"MAX_Slots"},
  237.         {"Tire_inVehicle"},
  238.         {"Engine_inVehicle"},
  239.         {"Parts_inVehicle"},
  240.         {"Tire_inVehicle_HP"},
  241.         {"Engine_inVehicle_HP"},
  242.         {"Parts_inVehicle_HP"},
  243.         {"spawn"},
  244.         {"fuel"},
  245.         {"receiver"},
  246.         {"vehicle:station"},
  247.         {"armorPoints"},
  248.         {"armorPointsMax"},
  249.     },
  250.     ["items"] = {
  251.     {"Tools"}
  252.     {"WoodPile"}
  253.     {"Bandage"}
  254.     {"Water Bootle"}
  255.     {"Pasta Can"}
  256.     {"Beans Can"}
  257.     {"Hamburger"}
  258.     {"Box Of Matches"}
  259.     {"MAG:M1911 "}
  260.     {"MAG:M9 SD"}
  261.     {"MAG:Rewolwer"}
  262.     {"Pistol:M1911"}
  263.     {"Pistol:M9 SD"}
  264.     {"Winchester 1866"}
  265.     {"Pistol:PDW",}
  266.     {"Battle Knife"}
  267.     {"Battle Axe"}
  268.     {"Pizza"}
  269.     {"Morphine"}
  270.     {"Water Bootle"}
  271.     {"Empty Gas Carnister"}
  272.     {"Full Gas Carnister"}
  273.     {"Fire"},
  274.     {"Milk"},
  275.     {"MAG:PDW"}
  276.     {"MAG::MP5A5 "}
  277.     {"MAG:G36 "}
  278.     {"BELT MAG:PKP "}
  279.     {"BELT MAG:PKM "}
  280.     {"MAG:AUG "},
  281.     {"BELT MAG:M240"}
  282.     {"BELT MAG:RPK"},
  283.     {"BELT MAG:MK48 "}
  284.     {"BELT MAG:M249"}
  285.     {"MAG:AS50 "}
  286.     {"MAG:M24 "}
  287.     {"MAG:DMR "}
  288.     {"MAG:KSVK "}
  289.     {"MAG:M107 "}
  290.     {"MAG:SVD"}
  291.     {"BELT MAG:MG36"}
  292.     {"BELT MAG:L85A2 "}
  293.     {"MAG:SCAR"}
  294.     {"MAG:M200"}
  295.     {"MAG:VSS"}
  296.     {"MAG:DSR"}
  297.     {"BELT MAG:PCA "}
  298.     {"MAGS:AK"}
  299.     {"MAGS:M4A1"}
  300.     {"Automat:M4A1 HWS M203"}
  301.     {"Automat:AKM"},
  302.     {"Automat:AKS-74 PSO"}
  303.     {"Automat:AK-107 GL"}
  304.     {"Automat:G36 Camo"}
  305.     {"Automat:AKS Gold"}
  306.     {"Automat:AKS-74UN Kobra"}
  307.     {"Automat:G36"},
  308.     {"Automat:G36C-SD"}
  309.     {"Heavy:PKP"}
  310.     {"Heavy:PKM"}
  311.     {"Automat:AUG"}
  312.     {"Heavy:M240"
  313.     {"Heavy:RPK"}
  314.     {"Heavy:MK48"}
  315.     {"Heavy:M249 SAW"},
  316.     {"Sniper-Rifle:AS50"}
  317.     {"Sniper-Rifle:M24"}
  318.     {"Sniper-Rifle:DMR"}
  319.     {"Sniper-Rifle:KSVK"}
  320.     {"Sniper-Rifle:M107"}
  321.     {"Sniper-Rifle:SVD Camo"}
  322.     {"Heavy:MG36"}
  323.     {"Automat:L85A2 Holo"}
  324.     {"Automat:M4A1 CCO SD"}
  325.     {"Automat:L85A2"}
  326.     {"Automat:L85A2 ACOG GL"}
  327.     {"Automat:SCAR-SD"}
  328.     {"Automat:SCAR"}
  329.     {"Sniper-Rifle:M200"}
  330.     {"Sniper-Rifle:VSS"}
  331.     {"Sniper-Rifle:DSR50"}
  332.     {"Heavy:PCA"}
  333.     {"Pepper Gas"}
  334.     {"Granade:Hand:Granade"}
  335.     {"Rewolwer"}
  336.     {"Sawn-Off Shotgun"}
  337.     {"Shotgun:SPAZ-12"}
  338.     {"MP5A5"}
  339.     {"HOURS"}
  340.     {"Med Kit"}
  341.     {"Heat Pack"}
  342.     {"Rifle:Lee Enfield"}
  343.     {"Pistol:PDW"}
  344.     {"Automat AK-74"}
  345.     {"Blood Bag"}
  346.     {"GPS"}
  347.     {"Cart"}
  348.     {"Tools"}
  349.     {"Wire Fence"}
  350.     {"Tire"}
  351.     {"Engine"}
  352.     {"Tank Parts"}
  353.     {"M136 Rocket"}
  354.     {"MAG:CZ550 "}
  355.     {"MAG:Lee Enfield "}
  356.     {"Automat:М4А1 CCO"}
  357.     {"MAG:CZ550"}
  358.     {"Satchel"}
  359.     {"Тепловизор"}
  360.     {"PNW"}
  361.     {"Tent (Small)"}
  362.     {"Tent (Military)"}
  363.     {"Tent (Big)"}
  364.     {"Cooked Meat"}
  365.     {"Raw Meat"}
  366.     {"Painkiller"}
  367.     {"Binoculars"}
  368.     {"Empty Water Bootle"}
  369.     {"Empty Can"}
  370.     {"Scraffy Burgers"}
  371.     {"Pack:1866 Slug"},
  372.     {"Pack:2Rnd. Slug"}
  373.     {"Pack:SPAZ-12 Pellet"}
  374.     {"Radio"}
  375.     {"Battle Axe"}
  376.     {"Shovel Of Justice"}
  377.     {"Golf Club"}
  378.     {"Radio Device"}
  379.     {"Automat:AK-101"}
  380.     {"Karambit"}
  381.     {"Automat:M4A1"}
  382.     {"Automat:M416"}
  383.     {"Automat:M16A1"}
  384.     {"Automat:M16A2"}
  385.     {"Automat:M16A2 M203"}
  386.     ---
  387.     {"Battle Kevlar (%.50)"}
  388.     {"Sniper Kevlarт (%.30)"}
  389.     {"Kevlar (%.40)"},
  390.     {"Light Kevlar (%.20)"}
  391.     {"Heavy Kevlar (%.60)"}
  392.     {"Sniper Cap"},
  393.     {"Heavy Helmet (%.80)"}
  394.     {"Berserker Helmet (%.90)"}
  395.     {"Striker Helmet (%.70)"}
  396.     {"Helmet (%.60)"},
  397.     {"Sniper Helmet (%.50)"}
  398.     },
  399. }
  400.  
  401. totalData = {
  402.     "zombieskilled_total",
  403.     "murders_total",
  404. }
  405.  
  406. function playerLogin(username, pass, player)
  407.     local playerID = getAccountData(getPlayerAccount(player),"playerID")
  408.     account = getPlayerAccount(player)
  409.     local x,y,z =  getAccountData(account,"last_x"),getAccountData(account,"last_y"),getAccountData(account,"last_z")
  410.     local skin = getAccountData(account,"skin")
  411.     if skin == 73 then skin = 0 end
  412.     for i, v in ipairs ( totalData ) do
  413.         setElementData(player,v,getAccountData(account,v) or 0)
  414.     end
  415.     if getAccountData(account,"isDead") then
  416.         spawnDayZPlayer(player)
  417.         return
  418.     end
  419.     spawnPlayer (player, x,y,z, math.random(0,360), skin, 0, 0)
  420.     setElementFrozen(player, true)
  421.     fadeCamera (player, true)
  422.     setCameraTarget (player, player)
  423.     setTimer( function(player)
  424.         if isElement(player) then
  425.             setElementFrozen(player, false)
  426.         end
  427.     end,500,1,player)
  428.     playerCol = createColSphere(x,y,z,1.5)
  429.     setElementData(player,"playerCol",playerCol)
  430.     attachElements ( playerCol, player, 0, 0, 0 )
  431.     setElementData(playerCol,"parent",player)
  432.     setElementData(playerCol,"player",true)
  433.     for i,data in ipairs(playerDataTable) do
  434.         local elementData = getAccountData(account,data[1])
  435.         -- if data[1] == "alivetime_total" then
  436.             -- local alive = getAccountData(account,"alivetime") or 1
  437.             -- if not elementData or elementData < alive then
  438.                 -- elementData = alive
  439.             -- end
  440.         -- end
  441.         if not elementData then
  442.             if data[1] == "brokenbone" or data[1] == "pain" or data[1] == "isPlayerZombie" or data[1] == "cold" or data[1] == "infection" or data[1] == "currentweapon_1" or data[1] == "currentweapon_2" or data[1] == "currentweapon_3" or data[1] == "bandit" then
  443.                 elementData = elementData
  444.             elseif data[1] == "zombieskilled_total" then
  445.                 elementData = getAccountData(account,"zombieskilled") or 0
  446.             elseif data[1] == "murders_total" then
  447.                 elementData = getAccountData(account,"murders") or 0
  448.             else
  449.                 elementData = 0
  450.             end
  451.         end
  452.         setElementData(player,data[1],elementData)
  453.     end
  454.     setElementData(player,"logedin",true)
  455.     setElementData(player,"Repairing",false)
  456.     setElementData(player,"isEating",false)
  457.     setElementData(player,"isUseMedic",false)
  458.     setElementData(player,"isDrinking",false)
  459.     setElementData(player,"isSetingTent",false)
  460.     local weapon = getElementData(player,"currentweapon_1")
  461.     if weapon then
  462.         local ammoData,weapID = getWeaponAmmoType (weapon)
  463.         giveWeapon(player,weapID,getElementData(player,ammoData), true )
  464.     end
  465.     local weapon = getElementData(player,"currentweapon_2")
  466.     if weapon then
  467.         local ammoData,weapID = getWeaponAmmoType (weapon)
  468.         giveWeapon(player,weapID,getElementData(player,ammoData), false )
  469.     end
  470.     local weapon = getElementData(player,"currentweapon_3")
  471.     if weapon then
  472.         local ammoData,weapID = getWeaponAmmoType (weapon)
  473.         giveWeapon(player,weapID,getElementData(player,ammoData), false )
  474.     end
  475.     setElementModel(player, skin)
  476.     setElementData ( player, "skin", skin )
  477.     --setElementData(player,gameplayVariables["clothname"],1)
  478.     setElementData(player,"admin",getAccountData(account,"admin") or false)
  479.     setElementData(player,"supporter",getAccountData(account,"supporter") or false)
  480.     triggerClientEvent(player, "onClientPlayerDayZLogin", player)
  481. end
  482. addEvent("onPlayerDayZLogin", true)
  483. addEventHandler("onPlayerDayZLogin", getRootElement(), playerLogin)
  484.  
  485. function playerRegister(username, pass, player)
  486.     local number = math.random(table.size(spawnPositions))
  487.     local x,y,z = spawnPositions[number][1],spawnPositions[number][2],spawnPositions[number][3]
  488.     spawnPlayer (player, x,y,z, math.random(0,360), 0, 0, 0)
  489.     fadeCamera (player, true)
  490.     setCameraTarget (player, player)
  491.     playerCol = createColSphere(x,y,z,1.5)
  492.     attachElements ( playerCol, player, 0, 0, 0 )
  493.     setElementData(playerCol,"parent",player)
  494.     setElementData(playerCol,"player",true)
  495.     for i,data in ipairs(playerDataTable) do
  496.         setElementData(player,data[1],data[2])     
  497.     end
  498.     account = getAccount(username)
  499.     local value = getAccounts()
  500.     local value = #value
  501.     --setElementData(player,gameplayVariables["clothname"],1)
  502.     setElementData(player,"playerID",value+1)
  503.     setAccountData(account,"playerID",value+1)
  504.     setElementData(player,"logedin",true)
  505. end
  506. addEvent("onPlayerDayZRegister", true)
  507. addEventHandler("onPlayerDayZRegister", getRootElement(), playerRegister)
  508.  
  509. function loadDataBase()
  510.     local qh = dbQuery(database, "SELECT * FROM vehicles")
  511.     if qh then
  512.         local result, num_affected_rows, errmsg = dbPoll ( qh, -1 )
  513.         if num_affected_rows > 0 then
  514.             for result, row in pairs ( result ) do
  515.                 createNewVehicle(row)
  516.             end
  517.         end
  518.     end
  519.     local qh = dbQuery(database, "SELECT * FROM tents")
  520.     if qh then
  521.         local result, num_affected_rows, errmsg = dbPoll ( qh, -1 )
  522.         if num_affected_rows > 0 then
  523.             for result, row in pairs ( result ) do
  524.                 createNewTent(row,"tent")
  525.             end
  526.         end
  527.     end
  528. end
  529.  
  530. function saveDataBased()
  531.     outputChatBox(" ",getRootElement(),255,255,255,true)
  532.     outputChatBox("#FF0000BACKUP:#FFFFFF DATA SAVING COMMING LITTLE LAG...",getRootElement(),255,255,255,true)
  533.     destroyDataBase("tents")
  534.     destroyDataBase("vehicles")
  535.     for i,tent in ipairs(getElementsByType("colshape")) do
  536.         if getElementData(tent,"tent") then
  537.             local x,y,z = getElementPosition(tent)
  538.             local col = getElementData(tent,"parent")
  539.             local rotx,roty,rot = getElementRotation(getElementData(tent,"parent"))
  540.             local dataT = {}
  541.             local noDeleteTent = false
  542.             for i,v in ipairs(serverData["items"]) do
  543.                 local data = getElementData(tent,v[1]) or 0
  544.                 if data > 0 then
  545.                     noDeleteTent = true
  546.                 end
  547.                 table.insert(dataT,{v[1],data})
  548.             end
  549.             if noDeleteTent == true then
  550.                 local result = dbQuery( database, "INSERT INTO  `tents` VALUES ('"..x.."', '"..y.."', '"..z.."', '"..rot.."','"..toJSON(dataT).."');")
  551.                 dbFree (result)
  552.             else
  553.                 destroyElement(tent)
  554.                 destroyElement(col)
  555.             end
  556.         end
  557.     end
  558.     for index,element in ipairs(getElementsByType("vehicle")) do
  559.         local x,y,z = getElementPosition(element)
  560.         local col = getElementData(element,"parent")
  561.         local rotx,roty,rot = getElementRotation(element)
  562.         local model = getElementModel(element)
  563.         local health = getElementHealth(element)
  564.         local dataT = {}
  565.         for i,v in ipairs(serverData["items"]) do
  566.             if col ~= false then
  567.                 local data = getElementData(col,v[1]) or 0
  568.                 table.insert(dataT,{v[1],data})
  569.             end
  570.         end
  571.         for i,v in ipairs(serverData["vehicle"]) do
  572.             if col ~= false then
  573.                 local data = getElementData(col,v[1]) or 0
  574.                 table.insert(dataT,{v[1],data})
  575.             end
  576.         end
  577.         local result = dbQuery( database, "INSERT INTO  `vehicles` VALUES ('"..model.."','"..x.."', '"..y.."', '"..z.."', '"..rot.."','"..health.."', '"..toJSON(dataT).."');")
  578.         dbFree (result)
  579.     end
  580.     outputChatBox("#FF0000BACKUP:#FFFFFF DATA SAVED..",getRootElement(),255,255,255,true)
  581.     baseCopy()
  582. end
  583. setTimer(saveDataBased,backTime,0)
  584.  
  585. function autoStopSave()
  586.     if auto_save == true then
  587.         saveDataBased()
  588.     end
  589. end
  590. addEventHandler("onResourceStop", getResourceRootElement(getThisResource()),autoStopSave)
  591.  
  592. addCommandHandler("save",function(player)
  593.     if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup(adm_group)) then
  594.         saveDataBased()
  595.     end
  596. end)
  597.  
  598. addCommandHandler("load",function(player)
  599.     if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup(adm_group)) then
  600.         if auto_load == true then
  601.             outputChatBox("Automatic Data Loading Can't do it by Hand.",player,255,0,0,true)
  602.             outputChatBox("Do it With Team.",player,255,0,0,true)
  603.             return true
  604.         end
  605.         loadDataBase()
  606.         outputChatBox("#00cc00Data base Loading.",player,255,255,255,true)
  607.     end
  608. end)
  609.  
  610. addCommandHandler("autoloadoff",function(player)
  611.     if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup(adm_group)) then
  612.         if auto_load == true then
  613.             auto_load = false
  614.             outputChatBox("Car Spawn Temporarily Blocked!",player)
  615.         else
  616.             auto_load = true
  617.             outputChatBox("Car Spawn Temporaily!",player)
  618.         end
  619.     end
  620. end)
  621.  
  622. addCommandHandler("autolsaveoff",function(player)
  623.     if isObjectInACLGroup("user."..getAccountName(getPlayerAccount(player)),aclGetGroup(adm_group)) then
  624.         if auto_save == true then
  625.             auto_save = false
  626.             outputChatBox("Automatic temporarily disconnected maintenance!",player)
  627.         else
  628.             auto_save = true
  629.             outputChatBox("Automatic temporarily included maintenance!",player)
  630.         end
  631.     end
  632. end)
  633.  
  634. function destroyDataBase(base)
  635.     if base == "vehicles" then
  636.         local qh = dbQuery(database, "DELETE FROM vehicles")
  637.         local result = dbPoll( qh, -1 )
  638.     elseif base == "tents" then
  639.         local qh = dbQuery(database, "DELETE FROM tents")
  640.         local result = dbPoll( qh, -1 )
  641.     end
  642. end
  643.  
  644. function createNewVehicle(row)
  645.     local model = tonumber(row['model'])
  646.     local data = fromJSON(row['data'])
  647.     local x = tonumber(row['x'])
  648.     local y = tonumber(row['y'])
  649.     local z = tonumber(row['z'])
  650.     local r = tonumber(row['r'])
  651.     local health = tonumber(row['health'])
  652.     veh = createVehicle(model,x,y,z,0,0,r)
  653.     vehCol = createColSphere(x,y,z,3)
  654.     attachElements(vehCol,veh,0,0,1.5)
  655.     setElementData(vehCol,"parent",veh)
  656.     setElementData(veh,"parent",vehCol)
  657.     setElementData(vehCol,"vehicle",true)
  658.     setElementData(vehCol,"ID",row)
  659.     setElementHealth(veh,health)
  660.     for i,v in pairs(data) do
  661.         setElementData(vehCol,v[1],v[2])
  662.     end
  663. end
  664.  
  665. function createNewTent(row,class)
  666.     local data = fromJSON(row['data'])
  667.     local x = tonumber(row['x'])
  668.     local y = tonumber(row['y'])
  669.     local z = tonumber(row['z'])
  670.     local r = tonumber(row['r'])
  671.     if class == "tent" then
  672.         tent = createObject(3243,x,y,z,0,0,r)
  673.         --setObjectScale(tent,1.3)
  674.         tentCol = createColSphere(x,y,z,3)
  675.         attachElements ( tentCol, tent, 0, 0, 0 )
  676.         setElementData(tentCol,"parent",tent)
  677.         setElementData(tent,"parent",tentCol)
  678.         setElementData(tentCol,"tent",true)
  679.         setElementData(tentCol,"vehicle",true)
  680.         --setElementData(tentCol,"MAX_Slots",100)
  681.         for i,v in pairs(data) do
  682.             setElementData(tentCol,v[1],v[2])
  683.         end
  684.         if getElementData(tentCol,"MAX_Slots") == false or nil then
  685.             setElementData(tentCol,"MAX_Slots",100)
  686.         end
  687.         if getElementData(tentCol,"MAX_Slots") == 100 then
  688.             setElementModel(tent,3243)
  689.         elseif getElementData(tentCol,"MAX_Slots") == 200 then
  690.             setElementModel(tent,1947) 
  691.         elseif getElementData(tentCol,"MAX_Slots") == 300 then
  692.             setElementModel(tent,14581)
  693.         end
  694.     end
  695. end
  696.  
  697. function destroyThisVehicle(ps, cmd)
  698.     if isObjectInACLGroup ("user."..getAccountName ( getPlayerAccount ( ps ) ), aclGetGroup ( adm_group ) ) then
  699.         local theVehicle = getPedOccupiedVehicle(ps)
  700.         if (theVehicle) then
  701.             local col = getElementData(theVehicle, "parent")
  702.             destroyElement(col)
  703.             destroyElement(theVehicle)
  704.         else
  705.             outputChatBox("You Should Be In Transport !.",ps,30,144,255,true)
  706.         end
  707.     end
  708. end
  709. addCommandHandler("dtv", destroyThisVehicle)
  710.  
  711. function destroyVehiclePack(ps, cmd)
  712.     if isObjectInACLGroup ("user."..getAccountName ( getPlayerAccount (ps) ), aclGetGroup ( adm_group ) ) then
  713.         vehicles = getElementsByType("vehicle")
  714.         for i,v in ipairs(vehicles) do
  715.             local col = getElementData(v, "parent")
  716.             if isElement (col) then
  717.                 destroyElement(col)
  718.             end
  719.             destroyElement(v)
  720.         end
  721.     end
  722. end
  723. addCommandHandler("dvp", destroyVehiclePack)
  724.  
  725. function saveAccounts ()
  726.     local account = getPlayerAccount(source)
  727.     if account then
  728.         if isElementInWater ( source ) then
  729.             setAccountData(account,"isDead",true)
  730.         end
  731.         for i,data in ipairs(playerDataTable) do
  732.             setAccountData(account,data[1],getElementData(source,data[1]))
  733.         end
  734.         setAccountData(account,"cloth0",getElementData(source,"cloth0") or 0)
  735.         setAccountData(account,"cloth1",getElementData(source,"cloth1") or 0)
  736.         setAccountData(account,"cloth2",getElementData(source,"cloth2") or 0)
  737.         setAccountData(account,"cloth3",getElementData(source,"cloth3") or 0)
  738.         setAccountData(account,"cloth15",getElementData(source,"cloth15") or 0)
  739.         setAccountData(account,"cloth16",getElementData(source,"cloth16") or 0)
  740.         if getElementData(source,"antiRelogWork") then
  741.             createPlayerBody(source)
  742.             setAccountData(account,"isDead",true)
  743.         end
  744.         local x,y,z =  getElementPosition(source)
  745.         setAccountData(account,"last_x",x)
  746.         setAccountData(account,"last_y",y)
  747.         setAccountData(account,"last_z",z)
  748.         if isElement(getElementData(source,"playerCol")) then
  749.         destroyElement(getElementData(source,"playerCol"))
  750.         end
  751.     end
  752.     setElementData(source,"logedin",false)
  753. end
  754. addEventHandler ( "onPlayerQuit", getRootElement(), saveAccounts )
  755.  
  756. function saveAccounts2 ()
  757.     for i, player in ipairs(getElementsByType("player")) do
  758.         local account = getPlayerAccount(player)
  759.         if account then
  760.             for i,data in ipairs(playerDataTable) do
  761.                 setAccountData(account,data[1],getElementData(player,data[1]))
  762.             end
  763.             local x,y,z =  getElementPosition(player)
  764.             setAccountData(account,"last_x",x)
  765.             setAccountData(account,"last_y",y)
  766.             if isElementInWater ( source ) then
  767.                 setAccountData(account,"last_z",z+30)
  768.             else
  769.                 setAccountData(account,"last_z",z)
  770.             end
  771.         end
  772.     end
  773. end
  774. addEventHandler ( "onResourceStop", getRootElement(), saveAccounts2 )
  775.  
  776. function baseCopy()
  777.     local randomName = randomString(10)
  778.     local time = getRealTime()
  779.     local second = time.second
  780.     local minute = time.minute
  781.     local hour = time.hour
  782.     local monthday = time.monthday
  783.     local month = time.month
  784.     local year = time.year
  785.     fileCopy("database.db","database_backup/"..monthday.."."..month + 1 ..".".. year + 1900 .."_"..hour.."."..minute.."."..second.."_"..randomName..".db")
  786. end
  787.  
  788. function randomString(sym_num)
  789.     symbols = {"A","a","B","b","C","c","D","d","I","i","J","j","K","k","L","l","M","m","N","n","O","o","P","p","Q","q","R","r","T","t","U","u","V","v","W","w","X","x","Y","y","Z","z"}
  790.     local pass = ""
  791.     for i = 1, sym_num do
  792.         if math.random (1,2) == 1 then
  793.             pass = pass..tostring(math.random(0,9))
  794.         else
  795.             pass = pass..symbols[math.random(1,#symbols)]
  796.         end
  797.     end
  798.     return pass
  799. end
Advertisement
Add Comment
Please, Sign In to add comment