xFutte / futte-newspaper

[QBCore] Newspaper script displaying news, prison sentences, and enables reporters to write, update and delete news
MIT License
77 stars 48 forks source link
fivem fivem-roleplay lua newspaper qbcore reporter svelte

Newspaper script for QBCore

CodeFactor

This newspaper resource will add a newspaper functionality to your beautiful QBCore FiveM server.

This resource supports:

I'll offer support in my Discord server.

Preview

Opening newspaper More screenshots

Dependencies

Implementation

  1. Run the attached import.sql file in the database.
  2. 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
  3. Add the newspaper.png image into your qb-inventory folder, where all the other images are located (located in the root of the repo).
  4. 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'},

Pickle Prison support

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

:bulb: Initially there will be a "Welcome.." story. As soon as you add your first story the "Welcome.." story will delete itself.

Development

  1. 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.'
  2. Run npm run dev in ./web to compile the GUI.

:bulb: When you are done working with the resource run npm run build to minify and uglify the resource to decrease the resource size.

Configuration

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