Advertisement
Guest User

Untitled

a guest
Jul 25th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.46 KB | None | 0 0
  1. local connection = exports.mta_connection:getConnection()
  2.  
  3. function loadAllGate()
  4. gates = {}
  5.  
  6. local queryHandler = dbQuery(connection, "SELECT * FROM gates")
  7. local result, numAffectedRows, errorMsg = dbPoll(queryHandler, -1)
  8. if numAffectedRows > 0 then
  9. for key, row in ipairs(result) do
  10. local gateId = tonumber(row["id"])
  11. gates[key] = {}
  12.  
  13. gates[key]["sqlId"] = gateId
  14. gates[key]["modelId"] = tonumber(row["modelId"])
  15.  
  16. gates[key]["lockState"] = true
  17.  
  18. gates[key]["defaultState"] = fromJSON(row["defaultState"])
  19. gates[key]["changeState"] = fromJSON(row["changeState"])
  20. gates[key]["createRotation"] = fromJSON(row["createRotation"])
  21. gates[key]["IndDim"] = fromJSON(row["IndDim"])
  22.  
  23. gates[key]["gate"] = createObject(gates[key]["modelId"], gates[key]["defaultState"][1], gates[key]["defaultState"][2], gates[key]["defaultState"][3], gates[key]["defaultState"][4], gates[key]["defaultState"][5], gates[key]["defaultState"][6])
  24. setElementRotation(gates[key]["gate"], gates[key]["createRotation"][1], gates[key]["createRotation"][2], gates[key]["createRotation"][3])
  25. setElementInterior(gates[key]["gate"], gates[key]["IndDim"][1])
  26. setElementDimension(gates[key]["gate"], gates[key]["IndDim"][2])
  27. end
  28. end
  29.  
  30. outputDebugString(#gates .. " gate(s) loaded")
  31. end
  32. addEventHandler("onResourceStart", resourceRoot, loadAllGate)
  33.  
  34. addCommandHandler("creategate", function (player, cmd, modellID, changex, changey, changez)
  35. if player then
  36. if modellID and changex and changey and changez then
  37. if getElementData(player, "acc:admin") >= 8 then
  38. local x, y, z = getElementPosition(player)
  39. local rotx, roty, rotz = getElementRotation(player)
  40. local int = getElementInterior(player)
  41. local dim = getElementDimension(player)
  42. dbExec(connection, "INSERT INTO gates SET defaultState = ?, createRotation = ?, changeState = ?, modelId = ?, IndDim = ? ", toJSON({x, y, z}), toJSON({rotx, roty, rotz}), toJSON({tonumber(changex), tonumber(changey), tonumber(changez)}), modellID, toJSON({int, dim}))
  43. outputChatBox("#7cc576'Sikeres' #ffffff Létrehozás", player, 255, 255, 255, true)
  44. end
  45. else
  46. outputChatBox("#7cc576[Használat] #ffffff/".. cmd .." #00ced1[Modell ID] [Mozgás_X] [Mozgás_Y] [Mozgás_Z]", player, 255, 255, 255, true)
  47. end
  48. end
  49. end)
  50.  
  51. addCommandHandler("gate", function(player)
  52. local gate = getClosestGate(player)
  53. if gate then
  54. if (not exports["mta_item"]:hasItemS(player, 36, tonumber(gate)) or false) and getElementData(player, "acc:admin") <= 5 then
  55. outputChatBox("#dc143c[Hiba]:#ffffff Nincs kulcsod a kapuhoz.", player, 255, 255, 255, true)
  56. return
  57. end
  58.  
  59. if getElementData(gates[gate]["gate"], "inUse") then
  60. return
  61. end
  62.  
  63. setElementData(gates[gate]["gate"], "inUse", true)
  64.  
  65. if gates[gate]["lockState"] then
  66. moveObject(gates[gate]["gate"], 1500, gates[gate]["changeState"][1], gates[gate]["changeState"][2], gates[gate]["changeState"][3], gates[gate]["changeState"][4], gates[gate]["changeState"][5], gates[gate]["changeState"][6], "OutQuad")
  67. setElementInterior(gates[gate]["gate"], gates[gate]["IndDim"][1])
  68. setElementDimension(gates[gate]["gate"], gates[gate]["IndDim"][2])
  69. else
  70. moveObject(gates[gate]["gate"], 1500, gates[gate]["defaultState"][1], gates[gate]["defaultState"][2], gates[gate]["defaultState"][3], gates[gate]["defaultState"][4], gates[gate]["defaultState"][5], gates[gate]["defaultState"][6], "OutQuad")
  71. setElementInterior(gates[gate]["gate"], gates[gate]["IndDim"][1])
  72. setElementDimension(gates[gate]["gate"], gates[gate]["IndDim"][2])
  73. end
  74.  
  75. gates[gate]["lockState"] = not gates[gate]["lockState"]
  76. setTimer(function()
  77. setElementData(gates[gate]["gate"], "inUse", false)
  78. end, 1500, 1)
  79. end
  80. end)
  81.  
  82. addCommandHandler("nearbygate", function(player)
  83. local gate = getClosestGate(player)
  84. if gate then
  85. outputChatBox("#7cc576[ExternalGaming] #ffffffLegközelebbi kapu: #7cc576"..gate, player, 0, 0, 0, true)
  86. else
  87. outputChatBox("#7cc576[ExternalGaming] #ffffffNincs a közeledben kapu.", player, 0, 0, 0, true)
  88. end
  89. end)
  90.  
  91. function getClosestGate(p1)
  92. local x, y, z = getElementPosition(p1)
  93. local dis = 99999
  94. local dis2 = 0
  95. local gate = false
  96.  
  97. for key, value in ipairs(gates) do
  98. local x2, y2, z2 = getElementPosition(gates[key]["gate"])
  99. dis2 = getDistanceBetweenPoints3D(x, y, z, x2, y2, z2)
  100.  
  101. if tonumber(dis2) < tonumber(dis) and tonumber(dis2) <= 9 then
  102. dis = dis2
  103. gate = key
  104. end
  105. end
  106. return gate
  107. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement