Skip to content

Commit

Permalink
feat: ESX support + Renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
Mycroft-Studios committed Sep 17, 2022
1 parent abe0cdd commit 0146fa4
Show file tree
Hide file tree
Showing 9 changed files with 122 additions and 51 deletions.
16 changes: 8 additions & 8 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ jobs:

- name: Bundle
run: |
mkdir -p ./temp/npwd_qb_services
cp ./{README.md,fxmanifest.lua,config.lua} ./temp/npwd_qb_services
cp -r ./client ./temp/npwd_qb_services
cp -r ./server ./temp/npwd_qb_services
cp -r ./web ./temp/npwd_qb_services
cd ./temp && zip -r ../npwd_qb_services.zip ./npwd_qb_services
mkdir -p ./temp/npwd_services
cp ./{README.md,fxmanifest.lua,config.lua} ./temp/npwd_services
cp -r ./client ./temp/npwd_services
cp -r ./server ./temp/npwd_services
cp -r ./web ./temp/npwd_services
cd ./temp && zip -r ../npwd_services.zip ./npwd_services
- name: Create Release
uses: "marvinpinto/action-automatic-releases@v1.2.1"
id: auto_release
with:
repo_token: "${{ secrets.GITHUB_TOKEN }}"
title: NPWD QB Services App | ${{ steps.get_tag.outputs.VERSION_TAG }}
title: NPWD Services App | ${{ steps.get_tag.outputs.VERSION_TAG }}
prerelease: false
files: npwd_qb_services.zip
files: npwd_services.zip

env:
CI: false
Expand Down
29 changes: 21 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,27 @@
# NPWD App for QB Services. Requires NPWD 1.5.0 or higher.
<h1 align='center'>[NPWD] Services App</a></h1><p align='center'><b><a href='https://discord.gg/uy5N7jT5aJ'>Discord</a> - <a href='https://github.com/project-error'>Github</a> - <a href='https://projecterror.dev/docs/'>Documentation</a></b></h5>
~
External NPWD app for Calling Services.

### Make sure you have OxMyql
Framework is automatically detected for ESX and QBCore

