This newspaper resource will add a newspaper functionality to your beautiful QBCore FiveM server.
This resource supports:
- Buying a newspaper at a newspaper stand
- Viewing news
- Writing, updating & deleting news as a news reporter
- Previewing a story before publishing it
- Display of prison sentences when someone gets sent to jail
- Easy configuration
I'll offer support in my Discord server.
- qb-target
- qb-inventory
- oxmysql
- Run the attached import.sql file in the database.
- Add the following to the
police:server:JailPlayer
event
local name = OtherPlayer.PlayerData.charinfo.firstname.." "..OtherPlayer.PlayerData.charinfo.lastname
exports['futte-newspaper']:CreateJailStory(name, time)
after the line
if not Player or not OtherPlayer or Player.PlayerData.job.name ~= "police" then return end
- Add the newspaper.png image into your qb-inventory folder, where all the other images are located (located in the root of the repo).
- Add following to either your shared.lua or items.lua file based on what version of qb-core you have installed:
['newspaper'] = {['name'] = 'newspaper', ['label'] = 'Newspaper', ['weight'] = 10, ['type'] = 'item', ['image'] = 'newspaper.png', ['unique'] = false , ['useable'] = true, ['shouldClose'] = true, ['combinable'] = nil, ['description'] = 'Los Santos Newspaper'},
if you use Pickle Prison, navigate to pickle_prisons\modules\prison\server.lua
search for
function JailPlayer(source, time, index, noSave)
and replace that whole function with this one
function JailPlayer(source, time, index, noSave)
local Player = QBCore.Functions.GetPlayer(source)
local name = Player.PlayerData.charinfo.firstname.." "..Player.PlayerData.charinfo.lastname
if Prisoners[source] then return end
local index = index or "default"
local prison = Config.Prisons[index]
if not time or not prison then return end
local identifier = GetIdentifier(source)
Prisoners[source] = {
identifier = identifier,
index = index,
time = time,
inventory = TakeInventory(source),
sentence_date = os.time(),
}
SetPlayerMetadata(source, "injail", time)
exports['futte-newspaper']:CreateJailStory(name, time)
TriggerClientEvent("pickle_prisons:jailPlayer", source, Prisoners[source])
if noSave then return end
MySQL.Async.execute("DELETE FROM pickle_prisons WHERE identifier=@identifier;", {["@identifier"] = identifier})
MySQL.Async.execute("INSERT INTO pickle_prisons (identifier, prison, time, inventory, sentence_date) VALUES (@identifier, @prison, @time, @inventory, @sentence_date);", {
["@identifier"] = Prisoners[source].identifier,
["@prison"] = Prisoners[source].index,
["@time"] = Prisoners[source].time,
["@inventory"] = json.encode(Prisoners[source].inventory),
["@sentence_date"] = Prisoners[source].sentence_date,
})
end
💡 Initially there will be a "Welcome.." story. As soon as you add your first story the "Welcome.." story will delete itself.
- Navigate to ./web in a command prompt and run
npm install
to install all dependencies. If you don't already have node.js installed, you can download it here.' - Run
npm run dev
in ./web to compile the GUI.
💡 When you are done working with the resource run npm run build
to minify and uglify the resource to decrease the resource size.
There are quite a lot of configurations possible out-of-the-box. These consists of two files: config.js
and config.lua
.
Config.js
export const Config = {
newspaperTitle: 'Los Santos Newspaper',
tabs: {
showPrisonSentences: true,
showCityNews: false,
},
articles: {
showImage: true,
showTitle: true,
showDate: true,
showPublisher: true,
},
// Set this to a custom year for the publish year if needed. Otherwise it will use the current date
customYear: undefined,
publishArticleControls: [
['bold', 'italic', 'underline', 'strike'],
['blockquote', 'image'],
[{ list: 'ordered' }, { list: 'bullet' }],
],
// Remember to align this with QBShared.Jobs in either shared.lua or jobs.lua (based on what version of qb-core you are using)
reporter: [
{
grade: 0,
canPublish: true,
canEdit: true,
canDelete: true,
},
{
grade: 1,
canPublish: true,
canEdit: true,
canDelete: true,
},
{
grade: 2,
canPublish: true,
canEdit: true,
canDelete: false,
},
{
grade: 3,
canPublish: true,
canEdit: true,
canDelete: true,
},
],
prisonSentences: {
imageUrl:
'https://cdn.realsport101.com/images/ncavvykf/gfinityesports/94d9c2c9e240b6b4e792a705ead0a0d188c1af47-808x455.png?w=686&h=386&auto=format',
imageCaption: 'Bolingbroke Penitentiary',
},
text: {
tabs: {
newspaper: 'Newspaper',
prisonSentences: 'Prison sentences',
reporterActions: 'Reporter actions',
},
prisonSentences: {
title: 'Prison sentences',
noSentencesAvailable: 'No sentences available',
},
reporterActions: {
title: 'Reporter actions',
noPermissions: 'You have no reporter permissions.',
publishNewStory: 'Publish a new story',
updateStories: 'Update stories',
deleteStories: 'Delete stories',
publishStory: {
textareaPlaceholder: 'Article content..',
imagePlaceholder: 'Image URL (Optional)',
titlePlaceholder: 'Title (Required)',
publish: 'Publish',
update: 'Update',
discardChanges: 'Discard changes',
preview: 'Preview',
wrongImageFormat:
'Wrong image format. Either .jpg, .jpeg, .png. .webp, .avif, .gif, or .svg expected',
required: 'Required',
cancel: 'Cancel',
},
},
articles: {
writtenBy: 'Written by',
on: 'on',
latestStories: 'Latest stories',
},
},
};
Config.lua
Config.BuyNewspaperText = 'Buy newspaper' -- Text shown with qb-target
Config.BuyNewspaperIcon = 'fas fa-newspaper' -- Icon shown with qb-target
Config.Price = 100 -- Price of buying the newspaper
Config.AmountOfNews = 10 -- Amount of news to be fetched from the database
Config.AmountOfSentences = 10 -- Amount of prison sentences to be fetched from the database