lua boxZoneMin is one corner of a rectangle boxZoneMax is the opposite corner of the…
- User
lua
boxZoneMin is one corner of a rectangle boxZoneMax is the opposite corner of the rectangle write a function which would allow me to enter two numbers and it would tell me if its within the rectangle
local boxZoneMin = {-1265.91, -1641.82} local boxZoneMax = {-1263.46, -1665.29}
- Assistant
function isInRectangle(x, y) if x >= boxZoneMin[1] and x <= boxZoneMax[1] and y >= boxZoneMin[2] and y <= boxZoneMax[2] then return true else return false end end
-- Example usage print(isInRectangle(-1265.5, -1660)) -- Output: true print(isInRectangle(-1266, -1670)) -- Output: false
- User
I'm working on a fivem script
boxZoneMin is one corner of a rectangle boxZoneMax is the opposite corner of the rectangle write a function which would allow me to enter two numbers and it would tell me if its within the rectangle
local boxZoneMin = {-1265.91, -1641.82} local boxZoneMax = {-1263.46, -1665.29}
- Assistant
Here's a function that iterates through all players and checks if their coordinates are within the box zone:
function isPlayerInBoxZone(x, y) for _, player in ipairs(GetPlayers()) do local playerCoords = GetEntityCoords(GetPlayerPed(player)) if playerCoords and playerCoords.x >= boxZoneMin[1] and playerCoords.x <= boxZoneMax[1] and playerCoords.y >= boxZoneMin[2] and playerCoords.y <= boxZoneMax[2] then return true end end return false endYou can call this function with the x and y values you want to check:
local x = -1264.2 local y = -1650.5 if isPlayerInBoxZone(x, y) then print("Player is in box zone!") else print("Player is not in box zone.") endThis function assumes that you have created a FiveM server-side script.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.