PageRenderTime 69ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 1ms

/[gameplay]/traffic/client/traffic_client.lua

https://gitlab.com/yasin3223/mtasa-resources
Lua | 650 lines | 440 code | 50 blank | 160 comment | 91 complexity | ede843162f4521ad1a13fa9e7d9268ca MD5 | raw file
  1. local sx, sy = guiGetScreenSize()
  2. CURVE = 45 --45
  3. NODE_LOSTDISTANCE = 100
  4. NODE_LOSTTIME = 10000
  5. CONTROLS = {"vehicle_left","vehicle_right","brake_reverse","accelerate","handbrake","horn"}
  6. addEventHandler ( "onClientResourceStart", getResourceRootElement(),
  7. function()
  8. triggerServerEvent("onPlayerFinishedDownloadTraffic", _local)
  9. outputChatBox("Press X to warp you in the next traffic vehicle", 0, 255, 0)
  10. end
  11. )
  12. -- Process all peds
  13. addEventHandler ( "onClientPreRender", _root, function ()
  14. -- Only in this resource and only streamed in
  15. for i, ped in ipairs ( getElementsByType ( "ped", getResourceRootElement(), true ) ) do
  16. if _peds[ped] and _peds[ped].parked ~= true then
  17. local veh = getElementParent(ped)
  18. local sync = isElementSyncer(veh)
  19. if _peds[ped].sync == sync then
  20. if sync then
  21. pedProcessSyncer(ped)
  22. else
  23. pedProcess(ped)
  24. end
  25. elseif sync then
  26. -- _peds[ped] = getElementData(veh,"trafficSettings")
  27. local node = pathsNodeFindClosest(getElementPosition(veh))
  28. local next = getNode(getElementData(veh, "next")) or pedGetNextNode(ped, node)
  29. pedFormQueue(ped, next, node)
  30. pedProcessSyncer(ped)
  31. -- if DEBUG then
  32. -- outputDebugString("syncerChange node = "..tostring(node.id).." next = "..tostring(next.id))
  33. -- end
  34. -- elseif not sync then
  35. -- triggerServerEvent("onSyncerLost", veh)
  36. end
  37. _peds[ped].sync = sync
  38. end
  39. end
  40. end )
  41. -- addEvent ( "onSyncerChange", true )
  42. -- addEventHandler ( "onSyncerChange", _root,
  43. -- function (node, next)
  44. -- local ped = getVehicleController(source)
  45. -- if _peds[ped] then
  46. -- if DEBUG then
  47. -- outputDebugString("onSyncerChange client end: node = "..tostring(node).." next = "..tostring(next))
  48. -- end
  49. -- pedInitialize(ped, node, next)
  50. -- local node = pathsNodeFindClosest(getElementPosition(source))
  51. -- local next = pedGetNextNode(ped, node, node)
  52. -- pedFormQueue(ped, next, node)
  53. -- pedProcessSyncer(ped)
  54. -- end
  55. -- end
  56. -- )
  57. -- addEventHandler ( "onClientPlayerQuit", _root, function ()
  58. -- for i, ped in ipairs ( getElementsByType ( "ped", getResourceRootElement(), true ) ) do
  59. -- if ( _peds[ped] ) then
  60. -- local veh = getElementParent(ped)
  61. -- if isElementSyncer(veh) then
  62. -- triggerServerEvent("onSyncerChange", veh, _peds[ped].queue[1].id, _peds[ped].queue[2].id)
  63. -- if DEBUG then
  64. -- outputDebugString("onSyncerChange client start on quit")
  65. -- end
  66. -- end
  67. -- end
  68. -- end
  69. -- end )
  70. addEvent ( VEH_CREATED, true )
  71. addEventHandler ( VEH_CREATED, _root, function ( node, next )
  72. if not _peds[source] then
  73. pedInitialize ( source, node, next )
  74. end
  75. end )
  76. addEventHandler ( "onClientElementDestroy", getResourceRootElement(), function()
  77. if ( _peds[source] ) then
  78. _peds[source] = nil
  79. end
  80. end )
  81. function pedProcessSyncer ( ped )
  82. local vehicle = getElementParent ( ped )
  83. if not vehicle then
  84. return
  85. end
  86. -- if DEBUG then
  87. -- _peds[ped].processed = true
  88. -- end
  89. local next = pedGetTargetNode ( ped )
  90. if not next then return end
  91. if _peds[ped].parked then
  92. next = _peds[ped].parked
  93. end
  94. local x, y, z = getElementPosition ( vehicle )
  95. local nx, ny, nz = next.x, next.y, next.z
  96. if DEBUG then
  97. dxDrawLine3D ( x, y, z, nx, ny, nz, tocolor ( 255, 0, 255, 255 ), 10 )
  98. end
  99. local stop
  100. local controls = {}
  101. local limit = SPEED_LIMIT[_peds[ped].nodes[1].type]
  102. local rot = ( 360 - math.deg ( math.atan2 ( ( nx - x ), ( ny - y ) ) ) ) % 360
  103. local _, _, vrot = getElementRotation ( vehicle )
  104. local vrot = vrot or 0
  105. local trot = ( rot - vrot ) % 360
  106. if ( _peds[ped].panic ) then
  107. limit = limit + PANIC_SPEED
  108. end
  109. if _peds[ped].queue[1].flags then
  110. if _peds[ped].queue[1].flags.highway then
  111. limit = limit + HIGHWAY_SPEED
  112. end
  113. if _peds[ped].queue[1].flags.parking then
  114. _peds[ped].parked = _peds[ped].queue[1]
  115. stop = true
  116. limit = 1
  117. end
  118. end
  119. local distance = getDistanceBetweenPoints3D(x, y, z, nx, ny, nz)
  120. _peds[ped].distance = math.floor(distance)
  121. if distance > NODE_LOSTDISTANCE or NODE_LOSTTIME < getTickCount() - _peds[ped].findNodeStartTime then
  122. local node = pathsNodeFindClosest(x, y, z)
  123. pedFormQueue(ped, node, pedGetNextNode(ped, node))
  124. return
  125. end
  126. local accuracy = distance < 7 and 20 or 6
  127. if ( trot > -accuracy and trot < accuracy ) then
  128. controls["vehicle_left"] = false
  129. controls["vehicle_right"] = false
  130. elseif ( trot <= 360 and trot >= 180 ) then
  131. limit = SPEED_TURNING[_peds[ped].nodes[1].type]
  132. controls["vehicle_left"] = false
  133. controls["vehicle_right"] = true
  134. elseif ( trot >= 0 and trot <= 180 ) then
  135. limit = SPEED_TURNING[_peds[ped].nodes[1].type]
  136. controls["vehicle_right"] = false
  137. controls["vehicle_left"] = true
  138. end
  139. if ( getVehicleSpeed ( vehicle ) > limit ) then
  140. controls["accelerate"] = false
  141. -- outputChatBox("limit: "..limit)
  142. else
  143. controls["brake_reverse"] = false
  144. controls["accelerate"] = true
  145. end
  146. local horn = false
  147. local sightLength = math.pow(getVehicleSpeed(vehicle)/10, 2)
  148. sightLength = sightLength < 4 and 4 or sightLength
  149. sightLength = sightLength > 30 and 30 or sightLength
  150. if 1500 > getTickCount() - _peds[ped].stopStartTime then
  151. sightLength = _peds[ped].stopLength or sightLength
  152. end
  153. local matrix = getElementMatrix(vehicle)
  154. -- dxDrawLine3D( matrix[4][1], matrix[4][2], matrix[4][3], matrix[4][1] + matrix[1][1], matrix[4][2] + matrix[2][1], matrix[4][3] + matrix[3][1], tocolor ( 0, 255, 0), 3)
  155. -- dxDrawLine3D( matrix[4][1], matrix[4][2], matrix[4][3], matrix[4][1] + matrix[1][2], matrix[4][2] + matrix[2][2], matrix[4][3] + matrix[3][2], tocolor ( 0, 255, 0), 3)
  156. -- dxDrawLine3D( matrix[4][1], matrix[4][2], matrix[4][3], matrix[4][1] + matrix[1][3], matrix[4][2] + matrix[2][3], matrix[4][3] + matrix[3][3], tocolor ( 0, 255, 0), 3)
  157. local distanceToGround = getElementDistanceFromCentreOfMassToBaseOfModel(vehicle) - 0.25
  158. local tx, ty, tz
  159. local process = {}
  160. local sideLineDistance = getVehicleType(vehicle) == "Bike" and 0.5 or 1
  161. for i=-sideLineDistance, sideLineDistance, 0.5 do
  162. for j=-distanceToGround, distanceToGround, distanceToGround do
  163. x, y, z = getMatrixOffsets(matrix, i, 0, j)
  164. tx, ty, tz = getMatrixOffsets(matrix, i, sightLength, j)
  165. local _, _, _, _, elem = processLineOfSight( x, y, z, tx, ty, tz, true, true, true, true, true, true, true, true, vehicle )
  166. table.insert(process, elem)
  167. if DEBUG then
  168. dxDrawLine3D( x, y, z, tx, ty, tz, tocolor ( 255, 255, 255), 3)
  169. end
  170. end
  171. end
  172. local hitElement = process[1]
  173. -- for _,elem in ipairs(process) do
  174. -- if elem then
  175. -- hitElement = elem
  176. -- break
  177. -- end
  178. -- end
  179. if hitElement then
  180. stop = not _peds[ped].panic
  181. horn = HORN_ENABLED
  182. -- outputChatBox(tostring(seeElement).." "..getElementType(seeElement))
  183. if getElementType(hitElement) == "vehicle" then
  184. stop = getVehicleController(hitElement)
  185. -- if _peds[occupant] then
  186. -- if next.leftlanes == 2 or next.rightlanes == 2 then
  187. -- lane = 0
  188. -- nextlanes = 5
  189. -- stop = false
  190. -- end
  191. -- end
  192. end
  193. else
  194. HORN_STARTTIME[ped] = getTickCount()
  195. end
  196. if ( stop ) then
  197. _peds[ped].stopStartTime = getTickCount()
  198. _peds[ped].stopLength = sightLength
  199. controls["accelerate"] = false
  200. -- controls["vehicle_left"] = false
  201. -- controls["vehicle_right"] = false
  202. controls["vehicle_left"] = controls["vehicle_right"]
  203. controls["vehicle_right"] = controls["vehicle_left"]
  204. if getVehicleSpeed( vehicle ) < 3 then
  205. controls["brake_reverse"] = false
  206. else
  207. controls["brake_reverse"] = true
  208. end
  209. controls["handbrake"] = true
  210. if horn then
  211. controls["horn"] = true
  212. if not HORN_STARTTIME[ped] then
  213. HORN_STARTTIME[ped] = getTickCount()
  214. end
  215. if HORN_TIME <= getTickCount() - HORN_STARTTIME[ped] then
  216. controls["horn"] = true
  217. HORN_STARTTIME[ped] = getTickCount()
  218. elseif HORN_TIME <= getTickCount() - HORN_STARTTIME[ped] + 500 then
  219. controls["horn"] = false
  220. end
  221. end
  222. if not HORN_STARTTIMELONG[ped] then
  223. HORN_STARTTIMELONG[ped] = getTickCount()
  224. end
  225. if 3*HORN_TIME <= getTickCount() - HORN_STARTTIMELONG[ped] then
  226. HORN_STARTTIMELONG[ped] = getTickCount()
  227. elseif 3*HORN_TIME <= getTickCount() - HORN_STARTTIMELONG[ped] + 1000 then
  228. -- outputChatBox("drive backwards")
  229. controls["handbrake"] = false
  230. controls["brake_reverse"] = true
  231. end
  232. else
  233. controls["brake_reverse"] = false
  234. controls["handbrake"] = false
  235. controls["horn"] = false
  236. end
  237. local naechsteKurve, kommendeKurve = 0, 0
  238. if #_peds[ped].queue >= 3 then
  239. naechsteKurve = math.abs( math.deg(math.atan2(_peds[ped].queue[3].y - _peds[ped].queue[2].y, _peds[ped].queue[3].x - _peds[ped].queue[2].x)) - math.deg(math.atan2(_peds[ped].queue[2].y - _peds[ped].queue[1].y, _peds[ped].queue[2].x - _peds[ped].queue[1].x)) )
  240. if #_peds[ped].queue >= 4 then
  241. kommendeKurve = math.abs( math.deg(math.atan2(_peds[ped].queue[4].y - _peds[ped].queue[3].y, _peds[ped].queue[4].x - _peds[ped].queue[3].x)) - math.deg(math.atan2(_peds[ped].queue[3].y - _peds[ped].queue[2].y, _peds[ped].queue[3].x - _peds[ped].queue[2].x)) )
  242. end
  243. end
  244. -- if not _peds[ped].queue[1].neighbours or kommendeKurve > CURVE or naechsteKurve > CURVE then
  245. if not _peds[ped].queue[1].nbs or kommendeKurve > CURVE or naechsteKurve > CURVE then
  246. if ( getVehicleSpeed ( vehicle ) > 35 ) then
  247. controls["brake_reverse"] = true
  248. controls["accelerate"] = false
  249. elseif ( getVehicleSpeed ( vehicle ) > 20 ) then
  250. controls["brake_reverse"] = false
  251. controls["accelerate"] = false
  252. end
  253. end
  254. sightLength = getVehicleType(vehicle) == "Bike" and 2 or 4
  255. sideLineDistance = getVehicleType(vehicle) == "Bike" and 0 or 1
  256. for i=-sideLineDistance, sideLineDistance, 0.5 do
  257. x, y, z = getMatrixOffsets(matrix, i, 0, 0)
  258. tx, ty, tz = getMatrixOffsets(matrix, i, sightLength, 0)
  259. local collideGTABuilding = processLineOfSight( x, y, z, tx, ty, tz, true, false, false, true, false, false, false, true, vehicle )
  260. if DEBUG then
  261. dxDrawLine3D( x, y, z, tx, ty, tz, tocolor ( 255, 0, 0), 3)
  262. end
  263. if collideGTABuilding then
  264. if getVehicleOccupant(vehicle,1) then
  265. dxDrawText ( "COLLIDE FRONT", sx - 200, sy/2 - 15, sx - 200, sy/2 - 15, tocolor(255,0,0), 2 )
  266. end
  267. _peds[ped].collideStartTimeFront = getTickCount()
  268. break
  269. end
  270. end
  271. if 750 >= getTickCount() - _peds[ped].collideStartTimeFront then
  272. controls["accelerate"] = false
  273. controls["brake_reverse"] = getVehicleSpeed ( vehicle ) < 10 and true or getVehicleSpeed ( vehicle ) > 15 and true or false
  274. controls["vehicle_left"] = controls["vehicle_right"]
  275. controls["vehicle_right"] = controls["vehicle_left"]
  276. end
  277. for i=-sideLineDistance, sideLineDistance, 0.5 do
  278. x, y, z = getMatrixOffsets(matrix, i, 0, 0)
  279. tx, ty, tz = getMatrixOffsets(matrix, i, -sightLength, 0)
  280. local collideGTABuilding = processLineOfSight( x, y, z, tx, ty, tz, true, false, false, true, false, false, false, true, vehicle )
  281. if DEBUG then
  282. dxDrawLine3D( x, y, z, tx, ty, tz, tocolor ( 255, 0, 0), 3)
  283. end
  284. if collideGTABuilding then
  285. if getVehicleOccupant(vehicle,1) then
  286. dxDrawText ( "COLLIDE BACK", sx - 200, sy/2 - 5, sx - 200, sy/2 - 5, tocolor(255,0,0), 2 )
  287. end
  288. _peds[ped].collideStartTimeBack = getTickCount()
  289. break
  290. end
  291. end
  292. if 750 >= getTickCount() - _peds[ped].collideStartTimeBack then
  293. controls["accelerate"] = getVehicleSpeed ( vehicle ) < 10 and true or getVehicleSpeed ( vehicle ) > 15 and true or false
  294. controls["brake_reverse"] = false
  295. controls["vehicle_left"] = controls["vehicle_right"]
  296. controls["vehicle_right"] = controls["vehicle_left"]
  297. end
  298. sightLength = sightLength/2
  299. sideLineDistance = sideLineDistance*2
  300. for i=-sideLineDistance, sideLineDistance, 1 do
  301. x, y, z = getMatrixOffsets(matrix, 0, i, 0)
  302. tx, ty, tz = getMatrixOffsets(matrix, sightLength, i, 0)
  303. local collideGTABuilding = processLineOfSight( x, y, z, tx, ty, tz, true, false, false, true, false, false, false, true, vehicle )
  304. if DEBUG then
  305. dxDrawLine3D( x, y, z, tx, ty, tz, tocolor ( 255, 0, 0), 3)
  306. end
  307. if collideGTABuilding then
  308. if getVehicleOccupant(vehicle,1) then
  309. dxDrawText ( "COLLIDE RIGHT", sx - 200, sy/2 + 5, sx - 200, sy/2 + 5, tocolor(255,0,0), 2 )
  310. end
  311. controls["vehicle_left"] = true
  312. controls["vehicle_right"] = false
  313. break
  314. end
  315. end
  316. for i=-sideLineDistance, sideLineDistance, 1 do
  317. x, y, z = getMatrixOffsets(matrix, 0, i, 0)
  318. tx, ty, tz = getMatrixOffsets(matrix, -sightLength, i, 0)
  319. local collideGTABuilding = processLineOfSight( x, y, z, tx, ty, tz, true, false, false, true, false, false, false, true, vehicle )
  320. if DEBUG then
  321. dxDrawLine3D( x, y, z, tx, ty, tz, tocolor ( 255, 0, 0), 3)
  322. end
  323. if collideGTABuilding then
  324. if getVehicleOccupant(vehicle,1) then
  325. dxDrawText ( "COLLIDE LEFT", sx - 200, sy/2 + 15, sx - 200, sy/2 + 15, tocolor(255,0,0), 2 )
  326. end
  327. controls["vehicle_left"] = false
  328. controls["vehicle_right"] = true
  329. break
  330. end
  331. end
  332. setElementData(vehicle, "next", next.id)
  333. if _peds[ped].parked and distance < 3 then
  334. for control in pairs(controls) do
  335. controls[control] = false
  336. end
  337. controls["handbrake"] = true
  338. setVehicleEngineState(vehicle, false)
  339. _peds[ped].parked = true
  340. end
  341. for control, state in pairs(controls) do
  342. if _peds[ped].controls[control] ~= state then
  343. setPedControlState(ped, control, state)
  344. setElementData(vehicle, control, state)
  345. end
  346. end
  347. _peds[ped].controls = controls
  348. -- setElementData(vehicle, "trafficSettings", _peds[ped])
  349. end
  350. function pedProcess(ped)
  351. for i, control in pairs(CONTROLS) do
  352. setPedControlState(ped, control, getElementData(getElementParent(ped), control))
  353. end
  354. end
  355. addEventHandler ( "onClientPlayerWeaponFire", _root, function()
  356. local px, py, pz = getElementPosition ( source )
  357. for i, ped in ipairs ( getElementsByType ( "ped", getResourceRootElement() ) ) do
  358. if ( _peds[ped] ) then
  359. local x, y, z = getElementPosition ( ped )
  360. if ( getDistanceBetweenPoints3D ( x, y, z, px, py, pz ) <= PANIC_DIST ) then
  361. if ( not _peds[ped].panic ) then
  362. _peds[ped].panic = true
  363. setTimer ( pedStopPanic, PANIC_TIME, 1, ped )
  364. end
  365. end
  366. end
  367. end
  368. end )
  369. function pedStopPanic ( ped )
  370. _peds[ped].panic = false
  371. end
  372. -- SHOWNODES = 70
  373. addEventHandler ( "onClientRender", _root, function()
  374. -- if SHOWNODES then
  375. -- local x,y,z = getElementPosition ( _local )
  376. -- local areaID = getAreaFromPos(x,y,z)
  377. -- for _, node in pairs (AREA_PATHS[areaID]) do
  378. -- if getDistanceBetweenPoints3D ( node.x, node.y, node.z, x,y,z ) < SHOWNODES then
  379. -- -- dxDrawLine3D( node.x, node.y, node.z, node.x, node.y, node.z+2, tocolor ( 255, 0, 0), 3)
  380. -- local dx, dy = getScreenFromWorldPosition ( node.x, node.y, node.z )
  381. -- if ( dx and dy ) then
  382. -- -- var_dump(node)
  383. -- local neighbours = ""
  384. -- for i,v in pairs(node.neighbours) do
  385. -- neighbours = neighbours..tostring(i).."("..tostring(v)..")"..", "
  386. -- end
  387. -- dxDrawText (
  388. -- "node: "..tostring(node.id)..
  389. -- "\nlanes: "..tostring(node.leftlanes).." "..tostring(node.rightlanes)..
  390. -- "\nneighbours: "..tostring(neighbours)..
  391. -- "\nwidth: "..tostring(node.width)..
  392. -- "\nflags: "..tostring(node.flags and table.concatIndex(node.flags)),
  393. -- dx, dy, dx, dy, tocolor ( 255, 255, 255, 255 ), 1.2, "default", "center" )
  394. -- end
  395. -- end
  396. -- end
  397. -- end
  398. if DEBUG then
  399. local px, py, pz = getElementPosition ( _local )
  400. local sx, sy = guiGetScreenSize()
  401. local count = 0
  402. local count_synced, count_local = 0, 0
  403. for i, ped in ipairs ( getElementsByType ( "ped", getResourceRootElement() ) ) do
  404. if ( _peds[ped] ) then
  405. local veh = getElementParent ( ped )
  406. if ( getElementType ( veh ) == "vehicle" ) then
  407. local x, y, z = getElementPosition ( veh )
  408. local areaID = getAreaFromPos ( x, y, z )
  409. count = count + 1
  410. local dist = getDistanceBetweenPoints3D ( x, y, z, px, py, pz )
  411. if ( dist < SYNC_DIST ) then
  412. count_synced = count_synced + 1
  413. if ( isElementOnScreen ( ped ) ) then
  414. local dx, dy = getScreenFromWorldPosition ( x, y, z + 1 )
  415. if ( dx and dy ) then
  416. local next = _peds[ped].next
  417. local next_id = "None"
  418. if ( next ) then next_id = next.id end
  419. local node = _peds[ped].node
  420. local node_id = "None"
  421. if ( node ) then node_id = node.id end
  422. dxDrawText (
  423. "area: "..areaID..
  424. "\nzonename: "..tostring(getZoneName(x,y,z)).." ("..tostring(getZoneName(x,y,z,true))..")"..
  425. "\nspeed: "..math.floor(getVehicleSpeed(veh))..
  426. "\nqueue: "..tostring(#_peds[ped].queue)..
  427. "\nparked: "..tostring ( _peds[ped].parked )..
  428. "\nangle: "..tostring(#_peds[ped].queue >= 3 and math.floor(math.abs(math.abs(math.deg(math.atan2(_peds[ped].queue[3].y - _peds[ped].queue[2].y, _peds[ped].queue[3].x - _peds[ped].queue[2].x))) - math.abs(math.deg(math.atan2(_peds[ped].queue[2].y - _peds[ped].queue[1].y, _peds[ped].queue[2].x - _peds[ped].queue[1].x))))) )..
  429. "\nneighbours: "..tostring(#_peds[ped].queue > 0 and _peds[ped].queue[1].id and table.size(pathsNodeGetNeighbours(_peds[ped].queue[1].id)))..
  430. "\nflags: "..tostring(#_peds[ped].queue > 0 and _peds[ped].queue[1].flags and table.concatIndex(_peds[ped].queue[1].flags))..
  431. "\ndistance: "..tostring (_peds[ped].distance)..
  432. "\nsyncer: "..tostring(getElementData(veh,"syncer"))..
  433. "\nyou sync: "..tostring(isElementSyncer(veh)),
  434. dx, dy, dx, dy, tocolor ( 255, 255, 255, 255 ), 1.2, "default", "center" )
  435. end
  436. end
  437. end
  438. if isElementSyncer(veh) then
  439. count_local = count_local + 1
  440. end
  441. end
  442. end
  443. end
  444. local areaID = getAreaFromPos ( px, py, pz )
  445. dxDrawText(
  446. "Count: "..tostring(count)..
  447. "\nSynced: "..tostring(count_synced)..
  448. "\nSynced by me: "..tostring(count_local)..
  449. "\nServer by me: "..tostring(getElementData(_local, "vehiclecount"))..
  450. "\nArea ID 256: "..tostring(areaID)..
  451. "\nArea ID 64: "..tostring(math.floor((py+3000)/750)*8+math.floor((px+3000)/750)),
  452. sx - 200, sy / 3 * 2, sx - 200, sy / 3 * 2, tocolor ( 255, 255, 255, 255 ), 1.5 )
  453. -- areas grid
  454. if ( isPlayerMapVisible() ) then
  455. local start = sx / 2 - sy / 2
  456. local width = sy / ( 6000 / AREA_WIDTH )
  457. for i = 1, ( ( 6000 / AREA_HEIGHT ) - 1 ) do
  458. dxDrawLine ( start + i * width, 0, start + i * width, sy, tocolor ( 0, 0, 255, 200 ) )
  459. dxDrawLine ( start, i * width, start + sy, i * width, tocolor ( 0, 0, 255, 200 ) )
  460. end
  461. end
  462. end
  463. end )
  464. addCommandHandler("shownodes", function(cmd,dist)
  465. dist = tonumber(dist)
  466. if dist then
  467. SHOWNODES = dist
  468. else
  469. SHOWNODES = false
  470. end
  471. end
  472. )
  473. addCommandHandler("nb", function()
  474. local node = pathsNodeFindClosest(getElementPosition(_local))
  475. var_dump(pathsNodeGetNeighbours(node.id,true))
  476. end
  477. )
  478. addCommandHandler("dist", function()
  479. local node = pathsNodeFindClosest(getElementPosition(_local))
  480. outputChatBox("dist to node "..tostring(node.id)..": "..tostring(getDistanceBetweenPoints3D(node.x,node.y,node.z,getElementPosition(_local))))
  481. end
  482. )
  483. addCommandHandler("pos", function()
  484. local node = pathsNodeFindClosest(getElementPosition(_local))
  485. outputChatBox("node "..tostring(node.id)..": " )
  486. end
  487. )
  488. SHOWALLNODES = 70
  489. addEventHandler ( "onClientRender", _root,
  490. function()
  491. if SHOWALLNODES then
  492. local x,y,z = getElementPosition ( _local )
  493. local areaID = math.floor((y+3000)/750)*8+math.floor((x+3000)/750)
  494. local areaIDVeh = getAreaFromPos ( x, y, z )
  495. -- outputChatBox(tostring(areaID))
  496. if not areaID then return end
  497. -- for _, node in pairs (AREA_PATHS[areaIDVeh]) do
  498. -- -- outputChatBox(tostring(getDistanceBetweenPoints3D ( node.x, node.y, node.z, x,y,z )))
  499. -- if getDistanceBetweenPoints3D ( node.x, node.y, node.z, x,y,z ) < SHOWALLNODES then
  500. -- -- dxDrawLine3D( node.x, node.y, node.z, node.x, node.y, node.z+2, tocolor ( 255, 0, 0), 3)
  501. -- local dx, dy = getScreenFromWorldPosition ( node.x, node.y, node.z )
  502. -- if ( dx and dy ) then
  503. -- -- var_dump(node)
  504. -- local neighbours = ""
  505. -- for i,v in pairs(node.neighbours) do
  506. -- neighbours = neighbours..tostring(i).."("..tostring(v)..")"..", "
  507. -- end
  508. -- dxDrawText (
  509. -- "node: "..tostring(node.id)..
  510. -- "\nneighbours: "..tostring(neighbours)..
  511. -- "\nwidth: "..tostring(node.width)..
  512. -- "\nlanes: "..tostring(node.leftlanes).." "..tostring(node.rightlanes)..
  513. -- "\nflags: "..tostring(node.flags and table.concatIndex(node.flags)),
  514. -- dx, dy, dx, dy, tocolor ( 255, 0, 0, 255 ), 1.2, "default", "center" )
  515. -- end
  516. -- end
  517. -- end
  518. if AREA_PATHS_ALL then
  519. for _, node in pairs (AREA_PATHS_ALL[areaID].veh) do
  520. -- outputChatBox(tostring(getDistanceBetweenPoints3D ( node.x, node.y, node.z, x,y,z )))
  521. if getDistanceBetweenPoints3D ( node.x, node.y, node.z, x,y,z ) < SHOWALLNODES then
  522. -- dxDrawLine3D( node.x, node.y, node.z, node.x, node.y, node.z+2, tocolor ( 255, 0, 0), 3)
  523. local dx, dy = getScreenFromWorldPosition ( node.x, node.y, node.z )
  524. if ( dx and dy ) then
  525. -- var_dump(node)
  526. local neighbours = ""
  527. for i,v in pairs(node.nbs) do
  528. neighbours = neighbours..tostring(i).."("..tostring(v)..")"..", "
  529. end
  530. --[[
  531. dxDrawText (
  532. "node: "..tostring(node.id)..
  533. "\nneighbours: "..tostring(neighbours)..
  534. "\nnavinbs: "..tostring(table.concat(node.navinbs,", "))..
  535. "\nwidth: "..tostring(node.width)..
  536. "\nflags: "..tostring(node.flags and table.concatIndex(node.flags)),
  537. dx, dy, dx, dy, tocolor ( 255, 0, 0, 255 ), 1.2, "default", "center" )
  538. --]]
  539. end
  540. end
  541. end
  542. -- for _, node in pairs (AREA_PATHS_ALL[areaID].ped) do
  543. -- if getDistanceBetweenPoints3D ( node.x, node.y, node.z, x,y,z ) < SHOWALLNODES then
  544. -- -- dxDrawLine3D( node.x, node.y, node.z, node.x, node.y, node.z+2, tocolor ( 255, 0, 0), 3)
  545. -- local dx, dy = getScreenFromWorldPosition ( node.x, node.y, node.z )
  546. -- if ( dx and dy ) then
  547. -- -- var_dump(node)
  548. -- local neighbours = ""
  549. -- for i,v in pairs(node.nbs) do
  550. -- neighbours = neighbours..tostring(i).."("..tostring(v)..")"..", "
  551. -- end
  552. -- dxDrawText (
  553. -- "node: "..tostring(node.id)..
  554. -- "\nneighbours: "..tostring(neighbours)..
  555. -- "\nwidth: "..tostring(node.width)..
  556. -- "\ntype: "..tostring(node.type)..
  557. -- "\nflags: "..tostring(node.flags and table.concatIndex(node.flags)),
  558. -- dx, dy, dx, dy, tocolor ( 0, 255, 0, 255 ), 1.2, "default", "center" )
  559. -- end
  560. -- end
  561. -- end
  562. for _, node in pairs (AREA_PATHS_ALL[areaID].navi) do
  563. if getDistanceBetweenPoints2D ( node.x, node.y, x,y ) < SHOWALLNODES then
  564. -- dxDrawLine3D( node.x, node.y, node.z, node.x, node.y, node.z+2, tocolor ( 255, 0, 0), 3)
  565. -- local gz = getGroundPosition(node.x, node.y, z + 10)
  566. local next = AREA_PATHS_ALL[math.floor(node.nb/4095)].veh[node.nb]
  567. local dx, dy = getScreenFromWorldPosition ( node.x, node.y, next.z)
  568. if ( dx and dy ) then
  569. -- dxDrawLine3D(node.x, node.y, gz+0.5, node.x+(node.dirx/100), node.y+(node.diry/100), gz+0.5, tocolor (255,255,255), 3)
  570. --dxDrawLine3D(node.x, node.y, next.z+1, next.x, next.y, next.z+1, tocolor ( 255, 0, 255), 12)
  571. local lanes = tostring(node.leftlanes).." "..tostring(node.rightlanes)
  572. -- if node.dy > 0 then
  573. -- lanes = tostring(node.rightlanes).." "..tostring(node.leftlanes).." changed"
  574. -- end
  575. --[[
  576. dxDrawText (
  577. "node: "..tostring(node.id)..
  578. "\nattached to id: "..tostring(node.nb)..
  579. "\ndx,dy: "..tostring(node.dx).." "..tostring(node.dy)..
  580. "\nwidth: "..tostring(node.width)..
  581. "\nlanes: "..lanes..
  582. "\ntrafficLight: "..tostring(node.trafficlight),
  583. dx, dy, dx, dy, tocolor ( 0, 255, 0, 255 ), 1.2, "default", "center" )
  584. --]]
  585. end
  586. end
  587. end
  588. end
  589. end
  590. end
  591. )
  592. addCommandHandler("showallnodes", function(cmd,dist)
  593. dist = tonumber(dist)
  594. if dist then
  595. SHOWALLNODES = dist
  596. else
  597. SHOWALLNODES = false
  598. end
  599. end
  600. )