Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 106 additions & 0 deletions creation/client/BoxZone.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
local function handleInput(useZ, heading, length, width, center)
if not useZ then
local scaleDelta, headingDelta = 0.2, 5
if IsDisabledControlPressed(2, Keys["CTRL"]) then -- ctrl held down
scaleDelta, headingDelta = 0.05, 1
end

if IsDisabledControlJustReleased(2, Keys["MWDOWN"]) then
if IsDisabledControlPressed(2, Keys["LALT"]) then -- alt held down
return heading, length, math.max(0.0, width - scaleDelta), center
end
if IsDisabledControlPressed(2, Keys["SHIFT"]) then -- shift held down
return heading, math.max(0.0, length - scaleDelta), width, center
end
return (heading - headingDelta) % 360, length, width, center
end

if IsDisabledControlJustReleased(2, Keys["MWUP"]) then
if IsDisabledControlPressed(2, Keys["LALT"]) then -- alt held down
return heading, length, math.max(0.0, width + scaleDelta), center
end
if IsDisabledControlPressed(2, Keys["SHIFT"]) then -- shift held down
return heading, math.max(0.0, length + scaleDelta), width, center
end
return (heading + headingDelta) % 360, length, width, center
end
end

local rot = GetGameplayCamRot(2)
center = handleArrowInput(center, rot.z)

return heading, length, width, center
end

function handleZ(minZ, maxZ)
local delta = 0.2
if IsDisabledControlPressed(2, Keys["CTRL"]) then -- ctrl held down
delta = 0.05
end

if IsDisabledControlJustReleased(2, Keys["MWDOWN"]) then
if IsDisabledControlPressed(2, Keys["LALT"]) then -- alt held down
return minZ - delta, maxZ
end
if IsDisabledControlPressed(2, Keys["SHIFT"]) then -- shift held down
return minZ, maxZ - delta
end
return minZ - delta, maxZ - delta
end

if IsDisabledControlJustReleased(2, Keys["MWUP"]) then
if IsDisabledControlPressed(2, Keys["LALT"]) then -- alt held down
return minZ + delta, maxZ
end
if IsDisabledControlPressed(2, Keys["SHIFT"]) then -- shift held down
return minZ, maxZ + delta
end
return minZ + delta, maxZ + delta
end
return minZ, maxZ
end

function boxStart(name, heading, length, width, minHeight, maxHeight)
local center = GetEntityCoords(PlayerPedId())
createdZone = BoxZone:Create(center, length, width, {name = tostring(name)})
local useZ, minZ, maxZ = false, center.z - 1.0, center.z + 3.0
if minHeight then
minZ = center.z - minHeight
createdZone.minZ = minZ
end
if maxHeight then
maxZ = center.z + maxHeight
createdZone.maxZ = maxZ
end
Citizen.CreateThread(function()
LocalPlayer.state:set("PolyZoneCreation", true, true)
while createdZone do
DisableControls()
if IsControlJustPressed(2, Keys["Z"]) then -- Z pressed
useZ = not useZ
if useZ then
createdZone.debugColors.walls = {255, 0, 0}
else
createdZone.debugColors.walls = {0, 255, 0}
end
end
heading, length, width, center = handleInput(useZ, heading, length, width, center)
if useZ then
minZ, maxZ = handleZ(minZ, maxZ)
createdZone.minZ = minZ
createdZone.maxZ = maxZ
end
createdZone:setLength(length)
createdZone:setWidth(width)
createdZone:setHeading(heading)
createdZone:setCenter(center)
Wait(0)
end
LocalPlayer.state:set("PolyZoneCreation", false, true)
end)
end

function boxFinish()
TriggerServerEvent("polyzone:printBox",
{name=createdZone.name, center=createdZone.center, length=createdZone.length, width=createdZone.width, heading=createdZone.offsetRot, minZ=createdZone.minZ, maxZ=createdZone.maxZ})
end
51 changes: 51 additions & 0 deletions creation/client/CircleZone.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
local function handleInput(radius, center, useZ)
local delta = 0.05
-- BlockWeaponWheelThisFrame()
if IsDisabledControlPressed(2, Keys["CTRL"]) then -- ctrl held down
delta = 0.01
end
if IsDisabledControlJustPressed(2, Keys["MWDOWN"]) then
if IsDisabledControlPressed(2, Keys["LALT"]) then -- alt held down
return radius, vector3(center.x, center.y, center.z - delta), useZ
end
return math.max(0.0, radius - delta), center, useZ
end
if IsDisabledControlJustPressed(2, Keys["MWUP"]) then
if IsDisabledControlPressed(2, Keys["LALT"]) then -- alt held down
return radius, vector3(center.x, center.y, center.z + delta), useZ
end
return radius + delta, center, useZ
end

if IsControlJustPressed(2, Keys["Z"]) then -- Z pressed
return radius, center, not useZ
end

local rot = GetGameplayCamRot(2)
center = handleArrowInput(center, rot.z)

return radius, center, useZ
end

