Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.47 KB | None | 0 0
  1.  
  2. inUse = false
  3. allZone = {}
  4. debugg = true
  5.  
  6. RegisterNetEvent("izone:notification")
  7. AddEventHandler("izone:notification", function(msg, state)
  8. if state then
  9. message = "~g~"..msg
  10. else
  11. message = "~r~"..msg
  12. end
  13. SetNotificationTextEntry("STRING")
  14. AddTextComponentString(message)
  15. DrawNotification(false, false)
  16. end)
  17.  
  18.  
  19.  
  20. RegisterNetEvent("izone:okforpoint")
  21. AddEventHandler("izone:okforpoint", function()
  22. inUse = true
  23. end)
  24.  
  25. RegisterNetEvent("izone:askforname")
  26. AddEventHandler("izone:askforname", function()
  27. local editing = true
  28. DisplayOnscreenKeyboard(true, "FMMC_KEY_TIP8", "", "", "zoneName categorie", "", "", 120)
  29. while editing do
  30. Wait(0)
  31. if UpdateOnscreenKeyboard() == 2 then
  32. editing = false
  33. TriggerEvent("izone:notification","Zone/Point non sauvegardé", false)
  34. end
  35. if UpdateOnscreenKeyboard() == 1 then
  36. editing = false
  37. resultat = GetOnscreenKeyboardResult()
  38. TriggerEvent("izone:notification", "Zone/Point enregistré", true)
  39. local result = {}
  40.  
  41. for token in string.gmatch(resultat1, "[^%s]+") do
  42. table.insert(result, token)
  43. end
  44. if #result == 2 then
  45. TriggerServerEvent("izone:savedb", result[1], result[2])
  46. else
  47. TriggerEvent("izone:notification", "Merci de rentrer la categorie, avec un espace entre le nom de la zone et la categorie", false)
  48. end
  49. end
  50. end
  51. end)
  52.  
  53. RegisterNetEvent("izone:transfertzones")
  54. AddEventHandler("izone:transfertzones", function(allZones)
  55. allZone = allZones
  56. end)
  57.  
  58. Citizen.CreateThread(function()
  59. TriggerServerEvent('givemezone')
  60. while true do
  61. Wait(0)
  62. if IsControlJustReleased(1, 182) and inUse then
  63. local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
  64. TriggerEvent("izone:notification", "Point ajouté ".. "x = "..tostring(math.ceil(x)) .. " y = " .. tostring(math.ceil(y)) .. " z = " .. tostring(math.ceil(z)), true)
  65. TriggerServerEvent("izone:addpoint", tostring(x), tostring(y), tostring(z))
  66. Wait(1000)
  67. --elseif IsControlJustReleased(1, Keys["E"]) and debugg == true then
  68. -- TriggerEvent("izone:isPlayerInZone", "testizio",function(cb)
  69. -- Citizen.Trace(tostring(cb))
  70. -- end)
  71. --end
  72. end
  73.  
  74. end
  75.  
  76. end)
  77.  
  78. RegisterNetEvent("izone:isPlayerInZone")
  79. AddEventHandler("izone:isPlayerInZone", function(zone, cb)
  80. found = FindZone(zone)
  81. if not found then
  82. cb(nil)
  83. else
  84. local plyCoords = GetEntityCoords(GetPlayerPed(-1), true)
  85. local x1, y1, z1 = table.unpack(plyCoords)
  86. if GetDistanceBetweenCoords(x1, y1, z1, tonumber(allZone[found].gravityCenter.x), tonumber(allZone[found].gravityCenter.y), 1.01, false) < tonumber(allZone[found].longestDistance) then
  87. local n = windPnPoly(allZone[found].coords, plyCoords)
  88. if n ~= 0 then
  89. cb(true)
  90. else
  91. cb(false)
  92. end
  93. else
  94. cb(false)
  95. end
  96. end
  97. end)
  98.  
  99. RegisterNetEvent("izone:isPointInZone")
  100. AddEventHandler("izone:isPointInZone", function(xr, yr, zone, cb)
  101. found = FindZone(zone)
  102. if not found then
  103. cb(nil)
  104. else
  105. local flag = { x = xr, y = yr}
  106. if GetDistanceBetweenCoords(xr, yr, 1.01, tonumber(allZone[found].gravityCenter.x), tonumber(allZone[found].gravityCenter.y), 1.01, false) < tonumber(allZone[found].longestDistance) then
  107. local n = windPnPoly(allZone[found].coords, flag)
  108. if n ~= 0 then
  109. cb(true)
  110. else
  111. cb(false)
  112. end
  113. end
  114. end
  115. end)
  116.  
  117. RegisterNetEvent("izone:tpToPointZone")
  118. AddEventHandler("izone:tpToPointZone", function(zone, pointNumber)
  119. found = FindZone(zone)
  120. if not found then
  121. Citizen.Trace("Pas de zone avec ce nom")
  122. else
  123. if pointNumber <= #allZone[found].coords then
  124. local x = allZone[found].coords[pointNumber].x
  125. local y = allZone[found].coords[pointNumber].y
  126. local z = allZone[found].coords[pointNumber].z
  127. TeleportPlayerToCoords(x, y, z)
  128. else
  129. Citizen.Trace("Point out of range")
  130. end
  131. end
  132.  
  133. end)
  134.  
  135. RegisterNetEvent("izone:tpToZone")
  136. AddEventHandler("izone:tpToZone", function(zone)
  137. found = FindZone(zone)
  138. if not found then
  139. Citizen.Trace("Pas de zone avec ce nom")
  140. else
  141. local x = allZone[found].coords[1].x
  142. local y = allZone[found].coords[1].y
  143. local z = allZone[found].coords[1].z
  144. TeleportPlayerToCoords(x, y, z)
  145. end
  146. end)
  147.  
  148. RegisterNetEvent("izone:isPlayerInAnyZone")
  149. AddEventHandler("izone:isPlayerInAnyZone", function(cb)
  150. local arrayReturn = {}
  151. local plyCoords = GetEntityCoords(GetPlayerPed(-1), true)
  152. local x1, y1, z1 = table.unpack(plyCoords)
  153.  
  154. for i=1, #allZone do
  155. if GetDistanceBetweenCoords(x1, y1, z1, tonumber(allZone[i].gravityCenter.x), tonumber(allZone[i].gravityCenter.y), 1.01, false) < tonumber(allZone[i].longestDistance) then
  156. local n = windPnPoly(allZone[i].coords, plyCoords)
  157. if n ~= 0 then
  158. table.insert(arrayReturn, allZone[i].nom)
  159.  
  160. end
  161. end
  162. end
  163. if #arrayReturn == 0 then
  164. cb(nil)
  165. else
  166. cb(arrayReturn)
  167. end
  168.  
  169. end)
  170.  
  171. RegisterNetEvent("izone:isPointInAnyZone")
  172. AddEventHandler("izone:isPointInAnyZone", function(xr, yr, cb)
  173. local arrayReturn = {}
  174. local flag = { x = xr, y = yr}
  175.  
  176. for i=1, #allZone do
  177. if GetDistanceBetweenCoords(xr, yr, 1.01, tonumber(allZone[i].gravityCenter.x), tonumber(allZone[i].gravityCenter.y), 1.01, false) < tonumber(allZone[i].longestDistance) then
  178. local n = windPnPoly(allZone[i].coords, flag)
  179. if n ~= 0 then
  180. table.insert(arrayReturn, allZone[i].nom)
  181.  
  182. end
  183. end
  184. end
  185. if #arrayReturn == 0 then
  186. cb(nil)
  187. else
  188. cb(arrayReturn)
  189. end
  190. end)
  191.  
  192. function windPnPoly(tablePoints, flag)
  193. if tostring(type(flag)) == table then
  194. py = flag.y
  195. px = flag.x
  196. else
  197. px, py, pz = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
  198. end
  199. local wn = 0
  200. table.insert(tablePoints, tablePoints[1])
  201. for i=1, #tablePoints do
  202. if i == #tablePoints then
  203. break
  204. end
  205. if tonumber(tablePoints[i].y) <= py then
  206. if tonumber(tablePoints[i+1].y) > py then
  207. if IsLeft(tablePoints[i], tablePoints[i+1], flag) > 0 then
  208. wn = wn + 1
  209. end
  210. end
  211. else
  212. if tonumber(tablePoints[i+1].y) <= py then
  213. if IsLeft(tablePoints[i], tablePoints[i+1], flag) < 0 then
  214. wn = wn - 1
  215. end
  216. end
  217. end
  218. end
  219. return wn
  220. end
  221. function IsLeft(p1s, p2s, flag)
  222. p1 = p1s
  223. p2 = p2s
  224. if tostring(type(flag)) == "table" then
  225. p = flag
  226. else
  227. p = GetEntityCoords(GetPlayerPed(-1), true)
  228. end
  229. return ( ((p1.x - p.x) * (p2.y - p.y))
  230. - ((p2.x - p.x) * (p1.y - p.y)) )
  231. end
  232.  
  233. function TeleportPlayerToCoords(x, y, z)
  234. local myPly = GetPlayerPed(-1)
  235. Citizen.Trace("x : " .. tostring(x) .. " y = " .. tostring(y) .. "z = " .. tostring(z))
  236. Citizen.Trace(tostring(type(x)))
  237. SetEntityCoords(myPly, tonumber(x), tonumber(y), tonumber(z), 1, 0, 0, 1)
  238. end
  239.  
  240. RegisterNetEvent("izone:tptc")
  241. AddEventHandler("izone:tptc", function(x, y, z)
  242. TeleportPlayerToCoords(x,y,z)
  243. end)
  244.  
  245. --RegisterNetEvent("izone:senddebug")
  246. --AddEventHandler("izone:senddebug", function(allZones)
  247. -- allZone = allZones
  248. -- Citizen.Trace(allZone[1].coords[1].x)
  249. --end)
  250. function FindZone(zone)
  251. for i = 1, #allZone do
  252. if allZone[i].nom == zone then
  253. return i
  254. end
  255. end
  256. return false
  257. end
  258.  
  259. function TeleportPlayerToCoords(x, y, z)
  260. local myPly = GetPlayerPed(-1)
  261. SetEntityCoords(myPly, tonumber(x), tonumber(y), tonumber(z), 1, 0, 0, 1)
  262. end
  263.  
  264. RegisterNetEvent("izone:tptc")
  265. AddEventHandler("izone:tptc", function(x, y, z)
  266. TeleportPlayerToCoords(x,y,z)
  267. end)
  268.  
  269. --RegisterNetEvent("izone:senddebug")
  270. --AddEventHandler("izone:senddebug", function(allZones)
  271. -- allZone = allZones
  272. -- Citizen.Trace(allZone[1].coords[1].x)
  273. --end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement