Files
jim_bridge/README.md

559 lines
17 KiB
Markdown
Raw Normal View History

2024-02-09 16:49:29 +00:00
# Jim_Bridge
This script is intended to be used with my all my scripts (soon)
It was started due to wanting to bring the same features from some scripts into others with minimal work and multiple updates
- Having certain functions in one place(this script) makes it easier to update, enchance and fix things
- This brings the possibility of branching to mutliple frameworks as I've added some already:
- `"qb-core"`
- `"qbx-core"`
- `"ox_core"`
- `"es_extended"` (requires ox_lib and ox_inventory)
All the next updates of my scripts will use this script and be added as a dependancy
------
It was a tough decision to put it up on github instead of tebex and encrypted
But I want this script to grow with help of others who know more about other cores
---
The installation of this script is simple
- REMOVE `-main` from the folder name, like any other github hosted script
- it just needs to start before any script that requires it
- it can start before core scripts if you want
- for `qb-core` I personally place this script in `resources > [standalone]`
2024-02-09 16:49:29 +00:00
---
### Support for different exports and scripts
In exports.lua is the list of script folder names
This is for people who have customised/renamed scripts
eg. for people who use `ps-inventory`, this is mainly based on qb-inventory
so you need to rename
```lua
QBInv = "qb-inventory",
```
to
```lua
QBInv = "ps-inventory",
```
This will now use events from `ps-inventory` and use it through out the scripts.
# WIP
## Documentation
2024-02-09 17:02:45 +00:00
This script brings alot of features to simplify making scripts with preset functions and automations.
2024-02-09 16:49:29 +00:00
It attempts to make use of configs from the scripts its loaded into. For example:
### `Config`
```lua
Config = {
System = {
Debug = true, -- This enables Debug mode
-- Revealing debug prints and debug boxes on targets
Menu = "qb", -- This specifies what menu script will be loaded
-- "qb" = `qb-menu` and edited versions of it
-- "ox" = `ox_lib`'s context menu system
-- "gta" = `WarMenu' a free script for a gta style menu
Notify = "gta", -- This allows you to choose the notification system for scripts
-- "qb" = `qb-core`'s built in notifications
-- "ox" = `ox_lib`'s built in notifications
-- "esx" = `esx_notify` esx's default notifications
-- "okok" = `okok-notify` okok's notifications
-- "gta" = Native GTA style popups
drawText = "gta", -- The style of drawText you want to use
-- "qb" = `qb-core`'s drawText system
-- "ox" = `ox_lib`'s drawTextUI system
-- "gta" = Native GTA style popups
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
progressBar = "gta" -- The style of progressBar you want to use
-- "qb" = `qb-core`'s style progressBar
-- "ox" = `ox_lib`'s default progressBar
-- "gta" = Native GTA style "spinner"
},
}
```
### `openMenu(Menu, data)`
This handles creation of menus using `OX_Lib`, `qb-menu` or `WarMenu`
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
It uses mixed/new functions to bring more compatability to one another
`Menu` is your button entries and works like qb-menu or ox_lib, for example:
```lua
local Menu = {}
Menu[#Menu + 1] = {
isMenuHeader = true, -- This makes the current button unclickable
icon = invImg("lockpick") -- Supports fontawesome or custom images
-- This example use the custom function `invImg()` to retreive an nui:// link to the given item's image
arrow = true, -- Adds a arrow icon to the button (in qb-menu overrides the icon)
header = "Header Test", -- The header/title for the button
txt = "Text test", -- The txt/description for the button
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
onSelect = function() -- This brings the onSelect function to qb-menu
TriggerEvent("lolhi", { lol = hi }),
end,
-- Enter what happens when you click the button
}
```
As you can see above, it mixes variables but makes it possible to switch between menus just by changing the config option
After you have created the info above, you need to then trigger opening of this menu with:
```lua
openMenu(Menu, -- Menu here is your table name you created above
{ -- Next entry in openMenu is a table
header = "Menu Header", -- What your menu title will be shown as
headertxt = "Header info", -- Info to be displayed under the title
onExit = function() -- Will create a "Close button"
TriggerEvent("lolhi", { lol = hi }),
end, -- When clicked it will trigger the onExit event
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
onBack = function() -- Will create a "Back button"
TriggerEvent("lolhi", { lol = hi }),
end, -- When clicked it will trigger the onBack event
})
```
### Support for multiple target events
These automatically detect what target script you are using
2024-02-09 17:02:45 +00:00
They are also automatically removed when the script is stopped (for helping optimization)
2024-02-09 16:49:29 +00:00
### `createEntityTarget(entity, opts, dist)`
Create an entity based target
```lua
createEntityTarget(
entity, -- The entity ID of what you want to target
{
{ -- Your target options here
icon = "icon", -- Your icon, only supports font awesome icons
label = "Test Label", -- The label of your target
item = "lockpick" -- The required it em
job = "mechanic", -- The required job
gang = "lostmc", -- The required gang
action = function() -- What happens when the target is selected
TriggerEvent("lolhi", { lol = hi }),
end,
},
}
, dist) -- How close you ned to be to see the target
```
### `createBoxTarget(data, opts, dist)`
Create an entity based target
```lua
createBoxTarget(
{
"TargetName", -- The name/id of your target here
vec3(0, 0, 0), -- The coordinates of your target
2.0, -- The width of your target box
2.0, -- The depth of your target box
2024-02-09 17:02:45 +00:00
{
2024-02-09 16:49:29 +00:00
name = "TargetName", -- The name/id of your target here
heading = 200.0, -- The direction your target will be placed
debugPoly = true, -- Wether to show debug boxes to help place targets
minZ = 190.0, -- The bottom of your box
maxZ = 210.0, -- The top of your box
},
},
{
{ -- Your target options here
icon = "icon", -- Your icon, only supports font awesome icons
label = "Test Label", -- The label of your target
item = "lockpick" -- The required it em
job = "mechanic", -- The required job
gang = "lostmc", -- The required gang
action = function() -- What happens when the target is selected
TriggerEvent("lolhi", { lol = hi }),
end,
},
},
dist) -- How close you ned to be to see the target
```
### `createCircleTarget(data, opts, dist)`
Create an entity based target
```lua
createCircleTarget(
{
"TargetName", -- The name/id of your target here
vec3(0, 0, 0), -- The coordinates of your target
2.0, -- The radius of your target circle
2024-02-09 17:02:45 +00:00
{
2024-02-09 16:49:29 +00:00
name = "TargetName", -- The name/id of your target here
heading = 200.0, -- The direction your target will be placed
debugPoly = true, -- Wether to show debug boxes to help place targets
minZ = 190.0, -- The bottom of your box
maxZ = 210.0, -- The top of your box
},
},
{
{ -- Your target options here
icon = "icon", -- Your icon, only supports font awesome icons
label = "Test Label", -- The label of your target
item = "lockpick" -- The required it em
job = "mechanic", -- The required job
gang = "lostmc", -- The required gang
action = function() -- What happens when the target is selected
TriggerEvent("lolhi", { lol = hi }),
end,
},
},
dist) -- How close you ned to be to see the target
```
### `removeEntityTarget(entity)`
Triggers removal of the target entity, by checking the entity name
### `removeZoneTarget(target)`
Triggers removal of a zone(Box/Circle) target by calling the target's name/id
2024-02-09 17:02:45 +00:00
### `triggerNotify(title, message, type, src)`
2024-02-09 16:49:29 +00:00
Handles notifications for the script called from either the server or client
Supports:
- `okok`
- `qb`
- `ox`
- `gta`
- `esx`
```lua
triggerNotify(
title = "Notification Title", -- Usually 'nil' in my scripts, supports notifications with titles
message = "Notification Message", -- The notification's message
type = "success" -- The type of notification, depends on the supporting script
src = 1, -- If in the server, this is required to send to player
)
```
2024-02-09 17:02:45 +00:00
### `drawText(image, input, style)`
2024-02-09 16:49:29 +00:00
This handles calling drawText functions
Supports:
- `gta`
- `qb`
- `ox`
- `esx`
```lua
2024-02-09 17:02:45 +00:00
drawText(
187, -- Very specific for adding blip images to drawtexts, usually nil
2024-02-09 16:49:29 +00:00
{
"Line 1", -- Supports multiple lines, helpful for displaying button prompts
"Line 2",
},
"g" -- Sets colour of text after a ":" when using GTA drawtext
)
```
2024-02-09 17:02:45 +00:00
### `hideText()`
2024-02-09 16:49:29 +00:00
Simply used to hide drawText prompts when not needed anymore
2024-02-09 17:02:45 +00:00
### `createCallback(callbackName, funct)`
2024-02-09 16:49:29 +00:00
This is my attempt at making multiframework server callbacks by using their provided events
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
(Only works server side)
```lua
createCallback(
"jimsCallback", -- Callback event name, needs to be something that isn't already set
function()
end)
end
```
2024-02-09 17:02:45 +00:00
### `triggerCallback(callBackName, value)`
2024-02-09 16:49:29 +00:00
This is an attempt at a mutliframework callback
2024-02-09 17:02:45 +00:00
### `onPlayerLoaded(func)`
2024-02-09 16:49:29 +00:00
This is a multiframework event that is triggered when a player has fully loaded their character in
```lua
onPlayerLoaded(
function()
print("Player Loaded In!")
end
)
```
2024-02-09 17:02:45 +00:00
### `createInput(title, opts)`
2024-02-09 16:49:29 +00:00
2024-02-09 17:02:45 +00:00
### `searchCar(vehicle)`
2024-02-09 16:49:29 +00:00
This function was made for `jim-mechanic` but can be used in other instances
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
I searches the model name of a currently spawned vehicle and retrieves info about it
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
It is smart, in terms of, if you use this multiple times it reteives the previously found info instead of searching again
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
It retrieves data from your vehicles.lua/database:
- `name` for example: "Zentorno Pegassi"
- `price` for example: 100000
- `class` this converts the class number to a String, for example: if the class is 10 it converts this to "Off-road"
2024-02-09 17:02:45 +00:00
### `getVehicleProperties(vehicle)`
2024-02-09 16:49:29 +00:00
Gets the current properties of the vehicle in a table
2024-02-09 17:02:45 +00:00
### `setVehicleProperties(vehicle, props)`
2024-02-09 16:49:29 +00:00
Set's the vehicles properites using the `props` table provided
2024-02-09 17:02:45 +00:00
### `checkDifferences(vehicle, newProps)`
This function is used by `setVehicleProperties`
2024-02-09 16:49:29 +00:00
It determine's what differences there are between the current vehicle and the new set of properites
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
If there are differences, return `true`
2024-02-09 17:02:45 +00:00
### `RegisterNetEvent(GetCurrentResourceName()..":server:ChargePlayer", function(cost, type, newsrc)`
2024-02-09 16:49:29 +00:00
This event is made to REMOVE money from a player
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
It can be called from client with `TriggerServerEvent`
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
Also can be called from server with `TriggerEvent` and a source id in `newsrc`
2024-02-09 17:02:45 +00:00
The name of the event uses `GetCurrentResourceName()` so it doesn't double up results with other scripts
2024-02-09 16:49:29 +00:00
```lua
cost = 100 -- The amount of money to be removed
type = "cash" or "card" -- The type of money that should be removed
newsrc = 1 -- The source of the player, must be nil if calling from client
```
2024-02-09 17:02:45 +00:00
## `RegisterNetEvent(GetCurrentResourceName()..":server:FundPlayer", function(fund, type, newsrc)`
2024-02-09 16:49:29 +00:00
This event is made to ADD money from a player
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
It can be called from client with `TriggerServerEvent`
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
Also can be called from server with `TriggerEvent` and a source id in `newsrc`
2024-02-09 17:02:45 +00:00
The name of the event uses `GetCurrentResourceName()` so it doesn't double up results with other scripts
2024-02-09 16:49:29 +00:00
```lua
fund = 100 -- The amount of money to be added
type = "cash" or "card" -- The type of money that should be added
newsrc = 1 -- The source of the player, must be `nil` if calling from client
```
2024-02-09 17:02:45 +00:00
### `createUseableItem(item, funct)`
2024-02-09 16:49:29 +00:00
This is a server side event to make an item usable
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
Note: If using ox-inv and the item info has event info, this will be ignored
```lua
createUseableItem(
"lockpick", -- The item you want to make usable
function(source, item)
TriggerClientEvent("lolhi", source, { lol = item.name }),
end
)
```
2024-02-09 17:02:45 +00:00
### `hasJob(job, source, grade)`
2024-02-09 16:49:29 +00:00
This is an event that makes checking if the player has the requested job simple
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
It works both client side and server side
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
returns `true` or `false` and if they are on duty or not
```lua
local hasjob, duty =
hasJob(
"mechanic", -- the job role
1, -- the source id of the player, set to nil if on client
3, -- the required grade of the player, can be nil to check job
)
```
2024-02-09 17:02:45 +00:00
### `getPlayer(source)`
2024-02-09 16:49:29 +00:00
This retrieves basic info of the player
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
works client side and server side
Retrieves:
- Players Name
- Players Current Cash
- Players Current Bank Balance
```lua
local PlayerInfo =
getPlayer(
2024-02-09 17:02:45 +00:00
1 -- The
2024-02-09 16:49:29 +00:00
)
print(json.encode(PlayerInfo, { indent = true })
```
2024-02-09 17:02:45 +00:00
### `registerCommand(command, options)`
This is a server side event that uses
2024-02-09 16:49:29 +00:00
- `ox_lib`'s - `lib.addCommand`
- `qb-core`'s - `QBCore.Commands.Add`
Example:
```lua
registerCommand(
"hello", -- /hello the command to be used
"Print 'hello world'", -- text to show in chat
{ name = "lol", help = "hi }, -- Help text for the command
false,
function() -- Function to be ran when the command is triggered
print("Hello World")
end,
"admin", -- the restriction, can be nil
)
```
2024-02-09 17:02:45 +00:00
### `invImg(item)`
2024-02-09 16:49:29 +00:00
This is used mainly for menu's to retrieve the item images
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
It detects what inventory you are using and automatically generates an `nui://` link
```lua
local imgLink = invImg("lockpick")
print(imgLink)
```
2024-02-09 17:02:45 +00:00
### `registerStash(name, label, slots, weight)`
2024-02-09 16:49:29 +00:00
This is a serverside function used to register a new stash in `ox_inventory` and `qs-inventory`
```lua
registerStash(
"newStash", -- The stash name/ID, this is used to open it later
"New created Stash", -- The name of the stash that shows in inventories
50, -- The amount of slots in the inventory
4000000, -- The max weight in the inventory
)
```
2024-02-09 17:02:45 +00:00
### `loadModel(model)`
2024-02-09 16:49:29 +00:00
This loads the requested model into the memory cache to help spawning of props
- Checks if the model exists in the server
- Attempts to load the model with a timeout, if not loaded, sends warning
2024-02-09 17:02:45 +00:00
### `unloadModel(model)`
2024-02-09 16:49:29 +00:00
This unloads a model to help clear the memory cache and help optimization
- Recommended to run after spawning a prop
2024-02-09 17:02:45 +00:00
### `loadAnimDict(animDict)`
2024-02-09 16:49:29 +00:00
This loads the requested animDict into the memory cache to help loading anims
- Checks if the dict exists in the server
2024-02-09 17:02:45 +00:00
### `unloadAnimDict(animDict)`
2024-02-09 16:49:29 +00:00
This unloads the animDict to help clear the memory cache and help optimization
- Recommended to run after running an animation
2024-02-09 17:02:45 +00:00
### `loadPtfxDict(ptFxName)`
2024-02-09 16:49:29 +00:00
This loads the requested ptFx dict into the memory cache to help loading particle effects
- Skips if the effect is alredy loaded
2024-02-09 17:02:45 +00:00
### `unloadPtfxDict(dict)`
2024-02-09 16:49:29 +00:00
This unloads a particle effect to help clear the memory cache and help optimization
- Recommended to run after running an ptfx
2024-02-09 17:02:45 +00:00
### `loadTextureDict(dict)`
2024-02-09 16:49:29 +00:00
This loads the requested texture dictionary into memory
2024-02-09 17:02:45 +00:00
### `countTable(table)`
2024-02-09 16:49:29 +00:00
This is a simple function to count how many entires are in a table, for if your table keys aren't numbered
```lua
local table = {
["tableentry"] = true,
["anotherentry"] = true,
}
print("countTable", countTable(table))
```
2024-02-09 17:02:45 +00:00
### `pairsByKeys(t)`
2024-02-09 16:49:29 +00:00
Searches through a table alphabetically instead of randomly
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
This is an optional function made to replace:
```lua
for k, v in pairs(table) do end
```
with:
```lua
for k, v in pairsByKeys(table) do end
```
2024-02-09 17:02:45 +00:00
### `playAnim(animDict, animName, duration, flag, ped)`
2024-02-09 16:49:29 +00:00
A simplified version of `TaskPlayAnim()`
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
Has some settings already set and basic ones ready to change
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
Loads the animDict automatically with `loadAnimDict()`
```lua
playAnim(
animDict, -- The animation dictionary
animName, -- The animation's name
duration, -- How far into the animation it should stop
flag, -- The animation flag
ped, -- Optional, for if you want any one other than the player to do the animation
)
```
2024-02-09 17:02:45 +00:00
### `stopAnim(animDict, animName, ped)`
2024-02-09 16:49:29 +00:00
Similar to `StopAnimTask()`
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
Made to stop the given animation with being able to choose which ped
```lua
stopAnim(
animDict, -- The animation dictionary
animName, -- The animation's name
ped, -- Optional, for if you want any one other than the player to do the animation
)
```
2024-02-09 17:02:45 +00:00
### `makeVeh(model, coords)`
2024-02-09 16:49:29 +00:00
2024-02-09 17:02:45 +00:00
### `makePed(model, coords, freeze, collision, scenario, anim, synced)`
2024-02-09 16:49:29 +00:00
2024-02-09 17:02:45 +00:00
### `makeProp(data, freeze, synced)`
2024-02-09 16:49:29 +00:00
2024-02-09 17:02:45 +00:00
### `instantLookEnt(ent, ent2)`
2024-02-09 16:49:29 +00:00
This function forcibly changes `ent`'s heading to face `ent2`
Helpful for animations
2024-02-09 17:02:45 +00:00
### `lookEnt(entity)`
2024-02-09 16:49:29 +00:00
This function attempts to slowly turn the player to the given entity/coords
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
Accepts either a `entity ID` or `vector3`
2024-02-09 17:02:45 +00:00
### `destroyProp(entity)`
2024-02-09 16:49:29 +00:00
Attempts to remove a spawned prop
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
If its attached to a player it attempts to to detatch it first
2024-02-09 17:02:45 +00:00
### `pushVehicle(entity)`
2024-02-09 16:49:29 +00:00
This attempts to make the current entity(vehicle) network controlled
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
This helps with syncing it with other players (used in jim-mechanic alot)
2024-02-09 17:02:45 +00:00
### `ensureNetToVeh(vehNetId)`
2024-02-09 16:49:29 +00:00
This was created to get around fivem's warnings of failing to get network objects
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
Although these warnings mean't nothing, it is annoying
2024-02-09 17:02:45 +00:00
2024-02-09 16:49:29 +00:00
This is made to replace the native `NetToVeh()` but checking first if it exists
---