function circleStart(name, radius, useZ)
local center = GetEntityCoords(PlayerPedId())
useZ = useZ or false
createdZone = CircleZone:Create(center, radius, {name = tostring(name), useZ = useZ})
Citizen.CreateThread(function()
LocalPlayer.state:set("PolyZoneCreation", true, true)
while createdZone do
DisableControls()
radius, center, useZ = handleInput(radius, center, useZ)
createdZone:setRadius(radius)
createdZone:setCenter(center)
createdZone.useZ = useZ
Wait(0)
end
LocalPlayer.state:set("PolyZoneCreation", false, true)
end)
end

function circleFinish()
TriggerServerEvent("polyzone:printCircle",
{name=createdZone.name, center=createdZone.center, radius=createdZone.radius, useZ=createdZone.useZ})
end
62 changes: 62 additions & 0 deletions creation/client/PolyZone.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
local minZ, maxZ = nil, nil

local function handleInput(center)
local rot = GetGameplayCamRot(2)
center = handleArrowInput(center, rot.z)
return center
end

function polyStart(name)
local coords = GetEntityCoords(PlayerPedId())
createdZone = PolyZone:Create({vector2(coords.x, coords.y)}, {name = tostring(name), useGrid=false})
Citizen.CreateThread(function()
LocalPlayer.state:set("PolyZoneCreation", true, true)
while createdZone do
-- Have to convert the point to a vector3 prior to calling handleInput,
-- then convert it back to vector2 afterwards
lastPoint = createdZone.points[#createdZone.points]
lastPoint = vector3(lastPoint.x, lastPoint.y, 0.0)
lastPoint = handleInput(lastPoint)
createdZone.points[#createdZone.points] = lastPoint.xy
Wait(0)
end
LocalPlayer.state:set("PolyZoneCreation", false, true)
end)
minZ, maxZ = coords.z, coords.z
end

function polyFinish()
TriggerServerEvent("polyzone:printPoly",
{name=createdZone.name, points=createdZone.points, minZ=minZ, maxZ=maxZ})
end

RegisterNetEvent("polyzone:pzadd")
AddEventHandler("polyzone:pzadd", function()
if createdZone == nil or createdZoneType ~= 'poly' then
return
end

local coords = GetEntityCoords(PlayerPedId())

if (coords.z > maxZ) then
maxZ = coords.z
end

if (coords.z < minZ) then
minZ = coords.z
end

createdZone.points[#createdZone.points + 1] = vector2(coords.x, coords.y)
end)

RegisterNetEvent("polyzone:pzundo")
AddEventHandler("polyzone:pzundo", function()
if createdZone == nil or createdZoneType ~= 'poly' then
return
end

createdZone.points[#createdZone.points] = nil
if #createdZone.points == 0 then
TriggerEvent("polyzone:pzcancel")
end
end)
68 changes: 68 additions & 0 deletions creation/client/commands.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
RegisterCommand("pzcreate", function(src, args)
local zoneType = args[1]
if zoneType == nil then
TriggerEvent('chat:addMessage', {
color = { 255, 0, 0},
multiline = true,
args = {"Me", "Please add zone type to create (poly, circle, box)!"}
})
return
end
if zoneType ~= 'poly' and zoneType ~= 'circle' and zoneType ~= 'box' then
TriggerEvent('chat:addMessage', {
color = { 255, 0, 0},
multiline = true,
args = {"Me", "Zone type must be one of: poly, circle, box"}
})
return
end
local name = nil
if #args >= 2 then name = args[2]
else name = GetUserInput("Enter name of zone:") end
if name == nil or name == "" then
TriggerEvent('chat:addMessage', {
color = { 255, 0, 0},
multiline = true,
args = {"Me", "Please add a name!"}
})
return
end
TriggerEvent("polyzone:pzcreate", zoneType, name, args)
end)

RegisterCommand("pzadd", function(src, args)
TriggerEvent("polyzone:pzadd")
end)

RegisterCommand("pzundo", function(src, args)
TriggerEvent("polyzone:pzundo")
end)

RegisterCommand("pzfinish", function(src, args)
TriggerEvent("polyzone:pzfinish")
end)

RegisterCommand("pzlast", function(src, args)
TriggerEvent("polyzone:pzlast")
end)

RegisterCommand("pzcancel", function(src, args)
TriggerEvent("polyzone:pzcancel")
end)

RegisterCommand("pzcomboinfo", function (src, args)
TriggerEvent("polyzone:pzcomboinfo")
end)

Citizen.CreateThread(function()
TriggerEvent('chat:addSuggestion', '/pzcreate', 'Starts creation of a zone for PolyZone of one of the available types: circle, box, poly', {
{name="zoneType", help="Zone Type (required)"},
})

TriggerEvent('chat:addSuggestion', '/pzadd', 'Adds point to zone.', {})
TriggerEvent('chat:addSuggestion', '/pzundo', 'Undoes the last point added.', {})
TriggerEvent('chat:addSuggestion', '/pzfinish', 'Finishes and prints zone.', {})
TriggerEvent('chat:addSuggestion', '/pzlast', 'Starts creation of the last zone you finished (only works on BoxZone and CircleZone)', {})
TriggerEvent('chat:addSuggestion', '/pzcancel', 'Cancel zone creation.', {})
TriggerEvent('chat:addSuggestion', '/pzcomboinfo', 'Prints some useful info for all created ComboZones', {})
end)
Loading