Click this button to create a new repository based on this template.
Contact me: https://omikkel.com/discord
- Typescript - https://www.typescriptlang.org/
- NextJS 14 - https://nextjs.org/
- Next-themes - https://www.npmjs.com/package/next-themes
- Tailwindcss - https://tailwindcss.com/
- Redux Toolkit - https://redux-toolkit.js.org/
- FiveM Integration
If you choose to rename the folder fivem-nextjs-example
to something else, make sure to update the NEXT_PUBLIC_RESOURCE_NAME
in the .env
file. in the ui
folder
If you are using vercel to deploy your ui, make sure to update the environment variables in the vercel dashboard
- Clone this repository or download it as a zip file.
- Extract the zip file (if you downloaded it as a zip file).
- Move the folder
fivem-nextjs-example
to your resources folder. - Add
ensure fivem-nextjs-example
to yourserver.cfg
file. - Update ui_page url in
fxmanifest.lua
to your ui deployment url - Edit
config.lua
to your liking. - Start your server.
- Create a new repository from the template button (upper right corner)
- Create a new project on https://vercel.com/new
- Connect your github repository to vercel
- Add the environment variables from
.env
in the vercel dashboard - Deploy your project
- Update ui_page url in
fxmanifest.lua
to your ui deployment url - Start your server.
- Clone this repository or download it as a zip file.
- Extract the zip file (if you downloaded it as a zip file).
- Go to the
ui
folder. - Run
npm install
oryarn install
orpnpm install
to install the dependencies. - Run
npm run build
oryarn build
orpnpm build
to build the project. - Run
npm run start
oryarn start
orpnpm start
to start the project. - Update ui_page url in
fxmanifest.lua
to your ui deployment url - Start your server.
Join your server and press the hotkey (default: H
) to open the menu.
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation - learn about Next.js features and API.
- Learn Next.js - an interactive Next.js tutorial.
You can check out the Next.js GitHub repository - your feedback and contributions are welcome!
-- client.lua
SendNUIMessage({
type = "app/setDisplay", -- Redux type sliceName/reducer
data = true/false, -- Redux payload
})
// state/reducers/app.ts
const appSlice = createSlice({
name: "app", // sliceName
initialState,
reducers: {
// reducer
setDisplay: (state, action: PayloadAction<boolean>) => {
state.display = action.payload; // action.payload is the data from the FiveM client
},
},
});
// app/page.tsx
const getPlayerCount = () => {
// Call FiveM client
nuiCallback("/getPlayerCount", {}, (result: number) => {
setPlayerCount(result); // Set React state
});
};
-- client.lua
RegisterNUICallback("getPlayerCount", function(data, cb)
TriggerServerEvent(cfg.resourceName..":getPlayerCount") -- Ask server for data
RegisterNetEvent(cfg.resourceName..":getPlayerCount")
AddEventHandler(cfg.resourceName..":getPlayerCount", function(count)
cb(count) -- Send server response back to ui
end)
end)
-- server.lua
RegisterServerEvent(cfg.resourceName..":getPlayerCount")
AddEventHandler(cfg.resourceName..":getPlayerCount", function()
TriggerClientEvent(cfg.resourceName..":getPlayerCount", source, GetNumPlayerIndices()) -- Respond to client with player count
end)