Skip to main content

Types


PaperContext

FieldTypeDescription
idstringUnique id of the paper
labelstringLabel of the paper
pricenumber?Price of the paper
iconstring?Fontawesome icon to use in menus.
canPublishfunction(source: number): booleanFunction that determines is player allowed to publish article from this paper.
canDeletefunction(source: number): booleanFunction that determines is player allowed to delete article from this paper.
onPurchasedfunction(source: number)?Function that executes when someone purchased a newspaper from this paper.

How to Register Paper?


You can register paper using API.RegisterPaper. You can find default WeazelNews paper in no-newspaper/newspapers/sh_weazelnews.lua You can copy this file and edit variables to create a new paper or you can register paper from another resource using API. API examples can be found in no-newspaper/api/server/examples.lua

Examples


local API = exports["no-newspaper"]
local WeazelNews = API:RegisterPaper({
    id = "weazelnews",
    label = "Weazel News",
    canPublish = function(source)
        local player = ESX.GetPlayerFromId(source)
        return player and player.job.name == "weazelnews"
    end,
    canDelete = function(source)
        local player = ESX.GetPlayerFromId(source)
        return player and player.job.name == "weazelnews"
    end
})
local function PrintArticles(articles)
    for _, article in pairs(articles) do
        print(article.id)
        print(article.header)
        print(article.author)
        print(article.content)
        print(article.image)
        print(article.date)
    end
end
local function PrintAllArticles()
    local articles = WeazelNews:GetAllArticles()
    PrintArticles(articles)
end
local function PrintArticlesByDate(date)
    local articles = WeazelNews:GetArticles(date)
    PrintArticles(articles)
end
RegisterNetEvent("jail:player", function(source, months)
    local player = ESX.GetPlayerFromId(source)
    if not player then return end
    local fullname = player.get("firstname") .. " " .. player.get("lastname")
    WeazelNews:Publish({
        header = "Jail Sentence",
        author = "Bolingbroke Penitentiary",
        content = fullname .. " sentenced for " .. months .. " months in jail!"
    })
end)