![preview](https://user-images.githubusercontent.com/97451137/184982211-754f223f-8163-44ac-8b11-b7b07fece10c.png)

## Requirements

- NPWD (1.5.0 or higher)
- oxmysql
- ESX *or* QBcore

## Install
1. Download the `npwd_qb_services.zip` from releases. DO NOT CHANGE THE RESOURCE NAME. If you want to change it, you'll have to download the source code, alter `fetchNui.ts`, and build the project.
1. Download the `npwd_services.zip` from releases. DO NOT CHANGE THE RESOURCE NAME. If you want to change it, you'll have to download the source code, alter `fetchNui.ts`, and build the project.
2. Unzip and add the resource to your server resources folder
3. Ensure `npwd_qb_services` BEFORE `npwd`
4. Add app to NPWD config.json in the `apps` section `"apps": ["npwd_qb_services]`

## Preview
![7eb7fcc02058624e3cdfb2d2514d59ac](https://user-images.githubusercontent.com/97451137/184982211-754f223f-8163-44ac-8b11-b7b07fece10c.png)
3. Ensure `npwd_services` BEFORE `npwd`
4. Add app to NPWD config.json in the `apps` section `"apps": ["npwd_services]`

#### PS: thanks chip cuz I stole half of it from esx app

# Credits

- chip (most of it from esx app)
- Mycroft (Conveting to ESX)

49 changes: 39 additions & 10 deletions client/client.lua
Original file line number Diff line number Diff line change
@@ -1,13 +1,42 @@
RegisterNUICallback("npwd:qb-services:getPlayers", function(_, cb)
TriggerServerEvent("npwd:qb-services:getPlayers")
RegisterNetEvent("npwd:qb-services:sendPlayers", function(players)
cb({ status = "ok", data = players })
local isESX = GetResourceState("es_extended") ~= "missing"
local isQB = GetResourceState("qb-core") ~= "missing"
local FrameworkObj = {}
if isESX and isQB then
print("[ERROR] You are using both ESX and QB-Core, please remove one of them.")
elseif isESX then
FrameworkObj = exports["es_extended"]:getSharedObject()
elseif isQB then
FrameworkObj = exports["qb-core"]:GetCoreObject()
end

if isESX then
RegisterNUICallback("npwd:services:getPlayers", function(_, cb)
FrameworkObj.TriggerServerCallback("npwd:services:getPlayers", function(PlayerList)
cb({ status = "ok", data = PlayerList })
end)
end)


RegisterNUICallback("npwd:services:callPlayer", function(data, cb)
-- print(data.job) job of player being called
exports.npwd:startPhoneCall(tostring(data.number))
cb({})
end)
end)
end

if isQB then
RegisterNUICallback("npwd:services:getPlayers", function(_, cb)
TriggerServerEvent("npwd:services:getPlayers")
RegisterNetEvent("npwd:services:sendPlayers", function(players)
cb({ status = "ok", data = players })
end)
end)


RegisterNUICallback("npwd:services:callPlayer", function(data, cb)
-- print(data.job) job of player being called
exports.npwd:startPhoneCall(tostring(data.number))
cb({})
end)
end

RegisterNUICallback("npwd:qb-services:callPlayer", function(data, cb)
-- print(data.job) job of player being called
exports.npwd:startPhoneCall(tostring(data.number))
cb({})
end)
2 changes: 1 addition & 1 deletion config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Config.Jobs = {
"garbage",
}

Config.ShowOffDuty = false --show players who aren't currently on duty
Config.ShowOffDuty = false --show players who aren't currently on duty (QBcore Only)
69 changes: 49 additions & 20 deletions server/server.lua
Original file line number Diff line number Diff line change
@@ -1,26 +1,55 @@
local QBCore = exports['qb-core']:GetCoreObject()
local isESX = GetResourceState("es_extended") ~= "missing"
local isQB = GetResourceState("qb-core") ~= "missing"
local FrameworkObj = {}
if isESX and isQB then
print("[ERROR] You are using both ESX and QB-Core, please remove one of them.")
elseif isESX then
FrameworkObj = exports["es_extended"]:getSharedObject()
elseif isQB then
FrameworkObj = exports["qb-core"]:GetCoreObject()
end

RegisterNetEvent("npwd:qb-services:getPlayers", function()
local src = source
local players = QBCore.Functions.GetQBPlayers()
local playerList = {}
if isESX then
FrameworkObj.RegisterServerCallback('npwd:services:getPlayers', function(src, cb)
local PlayerList = {}

for jobIndex =1, #Config.Jobs do
local PlayersWithJob = FrameworkObj.GetExtendedPlayers("job", Config.Jobs[jobIndex])
for playerIndex = 1, #PlayersWithJob do
local xPlayer = PlayersWithJob[playerIndex]
local PlayerData = exports.npwd:getPlayerData({source = src})
PlayerList[#PlayerList + 1] = {
name = xPlayer.getName(),
job = xPlayer.job.name,
phoneNumber = PlayerData.phoneNumber,
}
end
end
cb(PlayerList)
end)
end

if isQB then
RegisterNetEvent("npwd:services:getPlayers", function()
local src = source
local players = FrameworkObj.Functions.GetQBPlayers()
local playerList = {}

for i = 1, #players do
if not Config.ShowOffDuty and players[i].PlayerData.job.onduty then
for _, job in pairs(Config.Jobs) do
if job == players[i].PlayerData.job.name then
table.insert(playerList, {
name = players[i].PlayerData.charinfo.firstname .. " " .. players[i].PlayerData.charinfo.lastname,
job = players[i].PlayerData.job.name,
phoneNumber = players[i].PlayerData.charinfo.phone,
})

for i = 1, #players do
if not Config.ShowOffDuty and players[i].PlayerData.job.onduty then
for _, job in pairs(Config.Jobs) do
if job == players[i].PlayerData.job.name then
table.insert(playerList, {
name = players[i].PlayerData.charinfo.firstname .. " " .. players[i].PlayerData.charinfo.lastname,
job = players[i].PlayerData.job.name,
phoneNumber = players[i].PlayerData.charinfo.phone,
})
end
end
end
end
end

TriggerClientEvent('npwd:qb-services:sendPlayers', src, playerList)
end)



TriggerClientEvent('npwd:services:sendPlayers', src, playerList)
end)
end
2 changes: 1 addition & 1 deletion src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const App = (props: AppProps) => {
const isDarkMode = props.theme.palette.mode === 'dark';

useEffect(() => {
fetchNui<ServerPromiseResp<Player[]>>('npwd:qb-services:getPlayers').then((resp) => {
fetchNui<ServerPromiseResp<Player[]>>('npwd:services:getPlayers').then((resp) => {
setPlayers(resp.data);
});
}, []);
Expand Down
2 changes: 1 addition & 1 deletion src/components/PlayersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const PlayersList: React.FC<PlayersListProps> = ({ players, isDarkMode })
};

const handleCallPlayer = (number: string, job: string) => {
fetchNui<ServerPromiseResp>('npwd:qb-services:callPlayer', { number, job }).then((res) => {
fetchNui<ServerPromiseResp>('npwd:services:callPlayer', { number, job }).then((res) => {
console.log(res.data);
});
};
Expand Down
2 changes: 1 addition & 1 deletion src/utils/fetchNui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async function fetchNui<T = any, D = any>(eventName: string, data?: D, mockResp?
}


const resourceName = "npwd_qb_services";
const resourceName = "npwd_services";

const resp = await fetch(`https://${resourceName}/${eventName}`, options);

Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ module.exports = {
},
plugins: [
new ModuleFederationPlugin({
name: 'npwd_qb_services',
name: 'npwd_services',
filename: 'remoteEntry.js',
exposes: {
'./config': './npwd.config',
Expand Down

0 comments on commit 0146fa4

Please sign in to comment.