Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- inUse = false
- allZone = {}
- debugg = true
- RegisterNetEvent("izone:notification")
- AddEventHandler("izone:notification", function(msg, state)
- if state then
- message = "~g~"..msg
- else
- message = "~r~"..msg
- end
- SetNotificationTextEntry("STRING")
- AddTextComponentString(message)
- DrawNotification(false, false)
- end)
- RegisterNetEvent("izone:okforpoint")
- AddEventHandler("izone:okforpoint", function()
- inUse = true
- end)
- RegisterNetEvent("izone:askforname")
- AddEventHandler("izone:askforname", function()
- local editing = true
- DisplayOnscreenKeyboard(true, "FMMC_KEY_TIP8", "", "", "zoneName categorie", "", "", 120)
- while editing do
- Wait(0)
- if UpdateOnscreenKeyboard() == 2 then
- editing = false
- TriggerEvent("izone:notification","Zone/Point non sauvegardé", false)
- end
- if UpdateOnscreenKeyboard() == 1 then
- editing = false
- resultat = GetOnscreenKeyboardResult()
- TriggerEvent("izone:notification", "Zone/Point enregistré", true)
- local result = {}
- for token in string.gmatch(resultat1, "[^%s]+") do
- table.insert(result, token)
- end
- if #result == 2 then
- TriggerServerEvent("izone:savedb", result[1], result[2])
- else
- TriggerEvent("izone:notification", "Merci de rentrer la categorie, avec un espace entre le nom de la zone et la categorie", false)
- end
- end
- end
- end)
- RegisterNetEvent("izone:transfertzones")
- AddEventHandler("izone:transfertzones", function(allZones)
- allZone = allZones
- end)
- Citizen.CreateThread(function()
- TriggerServerEvent('givemezone')
- while true do
- Wait(0)
- if IsControlJustReleased(1, 182) and inUse then
- local x, y, z = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
- TriggerEvent("izone:notification", "Point ajouté ".. "x = "..tostring(math.ceil(x)) .. " y = " .. tostring(math.ceil(y)) .. " z = " .. tostring(math.ceil(z)), true)
- TriggerServerEvent("izone:addpoint", tostring(x), tostring(y), tostring(z))
- Wait(1000)
- --elseif IsControlJustReleased(1, Keys["E"]) and debugg == true then
- -- TriggerEvent("izone:isPlayerInZone", "testizio",function(cb)
- -- Citizen.Trace(tostring(cb))
- -- end)
- --end
- end
- end
- end)
- RegisterNetEvent("izone:isPlayerInZone")
- AddEventHandler("izone:isPlayerInZone", function(zone, cb)
- found = FindZone(zone)
- if not found then
- cb(nil)
- else
- local plyCoords = GetEntityCoords(GetPlayerPed(-1), true)
- local x1, y1, z1 = table.unpack(plyCoords)
- if GetDistanceBetweenCoords(x1, y1, z1, tonumber(allZone[found].gravityCenter.x), tonumber(allZone[found].gravityCenter.y), 1.01, false) < tonumber(allZone[found].longestDistance) then
- local n = windPnPoly(allZone[found].coords, plyCoords)
- if n ~= 0 then
- cb(true)
- else
- cb(false)
- end
- else
- cb(false)
- end
- end
- end)
- RegisterNetEvent("izone:isPointInZone")
- AddEventHandler("izone:isPointInZone", function(xr, yr, zone, cb)
- found = FindZone(zone)
- if not found then
- cb(nil)
- else
- local flag = { x = xr, y = yr}
- if GetDistanceBetweenCoords(xr, yr, 1.01, tonumber(allZone[found].gravityCenter.x), tonumber(allZone[found].gravityCenter.y), 1.01, false) < tonumber(allZone[found].longestDistance) then
- local n = windPnPoly(allZone[found].coords, flag)
- if n ~= 0 then
- cb(true)
- else
- cb(false)
- end
- end
- end
- end)
- RegisterNetEvent("izone:tpToPointZone")
- AddEventHandler("izone:tpToPointZone", function(zone, pointNumber)
- found = FindZone(zone)
- if not found then
- Citizen.Trace("Pas de zone avec ce nom")
- else
- if pointNumber <= #allZone[found].coords then
- local x = allZone[found].coords[pointNumber].x
- local y = allZone[found].coords[pointNumber].y
- local z = allZone[found].coords[pointNumber].z
- TeleportPlayerToCoords(x, y, z)
- else
- Citizen.Trace("Point out of range")
- end
- end
- end)
- RegisterNetEvent("izone:tpToZone")
- AddEventHandler("izone:tpToZone", function(zone)
- found = FindZone(zone)
- if not found then
- Citizen.Trace("Pas de zone avec ce nom")
- else
- local x = allZone[found].coords[1].x
- local y = allZone[found].coords[1].y
- local z = allZone[found].coords[1].z
- TeleportPlayerToCoords(x, y, z)
- end
- end)
- RegisterNetEvent("izone:isPlayerInAnyZone")
- AddEventHandler("izone:isPlayerInAnyZone", function(cb)
- local arrayReturn = {}
- local plyCoords = GetEntityCoords(GetPlayerPed(-1), true)
- local x1, y1, z1 = table.unpack(plyCoords)
- for i=1, #allZone do
- if GetDistanceBetweenCoords(x1, y1, z1, tonumber(allZone[i].gravityCenter.x), tonumber(allZone[i].gravityCenter.y), 1.01, false) < tonumber(allZone[i].longestDistance) then
- local n = windPnPoly(allZone[i].coords, plyCoords)
- if n ~= 0 then
- table.insert(arrayReturn, allZone[i].nom)
- end
- end
- end
- if #arrayReturn == 0 then
- cb(nil)
- else
- cb(arrayReturn)
- end
- end)
- RegisterNetEvent("izone:isPointInAnyZone")
- AddEventHandler("izone:isPointInAnyZone", function(xr, yr, cb)
- local arrayReturn = {}
- local flag = { x = xr, y = yr}
- for i=1, #allZone do
- if GetDistanceBetweenCoords(xr, yr, 1.01, tonumber(allZone[i].gravityCenter.x), tonumber(allZone[i].gravityCenter.y), 1.01, false) < tonumber(allZone[i].longestDistance) then
- local n = windPnPoly(allZone[i].coords, flag)
- if n ~= 0 then
- table.insert(arrayReturn, allZone[i].nom)
- end
- end
- end
- if #arrayReturn == 0 then
- cb(nil)
- else
- cb(arrayReturn)
- end
- end)
- function windPnPoly(tablePoints, flag)
- if tostring(type(flag)) == table then
- py = flag.y
- px = flag.x
- else
- px, py, pz = table.unpack(GetEntityCoords(GetPlayerPed(-1), true))
- end
- local wn = 0
- table.insert(tablePoints, tablePoints[1])
- for i=1, #tablePoints do
- if i == #tablePoints then
- break
- end
- if tonumber(tablePoints[i].y) <= py then
- if tonumber(tablePoints[i+1].y) > py then
- if IsLeft(tablePoints[i], tablePoints[i+1], flag) > 0 then
- wn = wn + 1
- end
- end
- else
- if tonumber(tablePoints[i+1].y) <= py then
- if IsLeft(tablePoints[i], tablePoints[i+1], flag) < 0 then
- wn = wn - 1
- end
- end
- end
- end
- return wn
- end
- function IsLeft(p1s, p2s, flag)
- p1 = p1s
- p2 = p2s
- if tostring(type(flag)) == "table" then
- p = flag
- else
- p = GetEntityCoords(GetPlayerPed(-1), true)
- end
- return ( ((p1.x - p.x) * (p2.y - p.y))
- - ((p2.x - p.x) * (p1.y - p.y)) )
- end
- function TeleportPlayerToCoords(x, y, z)
- local myPly = GetPlayerPed(-1)
- Citizen.Trace("x : " .. tostring(x) .. " y = " .. tostring(y) .. "z = " .. tostring(z))
- Citizen.Trace(tostring(type(x)))
- SetEntityCoords(myPly, tonumber(x), tonumber(y), tonumber(z), 1, 0, 0, 1)
- end
- RegisterNetEvent("izone:tptc")
- AddEventHandler("izone:tptc", function(x, y, z)
- TeleportPlayerToCoords(x,y,z)
- end)
- --RegisterNetEvent("izone:senddebug")
- --AddEventHandler("izone:senddebug", function(allZones)
- -- allZone = allZones
- -- Citizen.Trace(allZone[1].coords[1].x)
- --end)
- function FindZone(zone)
- for i = 1, #allZone do
- if allZone[i].nom == zone then
- return i
- end
- end
- return false
- end
- function TeleportPlayerToCoords(x, y, z)
- local myPly = GetPlayerPed(-1)
- SetEntityCoords(myPly, tonumber(x), tonumber(y), tonumber(z), 1, 0, 0, 1)
- end
- RegisterNetEvent("izone:tptc")
- AddEventHandler("izone:tptc", function(x, y, z)
- TeleportPlayerToCoords(x,y,z)
- end)
- --RegisterNetEvent("izone:senddebug")
- --AddEventHandler("izone:senddebug", function(allZones)
- -- allZone = allZones
- -- Citizen.Trace(allZone[1].coords[1].x)
- --end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement