Skip to content

Commit

Permalink
v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMxrcy committed Apr 3, 2024
0 parents commit 3329f26
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# FiveM 911 Script

911 Script for Community CAD

## Install

- Download the Latest Version
- Rename the folder to `cc-911`
- Drag Into your `resources` Folder
- Start `cc-911`


## Configuration

The resource includes one config file to get you up and running!

### `config.lua`

- `cadURL`: The URL Of Your CAD - Example https://community.communitycad.app
- `api_key`: Your CAD API Key
- `nearestPostalResourceName`: Name of your Neartest Postal Folder Name

## Dependencies

- [`nearest-postal`](https://github.com/DevBlocky/nearest-postal): This resource is required to obtain the nearest postal code. Ensure it is installed and running on your server for the postal code feature to function properly.

## Usage

`/911 <description of the incident>` in your chat box
33 changes: 33 additions & 0 deletions client.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
RegisterCommand('911', function(_, args)
local narrative = table.concat(args, " ") or 'None'

local x, y, z = table.unpack(GetEntityCoords(PlayerPedId(), true))
local streetHash = GetStreetNameAtCoord(x, y, z)
local streetName = GetStreetNameFromHashKey(streetHash)
local zoneName = GetNameOfZone(x, y, z)
local cityName = GetLabelText(zoneName)

local postal = ""
if exports['nearest-postal'] and type(exports['nearest-postal'].getPostal) == "function" then
postal = exports['nearest-postal']:getPostal() or ""
end

local callLocation = "Unknown Location"
if postal ~= "" and streetName ~= "" then
callLocation = postal .. "- " .. streetName
elseif streetName ~= "" then
callLocation = streetName
end

TriggerServerEvent('cc-911:Handle911Call', narrative, callLocation, cityName)
end, false)

TriggerEvent('chat:addSuggestion', '/911', 'Report an incident to emergency services.', {
{ name="description", help="Describe the incident." }
})

RegisterNetEvent('cc-911:CallResponse', function(success, message)
TriggerEvent('chat:addMessage', {
args = {"911 Dispatch", message}
})
end)
7 changes: 7 additions & 0 deletions config.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Config = {}

Config.nearestPostalResourceName = "nearest-postal" -- Your Nearest Postal Name https://github.com/DevBlocky/nearest-postal

Config.cadURL = "https://community.communitycad.app" -- Your CAD URL No Trailng / at the end!

Config.api_key = 'API_KEY' -- Your Community CAD API Key
13 changes: 13 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
fx_version 'cerulean'
game 'gta5'

author 'Mxrcy'
description 'Community CAD 911 Script'
version 'v1.0.0'


shared_script 'config.lua'

client_script 'client.lua'

server_script 'server.lua'
21 changes: 21 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
RegisterNetEvent('cc-911:Handle911Call', function(narrative, callLocation, cityName)
local source = source
local data = {
narrative = narrative,
location = callLocation,
city = cityName,
}

PerformHttpRequest(Config.cadURL .. "/api/v1/fivem/civilian/create_call", function(err, text, headers)
if err == 200 then
print("911 Call processed successfully.")
TriggerClientEvent('cc-911:CallResponse', source, true, "Your 911 call has been received! The authorities are on their way!")
else
print("Error processing 911 call. Error code:", err)
TriggerClientEvent('cc-911:CallResponse', source, false, "There was a problem with your 911 call. Please try again.")
end
end, 'POST', json.encode(data), {
["Content-Type"] = "application/json",
['token'] = Config.api_key
})
end)

0 comments on commit 3329f26

Please sign in to comment.