Facebook
From Hot Eider, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 148
  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", 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.                 setElementData(veh, "vehicle:pojemnosc", vehicle["pojemnosc_silnika"])
  112.                
  113.                
  114.                 if getElementData(veh, "vehicle:pojemnosc") > 11 then
  115.                         setElementData(veh, "vehicle:pojemnosc", 11)
  116.                 end
  117.  
  118.                 if getElementData(veh, "vehicle:pojemnosc") == 1 then
  119.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  120.                         local velocity = getVehicleHandling(veh).maxVelocity
  121.                         setElementData(veh, "vehicle:poj", "1.2")
  122.                         setVehicleHandling(veh, "engineAcceleration", acceleration+1.3)
  123.                 elseif getElementData(veh, "vehicle:pojemnosc") == 2 then
  124.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  125.                         local velocity = getVehicleHandling(veh).maxVelocity
  126.                         setElementData(veh, "vehicle:poj", "1.6")
  127.                         setVehicleHandling(veh, "engineAcceleration", acceleration+1.5)
  128.                 elseif getElementData(veh, "vehicle:pojemnosc") == 3 then
  129.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  130.                         local velocity = getVehicleHandling(veh).maxVelocity
  131.                         setElementData(veh, "vehicle:poj", "1.8")
  132.                         setVehicleHandling(veh, "maxVelocity", velocity+3)
  133.                         setVehicleHandling(veh, "engineAcceleration", acceleration+1.8)
  134.                 elseif getElementData(veh, "vehicle:pojemnosc") == 4 then
  135.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  136.                         local velocity = getVehicleHandling(veh).maxVelocity
  137.                         setElementData(veh, "vehicle:poj", "2.0")
  138.                         setVehicleHandling(veh, "maxVelocity", velocity+4)
  139.                         setVehicleHandling(veh, "engineAcceleration", acceleration+1.9)
  140.                 elseif getElementData(veh, "vehicle:pojemnosc") == 5 then
  141.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  142.                         local velocity = getVehicleHandling(veh).maxVelocity
  143.                         setElementData(veh, "vehicle:poj", "2.2")
  144.                         setVehicleHandling(veh, "maxVelocity", velocity+5)
  145.                         setVehicleHandling(veh, "engineAcceleration", acceleration+2.0)
  146.                 elseif getElementData(veh, "vehicle:pojemnosc") == 6 then
  147.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  148.                         local velocity = getVehicleHandling(veh).maxVelocity
  149.                         setElementData(veh, "vehicle:poj", "2.5")
  150.                         setVehicleHandling(veh, "maxVelocity", velocity+6)
  151.                         setVehicleHandling(veh, "engineAcceleration", acceleration+2.2)
  152.                 elseif getElementData(veh, "vehicle:pojemnosc") == 7 then
  153.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  154.                         local velocity = getVehicleHandling(veh).maxVelocity
  155.                         setElementData(veh, "vehicle:poj", "2.6")
  156.                         setVehicleHandling(veh, "maxVelocity", velocity+7)
  157.                         setVehicleHandling(veh, "engineAcceleration", acceleration+2.4)
  158.                 elseif getElementData(veh, "vehicle:pojemnosc") == 8 then
  159.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  160.                         local velocity = getVehicleHandling(veh).maxVelocity
  161.                         setElementData(veh, "vehicle:poj", "2.7")
  162.                         setVehicleHandling(veh, "maxVelocity", velocity+8)
  163.                         setVehicleHandling(veh, "engineAcceleration", acceleration+2.5)
  164.                 elseif getElementData(veh, "vehicle:pojemnosc") == 9 then
  165.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  166.                         local velocity = getVehicleHandling(veh).maxVelocity
  167.                         setElementData(veh, "vehicle:poj", "2.8")
  168.                         setVehicleHandling(veh, "maxVelocity", velocity+12)
  169.                         setVehicleHandling(veh, "engineAcceleration", acceleration+2.6)
  170.                 elseif getElementData(veh, "vehicle:pojemnosc") == 10 then
  171.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  172.                         local velocity = getVehicleHandling(veh).maxVelocity
  173.                         setElementData(veh, "vehicle:poj", "2.9")
  174.                         setVehicleHandling(veh, "maxVelocity", velocity+13)
  175.                         setVehicleHandling(veh, "engineAcceleration", acceleration+2.7)
  176.                 elseif getElementData(veh, "vehicle:pojemnosc") == 11 then
  177.                         local acceleration = getVehicleHandling(veh).engineAcceleration
  178.                         local velocity = getVehicleHandling(veh).maxVelocity
  179.                         setElementData(veh, "vehicle:poj", "3.0")
  180.                         setVehicleHandling(veh, "maxVelocity", velocity+18)
  181.                         setVehicleHandling(veh, "engineAcceleration", acceleration+5)
  182.                 end
  183.                 local mk1 = vehicle['mk1']
  184.                 if tonumber(mk1) ~= 0 then
  185.                 local acceleration = getVehicleHandling(veh).engineAcceleration
  186.                 local velocity = getVehicleHandling(veh).maxVelocity
  187.                 setVehicleHandling(veh,"engineAcceleration", acceleration+2)
  188.                 setVehicleHandling(veh,"maxVelocity", velocity+6)
  189.                 end
  190.                 local mk2 = vehicle['mk2']
  191.                 if tonumber(mk2) ~= 0 then
  192.                 local acceleration = getVehicleHandling(veh).engineAcceleration
  193.                 local velocity = getVehicleHandling(veh).maxVelocity
  194.                 setVehicleHandling(veh,"engineAcceleration", acceleration+4)
  195.                 setVehicleHandling(veh,"maxVelocity", velocity+8)
  196.                 end
  197.                 local mk3 = vehicle['mk3']
  198.                 if tonumber(mk3) ~= 0 then
  199.                 local acceleration = getVehicleHandling(veh).engineAcceleration
  200.                 local velocity = getVehicleHandling(veh).maxVelocity
  201.                 setVehicleHandling(veh,"engineAcceleration", acceleration+4)
  202.                 setVehicleHandling(veh,"maxVelocity", velocity+8)
  203.                 end
  204.                 local turbo = vehicle['turbo']
  205.                 if tonumber(turbo) ~= 0 then
  206.                 local acceleration = getVehicleHandling(veh).engineAcceleration
  207.                 local velocity = getVehicleHandling(veh).maxVelocity
  208.                 setVehicleHandling(veh,"engineAcceleration", acceleration+12)
  209.                 --setVehicleHandling(veh,"maxVelocity", velocity+8)
  210.                 end
  211.                 local drift = vehicle['drift']
  212.                 if tonumber(drift) ~= 0 then
  213.                 setVehicleHandling(veh,"driveType","rwd")
  214.                 setVehicleHandling(veh,"dragCoeff",1.59)
  215.                 end
  216.                 local naped = vehicle['naped']
  217.                 if tonumber(naped) ~= 0 then
  218.                 setVehicleHandling(veh,"driveType","awd")
  219.                 end            
  220.                 local mask = vehicle['masked']
  221.                 if tonumber(mask) ~= 0 then
  222.                 setElementData(veh,"vehicle:masked",vehicle['masked'])
  223.                 end
  224.                 local wariant = getElementModel(veh)
  225.                 if wariant == 429 then
  226.                 setVehicleVariant(veh, 2, 2)
  227.                 end
  228.                 if wariant == 562 then
  229.                 setVehicleVariant(veh, 1, 1)
  230.                 end
  231.                 if wariant == 415 then
  232.                 setVehicleVariant(veh, 4, 4)
  233.                 end
  234.                 if wariant == 477 then
  235.                 setVehicleVariant(veh, 0, 1)
  236.                 end
  237.                 if wariant == 480 then
  238.                 setVehicleVariant(veh, 0, 0)
  239.                 end
  240.                 if wariant == 579 then
  241.                 setVehicleVariant(veh, 0, 0)
  242.                 end
  243.                 if wariant == 559 then
  244.                 setVehicleVariant(veh, 0, 0)
  245.                 end
  246.                 if wariant == 411 then
  247.                 setVehicleVariant(veh, 0, 0)
  248.                 end
  249.                 if wariant == 561 then
  250.                 setVehicleVariant(veh, 0, 0)
  251.                 end
  252.                 setElementData(veh,"neony", vehicle["neon"])
  253.                 local rodzajneonu=tonumber(getElementData(veh,"neony"))
  254.                 if getElementData(veh,"neony") ~= 0 then
  255.                 local m = getElementModel(veh)
  256.                 local of
  257.                 if not nlOffsets[m] then
  258.                 of={-1,0,-0.5}
  259.                 else
  260.                 of=nlOffsets[m]
  261.                 end
  262.                 neon1=createObject(nlIDX[rodzajneonu],0,0,0)
  263.                 neon2=createObject(nlIDX[rodzajneonu],0,0,0)
  264.                 setElementData(veh,"zneony", {neon1, neon2})
  265.                 attachElements(neon1,veh,of[1],of[2],of[3])
  266.                 attachElements(neon2,veh,-of[1],of[2],of[3])
  267.                 end
  268.                
  269.                 if vehicle["blokada"] == "true" then
  270.                         setElementData(veh,"vehicle:block", true)
  271.                         setVehicleWheelStates(veh, 2, 2, 2, 2)
  272.                 else
  273.                         setElementData(veh,"vehicle:block", false)
  274.                 end
  275.                
  276.  
  277.         for i,v in ipairs(split(vehicle["tuning"], ",")) do addVehicleUpgrade(veh, v) end
  278.         for i,v in ipairs(split(vehicle["panelstates"], ",")) do setVehiclePanelState(veh, i, tonumber(v)) end
  279.                 setVehicleDamageProof(veh, true)
  280.         end
  281.  
  282.     outputDebugString("[pystories_vehicles] Loaded "..vehicles.." vehicles.")
  283. end
  284.  
  285. --///////////////////////////////////// ZAPISYWANIE POJAZDĂ“W /////////////////////////////////
  286. function onSaveVehicle(vehicle)
  287.     if getElementData(vehicle,"vehicle:spawn") then
  288.         -- Setting
  289.         local panelstates={}
  290.                 local model=getElementModel(vehicle)
  291.         local health=getElementHealth(vehicle)
  292.         local x,y,z=getElementPosition(vehicle)
  293.         local rx,ry,rz=getElementRotation(vehicle)
  294.         local desc=getElementData(vehicle,"vehicle:desc") or ""
  295.         local id=getElementData(vehicle,"vehicle:id")
  296.         local fuel=getElementData(vehicle,"vehicle:fuel")
  297.         local mileage=getElementData(vehicle,"vehicle:mileage")
  298.         local c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12=getVehicleColor(vehicle, true)
  299.         local driver=getElementData(vehicle,"vehicle:driver") or ""
  300.         local rent=getElementData(vehicle,"vehicle:rent") or ''
  301.         local player=getElementData(vehicle,"vehicle:ownedPlayer")
  302.                 local group=getElementData(vehicle,"vehicle:ownedGroup")
  303.         local blokada=getElementData(vehicle,"vehicle:block")
  304.         local h1,h2,h3=getVehicleHeadLightColor(vehicle)
  305.         local paintjob=getVehiclePaintjob(vehicle)
  306.                 local mask=getElementData(vehicle,"vehicle:masked") or 0
  307.                 local neon=getElementData(vehicle,"neony")
  308.                 local rear="Brak"
  309.         local frozen= isElementFrozen(vehicle) and 1 or 0
  310.         for i=0,6 do table.insert(panelstates, getVehiclePanelState(vehicle,i)) end
  311.         panelstates=table.concat(panelstates,",")
  312.         upgrades=getVehicleUpgrades(vehicle)
  313.         if not upgrades then upgrades={} end
  314.         upgrades=table.concat(upgrades, ",")
  315.         -- Query
  316.         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', masked='%d', 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",
  317.         model, x,y,z, rx,ry,rz, "0",desc, mask,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))
  318.                 if (type(rent) == "table") then
  319.                 local rr = string.format("%s", table.concat(rent, ',') )
  320.                 local query2= exports['pystories-db']:dbSet("UPDATE pystories_vehicles SET rent=? WHERE id=?",rr,id)
  321.                 end
  322.     end
  323. end
  324.  
  325. function onParkVehicle(vehicle)
  326.         local query=exports["pystories-db"]:dbSet("UPDATE pystories_vehicles SET parking=1 WHERE id=?", getElementData(vehicle,"vehicle:id"))
  327.         if query then
  328.                 local zneony=getElementData(vehicle,"zneony")
  329.                 if (zneony and type(zneony)=="table") then
  330.                 destroyElement(zneony[1])
  331.                 destroyElement(zneony[2])
  332.                 removeElementData(vehicle,"zneony")
  333.                 end
  334.         destroyElement(vehicle)
  335.         end
  336. end
  337.  
  338. --///////////////////////////////////// SPRAWDZANIE USTAWIEŃ /////////////////////////////////
  339. function getSettings(plr,code,value)
  340.         local sid=getElementData(plr,"player:sid")
  341.         if not sid then return end
  342.         if value == "faction" then
  343.                 local result=exports["pystories-db"]:dbGet("SELECT * FROM pystories_factions WHERE code=? AND sid=?", code, sid)
  344.                 if result and #result > 0 then
  345.                         return result[1].code
  346.                 else
  347.                         return false
  348.                 end
  349.         end
  350.         if value == "organization" then
  351.                 local result=exports["pystories-db"]:dbGet("SELECT * FROM ms_organizacje WHERE uid=?", sid)
  352.                 if result and #result > 0 then
  353.                         return result[1].code
  354.                 else
  355.                         return false
  356.                 end
  357.         end
  358.         if value == "owner" then
  359.                 local result=exports["pystories-db"]:dbGet("SELECT * FROM pystories_users WHERE id=?", sid)
  360.                 if result and #result > 0 then
  361.                         return result[1].id
  362.                 else
  363.                         return false
  364.                 end
  365.         end
  366. end
  367.  
  368. --///////////////////////////////////// INNE USTAWIENIA /////////////////////////////////
  369. addEventHandler("onVehicleExit", root, function(plr,seat)
  370.         if seat ~= 0 then return end
  371.         setVehicleEngineState(source, false)
  372.         setVehicleDamageProof(source, true)
  373.         onSaveVehicle(source)
  374. end)
  375.  
  376.  
  377. addEventHandler("onPlayerQuit", root, function()
  378.     local veh=getPedOccupiedVehicle(source)
  379.     if veh then
  380.                 setVehicleDamageProof(source, true)
  381.         onSaveVehicle(veh)
  382.     end
  383. end)
  384.  
  385. addEventHandler("onResourceStop", resourceRoot, function()
  386.     for i,v in ipairs(getElementsByType("vehicle")) do
  387.         onSaveVehicle(v)
  388.                 local zneony=getElementData(v,"zneony")
  389.                 if (zneony and type(zneony)=="table") then
  390.                 destroyElement(zneony[1])
  391.                 destroyElement(zneony[2])
  392.                 removeElementData(v,"zneony")
  393.                 end
  394.         end
  395.     outputDebugString("[pystories_vehicles] Saved all vehicles!")
  396. end)
  397.  
  398. addEventHandler("onVehicleEnter", root, function(plr,seat)
  399.     if seat ~= 0 then return end
  400.         setVehicleEngineState(source, false)
  401.         setElementData(source,"vehicle:driver",getElementData(plr, "player:nickname"))
  402.         if getElementData(source,"neony") and getElementData(source,"neony") ~= 0 then
  403.                 triggerClientEvent(plr,"onClientAddNotification",root,"Posiadasz neony w pojezdzie moĹĽesz \nwĹ‚Ä…czyć/wyĹ‚aczyć za pomocÄ… przycisku H.","info")
  404.                 bindKey(plr, 'h', 'down', bindHoron4, plr)
  405.         end
  406. end)
  407.  
  408. function bindHoron4(plr)
  409.                 veh=getPedOccupiedVehicle(plr)
  410.                 if not veh then return end
  411.                 local rodzajneonu=tonumber(getElementData(veh,"neony"))
  412.                 if not rodzajneonu then return end
  413.                 if rodzajneonu==0 then
  414.                 outputChatBox('* Brak Neonow.', plr, 255, 0 ,0)
  415.                 return end
  416.                 local zneony=getElementData(veh,"zneony")
  417.                 if (zneony and type(zneony)=="table") then
  418.                 destroyElement(zneony[1])
  419.                 destroyElement(zneony[2])
  420.                 removeElementData(veh,"zneony")
  421.  
  422.                 --triggerClientEvent(plr,"addNotification",root,'* WyĹ‚Ä…czyĹ‚eĹ› Neony.',"warning")
  423.                 else
  424.                 local m = getElementModel(veh)
  425.                 local of
  426.                 if not nlOffsets[m] then
  427.                 of={-1,0,-0.5}
  428.                 else
  429.                 of=nlOffsets[m]
  430.                 end
  431.                 neon1=createObject(nlIDX[rodzajneonu],0,0,0)
  432.                 neon2=createObject(nlIDX[rodzajneonu],0,0,0)
  433.                 setElementData(veh,"zneony", {neon1, neon2})
  434.                 attachElements(neon1,veh,of[1],of[2],of[3])
  435.                 attachElements(neon2,veh,-of[1],of[2],of[3])
  436.                 --triggerClientEvent(plr,"addNotification",root,'* WĹ‚Ä…czyĹ‚eĹ› Neony. PojawiÄ… siÄ™ one jak poruszysz pojazdem!',"info")
  437.                 end
  438. end
  439.  
  440. --///////////////////////////////////// SPRAWDZENIE WŁAŚCICIELA /////////////////////////////////
  441. addEventHandler("onVehicleStartEnter", resourceRoot, function(plr,seat,jacked)
  442.     if seat == 0 then
  443.         local rent=getElementData(source, "vehicle:rent")
  444.         local group=getElementData(source, "vehicle:ownedGroup")
  445.                 if group == "0" then group = "Brak" end
  446.         local player=getElementData(source, "vehicle:ownedPlayer")
  447.                 if getAdmin2(plr, 4) then
  448.                         return
  449.                 end
  450.                 if rent and (type(rent) == "table") then
  451.                         for i,s in pairs(rent) do
  452.                                 if tonumber(s) == getElementData(plr,"player:sid") then
  453.                                 return end
  454.                         end
  455.                 end
  456.                
  457.                 local plrgroup = getElementData(plr,"player:organization")
  458.                 if plrgroup then
  459.                         if getSettings(plr,false,"organization") == group then return end
  460.                 end
  461.                 if player and player ~= getSettings(plr,false,"owner") then
  462.                         outputChatBox("* Nie posiadasz kluczykĂłw do tego pojazdu.", plr)
  463.                         cancelEvent()
  464.                 end
  465.     end
  466. end)
  467.  
  468. addEventHandler("onElementDestroy", getRootElement(), function ()
  469.   if getElementType(source) == "vehicle" then
  470.         local zneony=getElementData(source,"zneony")
  471.         if (zneony and type(zneony)=="table") then
  472.                 destroyElement(zneony[1])
  473.                 destroyElement(zneony[2])
  474.                 removeElementData(source,"zneony")
  475.                 end
  476.         end
  477. end)
  478.  
  479. addEventHandler("onVehicleStartEnter", root, function(plr,seat,jacked)
  480.         if jacked then
  481.                 if getElementData(source,"vehicle:ownedPlayer") == getElementData(plr,"player:sid") then return end
  482.                 cancelEvent()
  483.         end
  484. end)
  485.  
  486. addEventHandler("onVehicleStartEnter", root, function(plr,seat,jacked)
  487.         if seat == 0 then
  488.                 if getElementData(source,"spawnowany")== true then
  489.                         if getElementData(plr,"player:admin")== false then
  490.                                 cancelEvent()
  491.                         end
  492.                 end
  493.         end
  494. end)
  495.  
  496. addEventHandler('onVehicleStartEnter', resourceRoot, function(player, seat, jacked)
  497.         if seat ~= 0 then return end
  498.         if not getElementData(source, 'vehicle:id') then return end
  499.  
  500.         local serial = getPlayerSerial(player)
  501.         local result = exports['pystories-db']:dbGet('select * from pystories_punish where serial = ? AND time>NOW()', serial)
  502.        
  503.  
  504.         if #result > 0 then
  505.                 cancelEvent()
  506.         else
  507.                 exports['pystories-db']:dbSet('delete from pystories_punish where serial = ?', serial)
  508.         end
  509.  
  510.  
  511. end)
  512.  
  513.  
  514. addEventHandler("onResourceStart", resourceRoot, function() onRespawnVehicles(_,false) end)
  515.  
  516. local categoryA={[463] = true,[462] = true,[461] = true,[581] = true,[448] = true,[468] = true,[471] = true,[521] = true,[522] = true,[523] = true}
  517. 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,
  518. [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,
  519. [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,
  520. [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,
  521. [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,
  522. [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,
  523. [606] = true,[607] = true,[610] = true,[590] = true,[569] = true,[611] = true,[584] = true,[608] = true,[435] = true,[450] = true,[591] = true,[594] = true}
  524. 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}
  525. local categoryL={[469] = true, [487] = true, [593] = true, [519] = true, [513] = true}
  526. addEventHandler("onVehicleStartEnter", resourceRoot, function(plr,seat,jacked)
  527.     if seat == 0 then
  528.                 if categoryA[getElementModel(source)] then
  529.                    if exports["pystories-ustawienia-praca"]:getVehicleLicense(plr,"A") then
  530.                         cancelEvent()
  531.                         end
  532.                 elseif categoryB[getElementModel(source)] then
  533.                         if exports["pystories-ustawienia-praca"]:getVehicleLicense(plr,"B") then
  534.                         cancelEvent()
  535.                         end
  536.                 elseif categoryC[getElementModel(source)] then
  537.                         if exports["pystories-ustawienia-praca"]:getVehicleLicense(plr,"C") then
  538.                         cancelEvent()
  539.                         end
  540.                 elseif categoryL[getElementModel(source)] then
  541.                         if exports["pystories-ustawienia-praca"]:getVehicleLicense(plr,"L") then
  542.                         cancelEvent()
  543.                         end
  544.                 end
  545.     end
  546. end)
  547.  
  548. addEventHandler("onVehicleEnter", root, function(plr,seat,jacked)
  549. if source then
  550. if source and getElementData(source,"vehicle:masked") then
  551. setElementData(plr,"player:old:nick",getPlayerName(plr))
  552. local x = string.format("#040707%s",getPlayerName(plr):gsub("#%x%x%x%x%x%x",""))
  553. setPlayerName(plr,x)
  554. end
  555. end
  556. end)
  557. addEventHandler("onVehicleExit", root, function(plr,seat,jacked)
  558. if source then
  559. if source and getElementData(source,"vehicle:masked") then
  560. local name = getElementData(plr,"player:old:nick")
  561. setPlayerName(plr,name)
  562. end
  563. end
  564. end)
  565. addEventHandler("onElementDestroy", root, function()
  566. if getElementType(source) ~= "vehicle" then return end
  567. if getElementData(source,"vehicle:masked") then
  568. for i,p in pairs(getVehicleOccupants(source)) do
  569. local name = getElementData(p,"player:old:nick")
  570. setPlayerName(p,name)
  571. end
  572. end
  573. end)
  574.  
  575. addEventHandler("onVehicleEnter", getRootElement(), function(plr,seat,jacked)
  576. if seat ~= 0 then return end
  577. if getElementData(source, "vehicle:id") and getElementData(source, "vehicle:spawn") then
  578. local mk2 = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND mk2=?",getElementData(source, "vehicle:id"), "1")
  579. local mk1 = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND mk1=?",getElementData(source, "vehicle:id"), "1")
  580. local rh = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND rh=?",getElementData(source, "vehicle:id"), "1")
  581. local np = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND naped=?",getElementData(source, "vehicle:id"), "1")
  582. local drift = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND drift=?",getElementData(source, "vehicle:id"), "1")
  583. local mk3 = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND mk3=?",getElementData(source, "vehicle:id"), "1")
  584. local turbo = exports['pystories-db']:dbGet("SELECT * FROM pystories_vehicles WHERE id=? AND turbo=?",getElementData(source, "vehicle:id"), "1")
  585. if #mk1 > 0 then outputChatBox("#ff6600(ⓘ) #FFFFFFPomyślnie zaprogramowano #ff6600Ulepszenie Silnika poz.1",plr,255, 255, 255, true) end
  586. if #mk2 > 0 then outputChatBox("#ff6600(ⓘ) #FFFFFFPomyślnie zaprogramowano #ff6600Ulepszenie Silnika poz.2",plr,255, 255, 255, true) end
  587. if #mk3 > 0 then outputChatBox("#ff6600(ⓘ) #FFFFFFPomyślnie zaprogramowano #ff6600Ulepszenie Silnika poz.3",plr,255, 255, 255, true) end
  588. if #rh > 0 then outputChatBox("#ff6600(ⓘ) #FFFFFFPomyślnie zaprogramowano #ff6600Gwintowane Zawieszenie(RH1)",plr,255, 255, 255, true) end
  589. if #np > 0 then outputChatBox("#ff6600(ⓘ) #FFFFFFPomyślnie zaprogramowano #ff6600Napęd 4x4",plr,255, 255, 255, true) end
  590. if #turbo > 0 then outputChatBox("#ff6600(ⓘ) #FFFFFFPomyślnie zaprogramowano #ff6600Turbo",plr,255, 255, 255, true) end
  591. if #drift > 0 then outputChatBox("#ff6600(ⓘ) #FFFFFFPomyślnie zaprogramowano #ff6600Drift",plr,255, 255, 255, true) end
  592. end
  593. end)
  594.