[FREE] [DEV] Postal Maker

Cover Image

Postal Maker

I made this because Im working I was working on a Liberty City server and needed postals, so I decided to try my “coding” skills and make something of my own.

Please remember that this is the “first” actual script I made on my own so that feedback would be much appreciated.

Recommended Nearest Postal Script

Dependencies

ox_lib

Preview

Streamable

Tutorial

  1. Start ox_lib and the script
  2. Once ingame, do /pmake add [postal]
  3. After you’ve collected all your postals do /pmake load
  4. Place your new postals.json in your nearest-postal resource
  5. Change the name of the json in the fxmanifest if needed
  6. Your postals are ready for use

Download

Disclaimer

This script is a dev tool, not just a regular resource.

6 Likes

have any preview?

done :+1:

1 Like

very cool

1 Like

This does not seem to work, I had to enable to lua 54 in fxmanifest to get it to even be compatible with ox_lib so it would stop doing a client error. Now even though there is no console errors the script is saying “postals table is empty” whenever I try to add a postal. Also the load and list commands still require a number code.

1 Like

I fixed it, change this in the client/main.lua:

local currentPostals = {}

local function printTable(table, indent)
    if not indent then indent = 0 end
    for k, v in pairs(table) do
        formatting = string.rep("  ", indent) .. k .. ": "
        if type(v) == "table" then
            print(formatting)
            printTable(v, indent+1)
        else
            print(formatting .. v)
        end
    end
end

local function isEmpty(table)
    for _, _ in pairs(table) do
        return false
    end
    return true
end

RegisterCommand('pmake', function(source, args)
    local type = args[1]
    local code = tonumber(args[2])
    local vaild = lib.table.contains(currentPostals, code)
    local ped = cache.ped
    local coords = GetEntityCoords(ped)
    local empty = isEmpty(currentPostals)           
    if vaild == nil then return TriggerEvent('chat:addMessage', {args = {"ERROR", "Code does not exist"}}) end
    if type == "remove" then
        if not code or code == nil then return TriggerEvent('chat:addMessage', {args = {"ERROR", "Missing 'CODE' value"}}) end

        table.remove(currentPostals, vaild)
        TriggerEvent('chat:addMessage', {args = {"SUCCESS", "Deleted postal: " .. code}})
    elseif type == "add" then
        if not code or code == nil then return TriggerEvent('chat:addMessage', {args = {"ERROR", "Missing 'CODE' value"}}) end

        table.insert(currentPostals, {x = coords.x, y = coords.y, code = code})
        TriggerEvent('chat:addMessage', {args = {"SUCCESS", "Added postal: " .. code}})
    elseif type == "load" then
        if empty then return TriggerEvent('chat:addMessage', {args = {"ERROR", "Postals table is empty"}}) end

        TriggerServerEvent(GetCurrentResourceName() .. ":server:loadPostals", currentPostals)
        TriggerEvent('chat:addMessage', {args = {"SUCCESS", "Loaded postals"}})
    elseif type == "clear" then
        if empty then return TriggerEvent('chat:addMessage', {args = {"ERROR", "Postals table is empty"}}) end

        TriggerEvent('chat:addMessage', {args = {"SUCCESS", "Cleared postals"}})
        for k, v in pairs(currentPostals) do 
            currentPostals[k] = nil 
        end
    elseif type == "list" then
        if empty then return TriggerEvent('chat:addMessage', {args = {"ERROR", "Postals table is empty"}}) end

        printTable(currentPostals, 1)
        TriggerEvent('chat:addMessage', {args = {"SUCCESS", "Printed list of postals in console"}})
    end
end)

TriggerEvent('chat:addSuggestion', '/pmake', 'Postal maker.', {
    { name = "type", help = "Add/Remove/Load/Clear/List" },
    { name = "code", help = "The postal code you would like to delete. (only required if type is add/remove)" }
})

and this in fx manifest:

fx_version 'cerulean'
game 'gta5'
lua54        'yes'

shared_script '@ox_lib/init.lua'

client_script 'source/client/main.lua'

server_script 'source/server/main.lua'

dependency 'ox_lib'

1 Like