Facebook
From Ja, 5 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 233
  1. vehicles=0
  2. root=getRootElement()
  3. resourceRoot=getResourceRootElement(getThisResource())
  4.  
  5. local nlOffsets={
  6.         [411]={-1,0,-0.6},      -- infernus
  7.         [470]={-1,0,-0.4},      -- patriot
  8.         [541]={-0.9,0,-0.4},    -- bulelt
  9.         [549]={-0.9,0,-0.4},    -- tampa
  10.         [587]={-1,0,-0.5},      -- euros
  11. }
  12.  
  13. local nlIDX={
  14.         3962,2113,1784,2054,2428,2352
  15. }
  16.  
  17. function getVehicleTable(ownerType, owner)
  18.         local tmpTable = {}
  19.         if(tonumber(ownerType) and tonumber(owner)) then
  20.                 for k, v in pairs(vehData) do
  21.                         if(v and v.ownerType == ownerType and v.ownerID == owner) then
  22.                                 table.insert(tmpTable, v)
  23.                         end
  24.                 end
  25.                 if(#tmpTable <= 0) then return false end
  26.                 return tmpTable
  27.         end
  28.         return false
  29. end
  30.  
  31. function getVehiclesToDashboard(player)
  32.         local vehs = getVehicleTable(1, player:getData("player:sid"))
  33.         if(not vehs) then vehs = {} end
  34.         return vehs
  35. end
  36.  
  37. function getVehicleHandlingProperty ( element, property )
  38.     if isElement ( element ) and getElementType ( element ) == "vehicle" and type ( property ) == "string" then
  39.         local handlingTable = getVehicleHandling ( element )
  40.         local value = handlingTable[property]
  41.  
  42.         if value then
  43.             return value
  44.         end
  45.     end
  46.  
  47.     return false
  48. end
  49.  
  50. function getAdmin2(plr,level)
  51.         if level then
  52.                 local result=exports["pystories-db"]:dbGet("SELECT * from pystories_admins WHERE serial=? AND level=?", getPlayerSerial(plr), level)
  53.                 if result and #result > 0 then
  54.                         return true
  55.                 else
  56.                         return false
  57.                 end
  58.         else
  59.                 local result=exports["pystories-db"]:dbGet("SELECT * from pystories_admins WHERE serial=?", getPlayerSerial(plr))
  60.                 if result and #result > 0 then
  61.                         return true
  62.                 else
  63.                         return false
  64.                 end
  65.         end
  66. end
  67. --///////////////////////////////////// WCZYTYWANIE POJAZDĂ“W /////////////////////////////////
  68. function onRespawnVehicles(_,id,poss,buyed,player)
  69.         -- Settings (QUERY)
  70.         if id then
  71.                 result=exports["pystories-db"]:dbGet("SELECT * FROM pystories_vehicles WHERE parking=1 AND id=?", id)
  72.                 query=exports["pystories-db"]:dbSet("UPDATE pystories_vehicles SET parking=0 WHERE id=?", id)
  73.         else
  74.                 result=exports["pystories-db"]:dbGet("SELECT * FROM pystories_vehicles WHERE parking=0")
  75.         end
  76.  
  77.         -- Pairs
  78.         for ile,vehicle in pairs(result) do
  79.         vehicles=ile
  80.  
  81.         if id then pos={poss[1], poss[2], poss[3], poss[4], poss[5], poss[6]}
  82.         else pos=split(vehicle["pos"], ",") end
  83.  
  84.         local color=split(vehicle["color"], ",")
  85.         local lights=split(vehicle["headlights"], ",")
  86.  
  87.                 local veh=createVehicle(vehicle["model"], pos[1], pos[2], pos[3], pos[4], pos[5], pos[6])
  88.                 if buyed then
  89.                         warpPedIntoVehicle(player,veh)
  90.                 end
  91.         setVehicleColor(veh, color[1], color[2], color[3], color[4],color[5], color[6], color[7], color[8],color[9], color[10], color[11], color[12])
  92.         setVehicleHeadLightColor(veh, lights[1], lights[2], lights[3])
  93.                 if vehicle["plateText"] ~= "" then
  94.                 setVehiclePlateText(veh, vehicle["plateText"])
  95.                 else
  96.                  setVehiclePlateText(veh, tostring("PL "..vehicle["id"]))
  97.                 end
  98.         setElementFrozen(veh, (vehicle["frozen"]) > 0)
  99.                 if vehicle["paintjob"] ~= 3 then
  100.         setVehiclePaintjob(veh, vehicle["paintjob"])
  101.                 end
  102.         setElementHealth(veh, vehicle["health"])
  103.         setElementData(veh,"vehicle:spawn",true)
  104.         setElementData(veh,"vehicle:id", vehicle["id"])
  105.         setElementData(veh,"vehicle:fuel", vehicle["fuel"])
  106.         setElementData(veh,"vehicle:desc", vehicle["text"] or false)
  107.         setElementData(veh,"vehicle:mileage", vehicle["mileage"])
  108.         setElementData(veh,"vehicle:driver", vehicle["driver"])
  109.         setElementData(veh,"vehicle:ownedGroup", vehicle["ownedGroup"])
  110.         setElementData(veh,"vehicle:ownedPlayer", vehicle["ownedPlayer"])
  111.                
  112.                 local mk1 = vehicle['mk1']
  113.                 local mk1 = vehicle['mk2']
  114.                 local xfour = vehicle['naped']
  115.                                
  116.                 if tonumber(xfour) == 1 then
  117.                 setVehicleHandling(veh,"driveType","awd")
  118.                 end
  119.                
  120.                 if tonumber(mk1) ~= 0 then
  121.                 local fast = getVehicleHandlingProperty(veh,"engineAcceleration")
  122.                 local maxfast = getVehicleHandlingProperty(veh,"maxVelocity")
  123.                 local masa = getVehicleHandlingProperty(veh,"mass")
  124.                 local masa2 = getVehicleHandlingProperty(veh,"turnMass")
  125.                 local xd = getVehicleHandlingProperty(veh,"tractionMultiplier")
  126.                 local coef = getVehicleHandlingProperty(veh,"dragCoeff")
  127.                 setVehicleHandling(veh,"engineAcceleration",fast+1.5)
  128.                 setVehicleHandling(veh,"maxVelocity",maxfast+16)
  129.                 setVehicleHandling(veh,"mass",masa+100)
  130.                 setVehicleHandling(veh,"tractionMultiplier",xd+0.1)
  131.                 setVehicleHandling(veh,"steeringLock",40)
  132.                 setVehicleHandling(veh,"dragCoeff",coef-0.15)
  133.                 end
  134.                
  135.                 if tonumber(mk2) ~= 0 then
  136.                 local fast = getVehicleHandlingProperty(veh,"engineAcceleration")
  137.                 local maxfast = getVehicleHandlingProperty(veh,"maxVelocity")
  138.                 local masa = getVehicleHandlingProperty(veh,"mass")
  139.                 local masa2 = getVehicleHandlingProperty(veh,"turnMass")
  140.                 local xd = getVehicleHandlingProperty(veh,"tractionMultiplier")
  141.                 local coef = getVehicleHandlingProperty(veh,"dragCoeff")
  142.                 setVehicleHandling(veh,"engineAcceleration",fast+1.7)
  143.                 setVehicleHandling(veh,"maxVelocity",maxfast+20)
  144.                 setVehicleHandling(veh,"tractionMultiplier",xd+0.2)
  145.                 setVehicleHandling(veh,"mass",masa+150)
  146.                 setVehicleHandling(veh,"steeringLock",42)
  147.                 setVehicleHandling(veh,"dragCoeff",coef-0.21)
  148.                 end
  149.                
  150.                         local wariant = getElementModel(veh)
  151.                 if wariant == 429 then
  152.                 setVehicleVariant(veh, 2, 2)
  153.                 end
  154.                 if wariant == 562 then
  155.                 setVehicleVariant(veh, 1, 1)
  156.                 end
  157.                 if wariant == 415 then
  158.                 setVehicleVariant(veh, 4, 4)
  159.                 end
  160.                 if wariant == 477 then
  161.                 setVehicleVariant(veh, 0, 1)
  162.                 end
  163.                 if wariant == 480 then
  164.                 setVehicleVariant(veh, 0, 0)
  165.                 end
  166.                 if wariant == 579 then
  167.                 setVehicleVariant(veh, 0, 0)
  168.                 end
  169.                 if wariant == 559 then
  170.                 setVehicleVariant(veh, 0, 0)
  171.                 end
  172.                 if wariant == 411 then
  173.                 setVehicleVariant(veh, 0, 0)
  174.                 end
  175.                 if wariant == 561 then
  176.                 setVehicleVariant(veh, 0, 0)
  177.                 end
  178.                
  179.                 if vehicle["blokada"] == "true" then
  180.                         setElementData(veh,"vehicle:block", true)
  181.                         setVehicleWheelStates(veh, 2, 2, 2, 2)
  182.                 else
  183.                         setElementData(veh,"vehicle:block", false)
  184.                 end
  185.                
  186.  
  187.         for i,v in ipairs(split(vehicle["tuning"], ",")) do addVehicleUpgrade(veh, v) end
  188.         for i,v in ipairs(split(vehicle["panelstates"], ",")) do setVehiclePanelState(veh, i, tonumber(v)) end
  189.                 setVehicleDamageProof(veh, true)
  190.         end
  191.  
  192.     outputDebugString("[pystories_vehicles] Loaded "..vehicles.." vehicles.")
  193. end
  194.  
  195. --///////////////////////////////////// ZAPISYWANIE POJAZDĂ“W /////////////////////////////////
  196. function onSaveVehicle(vehicle)
  197.     if getElementData(vehicle,"vehicle:spawn") then
  198.         -- Setting
  199.         local panelstates={}
  200.                 local model=getElementModel(vehicle)
  201.         local health=getElementHealth(vehicle)
  202.         local x,y,z=getElementPosition(vehicle)
  203.         local rx,ry,rz=getElementRotation(vehicle)
  204.         local desc=getElementData(vehicle,"vehicle:desc") or ""
  205.         local id=getElementData(vehicle,"vehicle:id")
  206.         local fuel=getElementData(vehicle,"vehicle:fuel")
  207.         local mileage=getElementData(vehicle,"vehicle:mileage")
  208.         local c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12=getVehicleColor(vehicle, true)
  209.         local driver=getElementData(vehicle,"vehicle:driver") or ""
  210.         local rent=getElementData(vehicle,"vehicle:rent") or ''
  211.         local player=getElementData(vehicle,"vehicle:ownedPlayer")
  212.                 local group=getElementData(vehicle,"vehicle:ownedGroup")
  213.         local blokada=getElementData(vehicle,"vehicle:block")
  214.                 local neon=getElementData(vehicle,"neony") or 0
  215.         local h1,h2,h3=getVehicleHeadLightColor(vehicle)
  216.         local paintjob=getVehiclePaintjob(vehicle)
  217.                 local rear="Brak"
  218.         local frozen= isElementFrozen(vehicle) and 1 or 0
  219.         for i=0,6 do table.insert(panelstates, getVehiclePanelState(vehicle,i)) end
  220.         panelstates=table.concat(panelstates,",")
  221.         upgrades=getVehicleUpgrades(vehicle)
  222.         if not upgrades then upgrades={} end
  223.         upgrades=table.concat(upgrades, ",")
  224.         -- Query
  225.         local query = exports["pystories-db"]:dbSet(string.format("UPDATE pystories_vehicles SET model='%d', pos='%.2f,%.2f,%.2f,%.2f,%.2f,%.2f', rent='%d',text='%s', health='%d', fuel='%d', mileage='%d', frozen='%d', driver='%s', color='%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d', panelstates='%s', paintjob='%d', tuning='%s', headlights='%d,%d,%d', ownedPlayer='%d', neon='%d', blokada='%s' WHERE id=%d",
  226.         model, x,y,z, rx,ry,rz, "0",desc, health, fuel, mileage, frozen, driver, c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12, panelstates, paintjob, upgrades, h1,h2,h3, player, neon, tostring(blokada), id))
  227.                 if (type(rent) == "table") then
  228.                 local rr = string.format("%s", table.concat(rent, ',') )
  229.                 local query2= exports['pystories-db']:dbSet("UPDATE pystories_vehicles SET rent=? WHERE id=?",rr,id)
  230.                 end
  231.     end
  232. end
  233.  
  234. function onParkVehicle(vehicle)
  235.         local query=exports["pystories-db"]:dbSet("UPDATE pystories_vehicles SET parking=1 WHERE id=?", getElementData(vehicle,"vehicle:id"))
  236.         if query then
  237.         destroyElement(vehicle)
  238.         end
  239. end
  240.  
  241. --///////////////////////////////////// SPRAWDZANIE USTAWIEŃ /////////////////////////////////
  242. function getSettings(plr,code,value)
  243.         local sid=getElementData(plr,"player:sid")
  244.         if not sid then return end
  245.         if value == "faction" then
  246.                 local result=exports["pystories-db"]:dbGet("SELECT * FROM pystories_factions WHERE code=? AND sid=?", code, sid)
  247.                 if result and #result > 0 then
  248.                         return result[1].code
  249.                 else
  250.                         return false
  251.                 end
  252.         end
  253.         if value == "organization" then
  254.                 local result=exports["pystories-db"]:dbGet("SELECT * FROM ms_organizacje WHERE uid=?", sid)
  255.                 if result and #result > 0 then
  256.                         return result[1].code
  257.                 else
  258.                         return false
  259.                 end
  260.         end
  261.         if value == "owner" then
  262.                 local result=exports["pystories-db"]:dbGet("SELECT * FROM pystories_users WHERE id=?", sid)
  263.                 if result and #result > 0 then
  264.                         return result[1].id
  265.                 else
  266.                         return false
  267.                 end
  268.         end
  269. end
  270.  
  271. --///////////////////////////////////// INNE USTAWIENIA /////////////////////////////////
  272. addEventHandler("onVehicleExit", root, function(plr,seat)
  273.         if seat ~= 0 then return end
  274.         setVehicleEngineState(source, false)
  275.         setVehicleDamageProof(source, true)
  276.         onSaveVehicle(source)
  277. end)
  278.  
  279.  
  280. addEventHandler("onPlayerQuit", root, function()
  281.     local veh=getPedOccupiedVehicle(source)
  282.     if veh then
  283.                 setVehicleDamageProof(source, true)
  284.         onSaveVehicle(veh)
  285.     end
  286. end)
  287.  
  288. addEventHandler("onResourceStop", resourceRoot, function()
  289.     for i,v in ipairs(getElementsByType("vehicle")) do
  290.         onSaveVehicle(v)
  291.     end
  292.     outputDebugString("[pystories_vehicles] Saved all vehicles!")
  293. end)
  294.  
  295. addEventHandler("onVehicleEnter", root, function(plr,seat)
  296.     if seat ~= 0 then return end
  297.         setVehicleEngineState(source, false)
  298.         setElementData(source,"vehicle:driver",getElementData(plr, "player:nickname"))
  299. end)
  300.  
  301. --///////////////////////////////////// SPRAWDZENIE WŁAŚCICIELA /////////////////////////////////
  302. addEventHandler("onVehicleStartEnter", resourceRoot, function(plr,seat,jacked)
  303.     if seat == 0 then
  304.         local rent=getElementData(source, "vehicle:rent")
  305.         local group=getElementData(source, "vehicle:ownedGroup")
  306.                 if group == "0" then group = "Brak" end
  307.         local player=getElementData(source, "vehicle:ownedPlayer")
  308.                 if getAdmin2(plr, 4) then
  309.                         return
  310.                 end
  311.                 if rent and (type(rent) == "table") then
  312.                         for i,s in pairs(rent) do
  313.                                 if tonumber(s) == getElementData(plr,"player:sid") then
  314.                                 return end
  315.                         end
  316.                 end
  317.                
  318.                 local plrgroup = getElementData(plr,"player:organization")
  319.                 if plrgroup then
  320.                         if getSettings(plr,false,"organization") == group then return end
  321.                 end
  322.                 if player and player ~= getSettings(plr,false,"owner") then
  323.                         outputChatBox("* Nie posiadasz kluczykĂłw do tego pojazdu.", plr)
  324.                         cancelEvent()
  325.                 end
  326.     end
  327. end)
  328.  
  329. addEventHandler("onVehicleStartEnter", root, function(plr,seat,jacked)
  330.         if jacked then
  331.                 if getElementData(source,"vehicle:ownedPlayer") == getElementData(plr,"player:sid") then return end
  332.                 cancelEvent()
  333.         end
  334. end)
  335.  
  336. addEventHandler("onVehicleStartEnter", root, function(plr,seat,jacked)
  337.         if seat == 0 then
  338.                 if getElementData(source,"spawnowany")== true then
  339.                         if getElementData(plr,"player:admin")== false then
  340.                                 cancelEvent()
  341.                         end
  342.                 end
  343.         end
  344. end)
  345.  
  346. addEventHandler('onVehicleStartEnter', resourceRoot, function(player, seat, jacked)
  347.         if seat ~= 0 then return end
  348.         if not getElementData(source, 'vehicle:id') then return end
  349.  
  350.         local serial = getPlayerSerial(player)
  351.         local result = exports['pystories-db']:dbGet('select * from pystories_punish where serial = ? AND time>NOW()', serial)
  352.        
  353.  
  354.         if #result > 0 then
  355.                 cancelEvent()
  356.         else
  357.                 exports['pystories-db']:dbSet('delete from pystories_punish where serial = ?', serial)
  358.         end
  359.  
  360.  
  361. end)
  362.  
  363.  
  364. addEventHandler("onResourceStart", resourceRoot, function() onRespawnVehicles(_,false) end)
  365.  
  366. local categoryA={[463] = true,[462] = true,[461] = true,[581] = true,[448] = true,[468] = true,[471] = true,[521] = true,[522] = true,[523] = true}
  367. local categoryB={[602] = true,[545] = true,[496] = true,[517] = true,[401] = true,[410] = true,[518] = true,[600] = true,[527] = true,[436] = true,[589] = true,[580] = true,[419] = true,[439] = true,[533] = true,[549] = true,[526] = true,[491] = true,[474] = true,[445] = true,[467] = true,[604] = true,[426] = true,[507] = true,[547] = true,[585] = true,[405] = true,[587] = true,[409] = true,[466] = true,[550] = true,[492] = true,[566] = true,[546] = true,[540] = true,[551] = true,[421] = true,[516] = true,[529] = true,[488] = true,[460] = true,
  368. [510] = true,[509] = true,[481] = true,[586] = true,[472] = true,[473] = true,[493] = true,[595] = true,[484] = true,[430] = true,[453] = true,[452] = true,[446] = true,[454] = true,[485] = true,[552] = true,
  369. [438] = true,[574] = true,[420] = true,[525] = true,[408] = true,[596] = true,[597] = true,[427] = true,[599] = true,[490] = true,[432] = true,[528] = true,[601] = true,[407] = true,[544] = true,[470] = true,[598] = true,[588] = true,
  370. [532] = true,[443] = true,[486] = true,[531] = true,[543] = true,[422] = true,[583] = true,[478] = true,[605] = true,[554] = true,[530] = true,[418] = true,[572] = true,[582] = true,[536] = true,[575] = true,[534] = true,
  371. [567] = true,[535] = true,[576] = true,[412] = true,[402] = true,[542] = true,[603] = true,[475] = true,[449] = true,[537] = true,[570] = true,[441] = true,[464] = true,[501] = true,[465] = true,[564] = true,[568] = true,[557] = true,[424] = true,[504] = true,[495] = true,[457] = true,[539] = true,[483] = true,[571] = true,[500] = true,
  372. [444] = true,[556] = true,[429] = true,[411] = true,[541] = true,[559] = true,[415] = true,[561] = true,[480] = true,[560] = true,[562] = true,[506] = true,[565] = true,[451] = true,[434] = true,[558] = true,[494] = true,[555] = true,[502] = true,[477] = true,[503] = true,[579] = true,[400] = true,[404] = true,[489] = true,[505] = true,[479] = true,[442] = true,[458] = true,
  373. [606] = true,[607] = true,[610] = true,[590] = true,[569] = true,[611] = true,[584] = true,[608] = true,[435] = true,[450] = true,[591] = true,[594] = true}
  374. local categoryC={[403] = true,[406] = true,[413] = true,[414] = true,[416] = true,[423] = true,[428] = true,[431] = true,[433] = true,[437] = true,[440] = true,[455] = true,[456] = true,[459] = true,[482] = true,[498] = true,[499] = true,[508] = true,[514] = true,[515] = true,[524] = true,[538] = true,[573] = true}
  375. local categoryL={[469] = true, [487] = true, [593] = true, [519] = true, [513] = true}
  376. addEventHandler("onVehicleStartEnter", resourceRoot, function(plr,seat,jacked)
  377.     if seat == 0 then
  378.                 if categoryA[getElementModel(source)] then
  379.                    if exports["pystories-ustawienia-praca"]:getVehicleLicense(plr,"A") then
  380.                         cancelEvent()
  381.                         end
  382.                 elseif categoryB[getElementModel(source)] then
  383.                         if exports["pystories-ustawienia-praca"]:getVehicleLicense(plr,"B") then
  384.                         cancelEvent()
  385.                         end
  386.                 elseif categoryC[getElementModel(source)] then
  387.                         if exports["pystories-ustawienia-praca"]:getVehicleLicense(plr,"C") then
  388.                         cancelEvent()
  389.                         end
  390.                 elseif categoryL[getElementModel(source)] then
  391.                         if exports["pystories-ustawienia-praca"]:getVehicleLicense(plr,"L") then
  392.                         cancelEvent()
  393.                         end
  394.                 end
  395.     end
  396. end)
  397.  
  398. addEventHandler("onVehicleEnter", getRootElement(), function(plr,seat,jacked)
  399. if seat ~= 0 then return end
  400. if getElementData(source, "vehicle:id") and getElementData(source, "vehicle:spawn") then
  401. local mk2 = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND mk2=?",getElementData(source, "vehicle:id"), "1")
  402. local mk1 = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND mk1=?",getElementData(source, "vehicle:id"), "1")
  403. local rh = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND rh=?",getElementData(source, "vehicle:id"), "1")
  404. local np = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND naped=?",getElementData(source, "vehicle:id"), "1")
  405. if #mk1 > 0 then outputChatBox("#007aff(ⓘ) #FFFFFFPomyślnie zaprogramowano #007affMK1",plr,255, 255, 255, true) end
  406. if #mk2 > 0 then outputChatBox("#007aff(ⓘ) #FFFFFFPomyślnie zaprogramowano #007affMK2",plr,255, 255, 255, true) end
  407. if #rh > 0 then outputChatBox("#007aff(ⓘ) #FFFFFFPomyślnie zaprogramowano #007affRH1",plr,255, 255, 255, true) end
  408. if #np > 0 then outputChatBox("#007aff(ⓘ) #FFFFFFPomyślnie zaprogramowano #007affNapęd 4x4",plr,255, 255, 255, true) end
  409. end
  410. end)
  411.