mirror of
https://github.com/jimathy/jim_bridge.git
synced 2026-08-17 05:56:02 +01:00
Remove old files
This commit is contained in:
639
README.md
639
README.md
@@ -1,639 +0,0 @@
|
|||||||
# 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]`
|
|
||||||
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### 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
|
|
||||||
|
|
||||||
This script brings alot of features to simplify making scripts with preset functions and automations.
|
|
||||||
|
|
||||||
It attempts to make use of configs from the scripts its loaded into. For example:
|
|
||||||
|
|
||||||
### `Config`
|
|
||||||
This needs to be in every script that uses it, a `System` table with Debug, Menu, Notify, drawText, progressBar
|
|
||||||
|
|
||||||
This is required to use jim_bridge with your script
|
|
||||||
```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
|
|
||||||
|
|
||||||
|
|
||||||
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`
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
They are also automatically removed when the script is stopped (for helping optimization)
|
|
||||||
### `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
|
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
|
||||||
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
|
|
||||||
|
|
||||||
### `triggerNotify(title, message, type, src)`
|
|
||||||
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
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### `drawText(image, input, style)`
|
|
||||||
This handles calling drawText functions
|
|
||||||
|
|
||||||
Supports:
|
|
||||||
- `gta`
|
|
||||||
- `qb`
|
|
||||||
- `ox`
|
|
||||||
- `esx`
|
|
||||||
|
|
||||||
```lua
|
|
||||||
drawText(
|
|
||||||
187, -- Very specific for adding blip images to drawtexts, usually nil
|
|
||||||
{
|
|
||||||
"Line 1", -- Supports multiple lines, helpful for displaying button prompts
|
|
||||||
"Line 2",
|
|
||||||
},
|
|
||||||
"g" -- Sets colour of text after a ":" when using GTA drawtext
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### `hideText()`
|
|
||||||
Simply used to hide drawText prompts when not needed anymore
|
|
||||||
|
|
||||||
### `createCallback(callbackName, funct)`
|
|
||||||
This is my attempt at making multiframework server callbacks by using their provided events
|
|
||||||
|
|
||||||
(Only works server side)
|
|
||||||
|
|
||||||
```lua
|
|
||||||
createCallback(
|
|
||||||
"jimsCallback", -- Callback event name, needs to be something that isn't already set
|
|
||||||
function()
|
|
||||||
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
```
|
|
||||||
|
|
||||||
### `triggerCallback(callBackName, value)`
|
|
||||||
This is an attempt at a mutliframework callback
|
|
||||||
|
|
||||||
### `onPlayerLoaded(func)`
|
|
||||||
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
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### `createInput(title, opts)`
|
|
||||||
|
|
||||||
### `searchCar(vehicle)`
|
|
||||||
|
|
||||||
This function was made for `jim-mechanic` but can be used in other instances
|
|
||||||
|
|
||||||
I searches the model name of a currently spawned vehicle and retrieves info about it
|
|
||||||
|
|
||||||
It is smart, in terms of, if you use this multiple times it reteives the previously found info instead of searching again
|
|
||||||
|
|
||||||
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"
|
|
||||||
|
|
||||||
### `getVehicleProperties(vehicle)`
|
|
||||||
Gets the current properties of the vehicle in a table
|
|
||||||
- if using qb-core it will default to its version
|
|
||||||
- if not it will attempt to use ox_libs version
|
|
||||||
|
|
||||||
### `setVehicleProperties(vehicle, props)`
|
|
||||||
Set's the vehicles properites using the `props` table provided
|
|
||||||
- if using qb-core it will default to its version
|
|
||||||
- if not it will attempt to use ox_libs version
|
|
||||||
|
|
||||||
### `checkDifferences(vehicle, newProps)`
|
|
||||||
This function is used by `setVehicleProperties`
|
|
||||||
|
|
||||||
It determine's what differences there are between the current vehicle and the new set of properites
|
|
||||||
|
|
||||||
If there are differences, return `true`
|
|
||||||
|
|
||||||
### `RegisterNetEvent(GetCurrentResourceName()..":server:ChargePlayer", function(cost, type, newsrc)`
|
|
||||||
This event is made to REMOVE money from a player
|
|
||||||
|
|
||||||
It can be called from client with `TriggerServerEvent`
|
|
||||||
|
|
||||||
Also can be called from server with `TriggerEvent` and a source id in `newsrc`
|
|
||||||
|
|
||||||
The name of the event uses `GetCurrentResourceName()` so it doesn't double up results with other scripts
|
|
||||||
```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
|
|
||||||
```
|
|
||||||
Examples of use:
|
|
||||||
```lua
|
|
||||||
-- Client
|
|
||||||
TriggerEvent(GetCurrentResourceName()..":server:ChargePlayer", function(1000, "cash")
|
|
||||||
|
|
||||||
-- Server
|
|
||||||
TriggerServerEvent(GetCurrentResourceName()..":server:ChargePlayer", function(1000, "bank", 1)
|
|
||||||
```
|
|
||||||
|
|
||||||
## `RegisterNetEvent(GetCurrentResourceName()..":server:FundPlayer", function(cost, type, newsrc)`
|
|
||||||
This event is made to ADD money from a player
|
|
||||||
|
|
||||||
It can be called from client with `TriggerServerEvent`
|
|
||||||
|
|
||||||
Also can be called from server with `TriggerEvent` and a source id in `newsrc`
|
|
||||||
|
|
||||||
The name of the event uses `GetCurrentResourceName()` so it doesn't double up results with other scripts
|
|
||||||
```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
|
|
||||||
```
|
|
||||||
Examples of use:
|
|
||||||
```lua
|
|
||||||
-- Client
|
|
||||||
TriggerEvent(GetCurrentResourceName()..":server:FundPlayer", function(1000, "cash")
|
|
||||||
|
|
||||||
-- Server
|
|
||||||
TriggerServerEvent(GetCurrentResourceName()..":server:FundPlayer", function(1000, "bank", newsrc)
|
|
||||||
```
|
|
||||||
|
|
||||||
### `createUseableItem(item, funct)`
|
|
||||||
This is a server side event to make an item usable
|
|
||||||
|
|
||||||
Note: If using ox_inv and the items.lua info has event or a `status` section, this will be ignored
|
|
||||||
|
|
||||||
```lua
|
|
||||||
createUseableItem(
|
|
||||||
"lockpick", -- The item you want to make usable
|
|
||||||
function(source, item)
|
|
||||||
TriggerClientEvent("lolhi", source, { lol = item.name }),
|
|
||||||
end
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### `hasJob(job, source, grade)`
|
|
||||||
This is an event that makes checking if the player has the requested job simple
|
|
||||||
|
|
||||||
It works both client side and server side
|
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### `getPlayer(source)`
|
|
||||||
This retrieves basic info of the player
|
|
||||||
|
|
||||||
works client side and server side
|
|
||||||
Retrieves:
|
|
||||||
- Players Name
|
|
||||||
- Players Current Cash
|
|
||||||
- Players Current Bank Balance
|
|
||||||
|
|
||||||
```lua
|
|
||||||
local PlayerInfo =
|
|
||||||
getPlayer(
|
|
||||||
1 -- The
|
|
||||||
)
|
|
||||||
print(json.encode(PlayerInfo, { indent = true })
|
|
||||||
```
|
|
||||||
|
|
||||||
### `registerCommand(command, options)`
|
|
||||||
This is a server side event that uses
|
|
||||||
- `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
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### `invImg(item)`
|
|
||||||
This is used mainly for menu's to retrieve the item images
|
|
||||||
|
|
||||||
It detects what inventory you are using and automatically generates an `nui://` link
|
|
||||||
|
|
||||||
```lua
|
|
||||||
local imgLink = invImg("lockpick")
|
|
||||||
print(imgLink)
|
|
||||||
```
|
|
||||||
|
|
||||||
### `registerStash(name, label, slots, weight)`
|
|
||||||
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
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### `loadModel(model)`
|
|
||||||
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
|
|
||||||
|
|
||||||
### `unloadModel(model)`
|
|
||||||
This unloads a model to help clear the memory cache and help optimization
|
|
||||||
- Recommended to run after spawning a prop
|
|
||||||
|
|
||||||
### `loadAnimDict(animDict)`
|
|
||||||
This loads the requested animDict into the memory cache to help loading anims
|
|
||||||
- Checks if the dict exists in the server
|
|
||||||
|
|
||||||
### `unloadAnimDict(animDict)`
|
|
||||||
This unloads the animDict to help clear the memory cache and help optimization
|
|
||||||
- Recommended to run after running an animation
|
|
||||||
|
|
||||||
### `loadPtfxDict(ptFxName)`
|
|
||||||
This loads the requested ptFx dict into the memory cache to help loading particle effects
|
|
||||||
- Skips if the effect is alredy loaded
|
|
||||||
|
|
||||||
### `unloadPtfxDict(dict)`
|
|
||||||
This unloads a particle effect to help clear the memory cache and help optimization
|
|
||||||
- Recommended to run after running an ptfx
|
|
||||||
|
|
||||||
### `loadTextureDict(dict)`
|
|
||||||
This loads the requested texture dictionary into memory
|
|
||||||
|
|
||||||
### `countTable(table)`
|
|
||||||
This is a simple function to count how many entires are in a table, for if your table keys aren't numbered
|
|
||||||
|
|
||||||
Example:
|
|
||||||
```lua
|
|
||||||
local table = {
|
|
||||||
["tableentry"] = true,
|
|
||||||
["anotherentry"] = true,
|
|
||||||
}
|
|
||||||
print("countTable", countTable(table))
|
|
||||||
```
|
|
||||||
|
|
||||||
### `pairsByKeys(t)`
|
|
||||||
Searches through a table alphabetically instead of randomly
|
|
||||||
|
|
||||||
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
|
|
||||||
```
|
|
||||||
|
|
||||||
### `playAnim(animDict, animName, duration, flag, ped)`
|
|
||||||
A simplified version of `TaskPlayAnim()`
|
|
||||||
|
|
||||||
Has some settings already set and basic ones ready to change
|
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
```
|
|
||||||
|
|
||||||
### `stopAnim(animDict, animName, ped)`
|
|
||||||
Similar to `StopAnimTask()`
|
|
||||||
|
|
||||||
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
|
|
||||||
)
|
|
||||||
```
|
|
||||||
### `makeVeh(model, coords)`
|
|
||||||
Spawns a vehicle for the player to use
|
|
||||||
- Server Synced
|
|
||||||
- Easy creation
|
|
||||||
- Returns entity id for further control through the script
|
|
||||||
- Loads model before spawning
|
|
||||||
- Unloads model from memory cache after spawn
|
|
||||||
|
|
||||||
Example of use:
|
|
||||||
```lua
|
|
||||||
local vehicle = makeVeh(
|
|
||||||
`zentorno`,
|
|
||||||
vec4(-596.74, 2090.99, 131.41, 16.6)
|
|
||||||
)
|
|
||||||
print(vehicle, GetEntityCoords(vehicle))
|
|
||||||
```
|
|
||||||
|
|
||||||
### `makePed(model, coords, freeze, collision, scenario, anim, synced)`
|
|
||||||
Spawns a controllable ped
|
|
||||||
- Loads the model before spawning
|
|
||||||
- Unloads model from memory cache after spawn
|
|
||||||
- Several options for creation
|
|
||||||
- Can spawn with scenario name or anims
|
|
||||||
- Spawns invincible
|
|
||||||
|
|
||||||
Example of use:
|
|
||||||
```lua
|
|
||||||
local ped = makePed(
|
|
||||||
`MP_M_Freemode_011,
|
|
||||||
vec4(-596.74, 2090.99, 131.41, 16.6),
|
|
||||||
true,
|
|
||||||
false,
|
|
||||||
nil,
|
|
||||||
{ "amb@prop_human_parking_meter@male@idle_a", "idle_a" },
|
|
||||||
false
|
|
||||||
)
|
|
||||||
print(ped, GetEntityCoords(ped))
|
|
||||||
```
|
|
||||||
|
|
||||||
### `makeProp(data, freeze, synced)`
|
|
||||||
This function is made to easily load a prop in the world
|
|
||||||
- Has a simplified process
|
|
||||||
- Lodas model before spawning prop
|
|
||||||
- Unloads model from memory cache when done
|
|
||||||
- Returns entity id for control through the script
|
|
||||||
|
|
||||||
Example of use:
|
|
||||||
```lua
|
|
||||||
local entityid = makeProp(
|
|
||||||
{
|
|
||||||
prop = "v_serv_plas_boxgt2", -- Prop model, can be a string or hash key
|
|
||||||
coords = vec4(-596.74, 2090.99, 131.41, 16.6), -- needs to be vector4 or vec4, 4th variable is heading
|
|
||||||
},
|
|
||||||
true, -- Decide if the entiy is frozen in place
|
|
||||||
false -- Does this prop spawn for everyone or just the client
|
|
||||||
)
|
|
||||||
print(entityid, GetEntityCoords(entityid))
|
|
||||||
```
|
|
||||||
|
|
||||||
### `instantLookEnt(ent, ent2)`
|
|
||||||
This function forcibly changes `ent`'s heading to face `ent2`
|
|
||||||
|
|
||||||
Helpful for animations in a specific direction
|
|
||||||
|
|
||||||
### `lookEnt(entity)`
|
|
||||||
This function attempts to slowly turn the player to the given entity/coords
|
|
||||||
|
|
||||||
Accepts either a `entity ID` or `vector3`
|
|
||||||
|
|
||||||
### `destroyProp(entity)`
|
|
||||||
Attempts to remove a spawned prop
|
|
||||||
|
|
||||||
If its attached to a player it attempts to to detatch it first
|
|
||||||
|
|
||||||
### `pushVehicle(entity)`
|
|
||||||
This attempts to make the current entity(vehicle) network controlled
|
|
||||||
|
|
||||||
This helps with syncing it with other players (used in jim-mechanic often)
|
|
||||||
|
|
||||||
### `ensureNetToVeh(vehNetId)`
|
|
||||||
This was created to get around fivem's warnings of failing to get network objects
|
|
||||||
|
|
||||||
Although these warnings mean't nothing, it is annoying
|
|
||||||
|
|
||||||
This is made to replace the native `NetToVeh()` but checking first if it exists
|
|
||||||
|
|
||||||
### `makeBlip(data)`
|
|
||||||
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
635
crafting.lua
635
crafting.lua
@@ -1,635 +0,0 @@
|
|||||||
if IsDuplicityVersion() then
|
|
||||||
if GetResourceState(OXLibExport):find("start") then
|
|
||||||
createCallback(GetCurrentResourceName()..':server:GetStashItems', function(source, stashName) local stash = getStash(stashName) return stash end)
|
|
||||||
else
|
|
||||||
createCallback(GetCurrentResourceName()..':server:GetStashItems', function(source, cb, stashName) local stash = getStash(stashName) cb(stash) end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local timeout, timing, stashItems = 0, false, {}
|
|
||||||
function GetStashTimeout(stashName, stop)
|
|
||||||
if stop then stashItems, timing, timeout = {}, false, 0 return end
|
|
||||||
if #stashItems > 0 then return true end
|
|
||||||
if timeout <= 0 then
|
|
||||||
stashItems = triggerCallback(GetCurrentResourceName()..':server:GetStashItems', stashName)
|
|
||||||
timeout = 10000
|
|
||||||
if not timing then
|
|
||||||
CreateThread(function()
|
|
||||||
timing = true
|
|
||||||
while timeout > 0 do timeout -= 1000 Wait(1000) end
|
|
||||||
timing, stashItems, timeout = false, {}, 0
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local CraftLock = false
|
|
||||||
function craftingMenu(data)
|
|
||||||
if CraftLock then return end
|
|
||||||
if data.stashName and not GetStashTimeout(data.stashName) then
|
|
||||||
--triggerNotify(nil, "Chacking", "success")
|
|
||||||
end
|
|
||||||
if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end
|
|
||||||
local Menu, hasjob = {}, false
|
|
||||||
local Recipes = data.craftable.Recipes
|
|
||||||
local tempCarryTable = {}
|
|
||||||
for i = 1, #Recipes do
|
|
||||||
for k in pairs(Recipes[i]) do
|
|
||||||
if k ~= "amount" and k ~= "job" and k ~= "gang" then
|
|
||||||
tempCarryTable[k] = Recipes[i].amount or 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local canCarryTable = triggerCallback(GetCurrentResourceName()..':server:canCarry', tempCarryTable)
|
|
||||||
for i = 1, #Recipes do
|
|
||||||
if not Recipes[i]["amount"] then Recipes[i]["amount"] = 1 end
|
|
||||||
for k, v in pairs(Recipes[i]) do
|
|
||||||
if k ~= "amount" and k ~= "job" and k ~= "gang" then
|
|
||||||
if Recipes[i].job then
|
|
||||||
for l, b in pairs(Recipes[i].job) do
|
|
||||||
hasjob = hasJob(l, nil, b)
|
|
||||||
if hasjob == true then break end
|
|
||||||
end
|
|
||||||
else hasjob = true end
|
|
||||||
local setheader, settext, disable = "", "", false
|
|
||||||
if hasjob then
|
|
||||||
local itemTable = {}
|
|
||||||
for l, b in pairs(Recipes[i][tostring(k)]) do
|
|
||||||
settext = settext..(settext ~= "" and br or "")..(Items[l] and Items[l].label or "error - "..l)..(b > 1 and " x"..b or "")
|
|
||||||
itemTable[l] = b
|
|
||||||
Wait(0)
|
|
||||||
end
|
|
||||||
while not canCarryTable do Wait(0) end
|
|
||||||
if Config.System.Debug then print("^6Bridge^7: ^2Checking"..(data.stashName and " ^7'^6"..data.stashName.."^7'" or "").." ^2ingredients^7 - ^6"..k.."^7") end
|
|
||||||
if data.stashName then disable = not stashhasItem(stashItems, itemTable)
|
|
||||||
else disable = not hasItem(itemTable) end
|
|
||||||
setheader = (Items[tostring(k)] and Items[tostring(k)].label or "error - " .. tostring(k)) .. (Recipes[i]["amount"] > 1 and " x" .. Recipes[i]["amount"] or "")
|
|
||||||
if not disable then
|
|
||||||
if not canCarryTable[k] then setheader = setheader .. " 📦"
|
|
||||||
else setheader = setheader .. " ✔️" end
|
|
||||||
elseif not canCarryTable[k] then setheader = setheader .. " 📦" end
|
|
||||||
Menu[#Menu + 1] = {
|
|
||||||
isMenuHeader = disable or not canCarryTable[k],
|
|
||||||
icon = invImg(tostring(k)),
|
|
||||||
header = setheader,
|
|
||||||
txt = settext,
|
|
||||||
onSelect = function()
|
|
||||||
local transdata = { item = k, craft = data.craftable.Recipes[i], craftable = data.craftable, coords = data.coords, stashName = data.stashName, onBack = data.onBack, }
|
|
||||||
if Config.Crafting.MultiCraft then multiCraft(transdata) else makeItem(transdata) end
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Wait(0)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
openMenu(Menu, { header = data.craftable.Header, onBack = data.onBack or nil, canClose = true, onExit = function() end, })
|
|
||||||
lookEnt(data.coords)
|
|
||||||
end
|
|
||||||
|
|
||||||
function multiCraft(data) local Menu = {}
|
|
||||||
local success = Config.Crafting.MultiCraftAmounts
|
|
||||||
if data.stashName and not GetStashTimeout(data.stashName) then
|
|
||||||
--triggerNotify(nil, "Refreshing stashinfo", "success")
|
|
||||||
end
|
|
||||||
Menu[#Menu+1] = {
|
|
||||||
isMenuHeader = true,
|
|
||||||
icon = invImg(data.item),
|
|
||||||
header = Items[data.item].label,
|
|
||||||
}
|
|
||||||
for k in pairsByKeys(success) do
|
|
||||||
local settext = ""
|
|
||||||
local itemTable = {}
|
|
||||||
for l, b in pairs(data.craft[data.item]) do
|
|
||||||
itemTable[l] = (b * k)
|
|
||||||
settext = settext..(settext ~= "" and br or "")..Items[l].label..(b*k > 1 and "- x"..b*k or "")
|
|
||||||
Wait(0)
|
|
||||||
end
|
|
||||||
local disable = false
|
|
||||||
if Config.System.Debug then print("^6Bridge^7: ^2Checking "..(data.stashName and "^7'^6"..data.stashName.."^7'" or "inventory").."^7x^5"..k.." ^2ingredients^7 - ^6"..data.item.."^7") end
|
|
||||||
if data.stashName then disable = not stashhasItem(stashItems, itemTable)
|
|
||||||
else disable = not hasItem(itemTable) end
|
|
||||||
|
|
||||||
Menu[#Menu + 1] = {
|
|
||||||
isMenuHeader = disable,
|
|
||||||
arrow = not disable,
|
|
||||||
header = "Craft - x"..k * data.craft.amount,
|
|
||||||
txt = settext,
|
|
||||||
onSelect = function ()
|
|
||||||
makeItem({item = data.item, craft = data.craft, craftable = data.craftable, amount = k, coords = data.coords, stashName = data.stashName, onBack = data.onBack })
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
openMenu(Menu, { header = data.craftable.Header, onBack = function() craftingMenu(data) end, })
|
|
||||||
end
|
|
||||||
|
|
||||||
function makeItem(data)
|
|
||||||
if CraftLock then return end
|
|
||||||
CraftLock = true
|
|
||||||
|
|
||||||
local bartime = data.craftable.progressBar and data.craftable.progressBar.time or 5000
|
|
||||||
local bartext = (data.craftable.progressBar and data.craftable.progressBar.label) or (Loc[Config.Lan].progressbar and Loc[Config.Lan].progressbar["progress_make"]) or "Making a"
|
|
||||||
local animDict = data.craftable.Anims and data.craftable.Anims.animDict or "amb@prop_human_parking_meter@male@idle_a"
|
|
||||||
local anim = data.craftable.Anims and data.craftable.Anims.anim or "idle_a"
|
|
||||||
local amount = data.amount and (data.amount ~= 1) and data.amount or 1
|
|
||||||
|
|
||||||
local crafted, crafting = true, true
|
|
||||||
local cam = createTempCam(PlayerPedId(), data.coords)
|
|
||||||
startTempCam(cam)
|
|
||||||
for i = 1, amount do
|
|
||||||
for k, v in pairs(data.craft) do
|
|
||||||
if k ~= "amount" and k ~= "job" then
|
|
||||||
if type(v) == "table" then
|
|
||||||
for l, b in pairs(v) do
|
|
||||||
if crafting and progressBar({
|
|
||||||
label = "Using "..b.." "..Items[l].label,
|
|
||||||
time = 1000,
|
|
||||||
cancel = true,
|
|
||||||
dict = 'pickup_object',
|
|
||||||
anim = "putdown_low",
|
|
||||||
flag = 48,
|
|
||||||
icon = l,
|
|
||||||
}) then
|
|
||||||
--TriggerEvent('inventory:client:ItemBox', Items[l], "use", b) -- Show item box for each item
|
|
||||||
else
|
|
||||||
crafted, crafting = false, false
|
|
||||||
break
|
|
||||||
end
|
|
||||||
Wait(200)
|
|
||||||
end
|
|
||||||
if crafted then
|
|
||||||
if crafting and progressBar({
|
|
||||||
label = bartext..Items[data.item].label,
|
|
||||||
time = bartime,
|
|
||||||
cancel = true,
|
|
||||||
dict = animDict,
|
|
||||||
anim = anim,
|
|
||||||
flag = 8,
|
|
||||||
icon = data.item,
|
|
||||||
}) then
|
|
||||||
TriggerServerEvent(GetCurrentResourceName()..":Crafting:GetItem", data.item, data.craft, data.stashName)
|
|
||||||
else
|
|
||||||
crafting = false
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
Wait(500)
|
|
||||||
end
|
|
||||||
stopTempCam()
|
|
||||||
CraftLock = false
|
|
||||||
lockInv(false)
|
|
||||||
craftingMenu(data)
|
|
||||||
ClearPedTasks(PlayerPedId())
|
|
||||||
end
|
|
||||||
|
|
||||||
RegisterNetEvent(GetCurrentResourceName()..":Crafting:GetItem", function(ItemMake, craftable, stashName)
|
|
||||||
local src, amount, stashItems = source, craftable and craftable.amount or 1, stashName and getStash(stashName)
|
|
||||||
if stashName then
|
|
||||||
local itemRemove = {}
|
|
||||||
for k, v in pairs(craftable[ItemMake] or {}) do
|
|
||||||
for _, b in pairs(stashItems or {}) do
|
|
||||||
if k == b.name then itemRemove[k] = v end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
stashRemoveItem(stashItems, stashName, itemRemove)
|
|
||||||
else
|
|
||||||
if craftable then
|
|
||||||
for k, v in pairs(craftable[ItemMake] or {}) do
|
|
||||||
TriggerEvent(GetCurrentResourceName()..":server:toggleItem", false, tostring(k), v, src)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
TriggerEvent(GetCurrentResourceName()..":server:toggleItem", true, ItemMake, amount, src)
|
|
||||||
if GetResourceState("core_skills"):find("start") then exports["core_skills"]:AddExperience(src, 2) end
|
|
||||||
end)
|
|
||||||
|
|
||||||
--[[SHOPS]]--
|
|
||||||
function sellMenu(data)
|
|
||||||
local origData = data
|
|
||||||
local Menu = {}
|
|
||||||
if data.sellTable.Items then
|
|
||||||
local itemList = {}
|
|
||||||
for k, v in pairs(data.sellTable.Items) do itemList[k] = 1 end
|
|
||||||
local hasitems, hasTable = hasItem(itemList)
|
|
||||||
for k, v in pairsByKeys(data.sellTable.Items) do
|
|
||||||
Menu[#Menu +1] = {
|
|
||||||
isMenuHeader = not hasTable[k].hasItem,
|
|
||||||
icon = invImg(k),
|
|
||||||
header = Items[k].label.. (hasTable[k].hasItem and "💰 (x"..hasTable[k].count..")" or ""),
|
|
||||||
txt = Loc[Config.Lan].info["sell_all"].." "..v.." "..Loc[Config.Lan].info["sell_each"],
|
|
||||||
onSelect = function()
|
|
||||||
sellAnim({ item = k, price = v, ped = data.ped, onBack = function() sellMenu(data) end })
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
else
|
|
||||||
for k, v in pairsByKeys(data.sellTable) do
|
|
||||||
if type(v) == "table" then
|
|
||||||
Menu[#Menu +1] = {
|
|
||||||
arrow = true,
|
|
||||||
header = k,
|
|
||||||
txt = "Amount of items: "..countTable(v.Items),
|
|
||||||
onSelect = function()
|
|
||||||
v.onBack = function() sellMenu(origData) end
|
|
||||||
v.sellTable = data.sellTable[k]
|
|
||||||
sellMenu(v)
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
openMenu(Menu, { header = data.sellTable.Header or "Amount of items: "..countTable(data.sellTable.Items), canClose = true, onBack = data.onBack })
|
|
||||||
end
|
|
||||||
|
|
||||||
function sellAnim(data)
|
|
||||||
if not hasItem(data.item, 1) then
|
|
||||||
triggerNotify(nil, Loc[Config.Lan].error["dont_have"].." "..Items[data.item].label, "error")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
for k, v in pairs(GetGamePool('CObject')) do
|
|
||||||
for _, model in pairs({`p_cs_clipboard`}) do
|
|
||||||
if GetEntityModel(v) == model then
|
|
||||||
if IsEntityAttachedToEntity(data.ped, v) then
|
|
||||||
DeleteObject(v) DetachEntity(v, 0, 0) SetEntityAsMissionEntity(v, true, true)
|
|
||||||
Wait(100) DeleteEntity(v)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
TriggerServerEvent(GetCurrentResourceName().."Sellitems", data) -- Had to slip in the sell command during the animation command
|
|
||||||
lookEnt(data.ped)
|
|
||||||
local dict = "mp_common"
|
|
||||||
playAnim(dict, "givetake2_a", 0.3, 2)
|
|
||||||
playAnim(dict, "givetake2_b", 0.3, 2, data.ped)
|
|
||||||
Wait(2000)
|
|
||||||
StopAnimTask(PlayerPedId(), dict, "givetake2_a", 0.5)
|
|
||||||
StopAnimTask(data.ped, dict, "givetake2_b", 0.5)
|
|
||||||
if data.onBack then data.onBack() end
|
|
||||||
end
|
|
||||||
|
|
||||||
RegisterNetEvent(GetCurrentResourceName().."Sellitems", function(data)
|
|
||||||
local src = source
|
|
||||||
local hasItems, hasTable = hasItem(data.item, 1, src)
|
|
||||||
if hasItems then
|
|
||||||
TriggerEvent(GetCurrentResourceName()..":server:toggleItem", false, data.item, hasTable[data.item].count, src)
|
|
||||||
TriggerEvent(GetCurrentResourceName()..":server:FundPlayer", (hasTable[data.item].count * data.price), "cash", src)
|
|
||||||
else
|
|
||||||
triggerNotify(nil,Loc[Config.Lan].error["dont_have"].." "..Items[data.item].label, "error", src)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
|
|
||||||
function openShop(data)
|
|
||||||
if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end
|
|
||||||
if GetResourceState(OXInv):find("start") then
|
|
||||||
exports[OXInv]:openInventory('shop', { type = data.shop })
|
|
||||||
else
|
|
||||||
TriggerServerEvent(Config.General.JimShops and "jim-shops:ShopOpen" or "inventory:server:OpenInventory", "shop", data.items.label, data.items)
|
|
||||||
end
|
|
||||||
lookEnt(data.coords)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Client & Server side
|
|
||||||
function hasItem(items, amount, src) local amount = amount and amount or 1
|
|
||||||
local grabInv = nil
|
|
||||||
local foundInv = ""
|
|
||||||
if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end
|
|
||||||
if GetResourceState(OXInv):find("start") then
|
|
||||||
foundInv = OXInv
|
|
||||||
if src then grabInv = exports[OXInv]:GetInventoryItems(src)
|
|
||||||
else grabInv = exports[OXInv]:GetPlayerItems() end
|
|
||||||
|
|
||||||
elseif GetResourceState(QSInv):find("start") then
|
|
||||||
foundInv = QSInv
|
|
||||||
if src then grabInv = exports[QSInv]:GetInventory(src)
|
|
||||||
else grabInv = exports[QSInv]:getUserInventory() end
|
|
||||||
|
|
||||||
elseif GetResourceState(OrigenInv):find("start") then
|
|
||||||
foundInv = OrigenInv
|
|
||||||
if src then grabInv = exports[OrigenInv]:GetInventory(src)
|
|
||||||
else grabInv = exports[OrigenInv]:getPlayerInventory() end
|
|
||||||
|
|
||||||
elseif GetResourceState(CoreInv):find("start") then
|
|
||||||
foundInv = CoreInv
|
|
||||||
if src then
|
|
||||||
if GetResourceState(QBExport):find("start") or GetResourceState(QBXExport):find("start") then
|
|
||||||
grabInv = Core.Functions.GetPlayer(src).PlayerData.items
|
|
||||||
elseif GetResourceState(ESXExport):find("start") then
|
|
||||||
local Player = ESX.GetPlayerFromId(src)
|
|
||||||
grabInv = Player.getInventory(false)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
local p = promise.new()
|
|
||||||
Core.Functions.TriggerCallback('core_inventory:server:getInventory', function(cb) p:resolve(cb) end)
|
|
||||||
local result = Citizen.Await(p)
|
|
||||||
if type(result) == "string" then result = json.decode(result) end
|
|
||||||
grabInv = result
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif GetResourceState(CodeMInv):find("start") then
|
|
||||||
foundInv = CodeMInv
|
|
||||||
if src then grabInv = exports[CodeMInv]:GetUserInventory(src)
|
|
||||||
else grabInv = exports[CodeMInv]:GetClientPlayerInventory() end
|
|
||||||
|
|
||||||
elseif GetResourceState(QBInv):find("start") then
|
|
||||||
foundInv = QBInv
|
|
||||||
if src then grabInv = Core.Functions.GetPlayer(src).PlayerData.items
|
|
||||||
else grabInv = Core.Functions.GetPlayerData().items end
|
|
||||||
|
|
||||||
else
|
|
||||||
print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7")
|
|
||||||
end
|
|
||||||
|
|
||||||
if grabInv then
|
|
||||||
local hasTable = {}
|
|
||||||
for item, amount in pairs(items) do
|
|
||||||
if not Items[item] then print("^4ERROR^7: ^2Script can't find ingredient item in Shared Items - ^1"..item.."^7") end
|
|
||||||
local count = 0
|
|
||||||
for _, itemData in pairs(grabInv) do
|
|
||||||
if itemData and (itemData.name == item) then count += (itemData.count or itemData.amount or 1) end
|
|
||||||
end
|
|
||||||
foundInv = foundInv:gsub("%-", "^7-^6"):gsub("%_", "^7_^6")
|
|
||||||
local foundMessage = "^6Bridge^7: ^3hasItem^7[^6"..foundInv.."^7]: "..tostring(item).." ^3"..count.."^7/^3"..amount
|
|
||||||
if count >= amount then foundMessage = foundMessage.." ^5FOUND^7" else foundMessage = foundMessage .." ^1NOT FOUND^7" end
|
|
||||||
if Config.System.Debug then print(foundMessage) end
|
|
||||||
hasTable[item] = { hasItem = count >= amount, count = count }
|
|
||||||
end
|
|
||||||
for k, v in pairs(hasTable) do if not v.hasItem then return false, hasTable end end
|
|
||||||
return true, hasTable
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Stash Items
|
|
||||||
function openStash(data)
|
|
||||||
if (data.job or data.gang) and not jobCheck(data.job or data.gang) then return end
|
|
||||||
if GetResourceState(OXInv):find("start") then
|
|
||||||
exports[OXInv]:openInventory('stash', data.stash)
|
|
||||||
elseif GetResourceState(CodeMInv):find("start") then
|
|
||||||
exports[CodeMInv]:OpenStash(data.stash, 400000, 100)
|
|
||||||
else
|
|
||||||
TriggerEvent("inventory:client:SetCurrentStash", data.stash)
|
|
||||||
TriggerServerEvent("inventory:server:OpenInventory", "stash", data.stash, data.stashOptions)
|
|
||||||
end
|
|
||||||
lookEnt(data.coords)
|
|
||||||
end
|
|
||||||
|
|
||||||
function getStash(stashName) local stashResource = ""
|
|
||||||
local stashItems, items = {}, {}
|
|
||||||
if GetResourceState(OXInv):find("start") then stashResource = OXInv
|
|
||||||
stashItems = exports[OXInv]:Inventory(stashName).items
|
|
||||||
|
|
||||||
elseif GetResourceState(QSInv):find("start") then stashResource = QSInv
|
|
||||||
stashItems = exports[QSInv]:GetStashItems(stashName)
|
|
||||||
|
|
||||||
elseif GetResourceState(CoreInv):find("start") then stashResource = CoreInv
|
|
||||||
stashItems = exports[CoreInv]:getInventory(stashName)
|
|
||||||
|
|
||||||
elseif GetResourceState(CodeMInv):find("start") then stashResource = CodeMInv
|
|
||||||
stashItems = exports[CodeMInv]:GetInventoryItems('Stash', stashName)
|
|
||||||
|
|
||||||
elseif GetResourceState(OrigenInv):find("start") then stashResource = OrigenInv
|
|
||||||
stashItems = exports[OrigenInv]:GetStashItems(stashName)
|
|
||||||
|
|
||||||
elseif GetResourceState(QBInv):find("start") then stashResource = QBInv
|
|
||||||
local result = MySQL.scalar.await('SELECT items FROM stashitems WHERE stash = ?', { stashName })
|
|
||||||
if result then stashItems = json.decode(result) end
|
|
||||||
end
|
|
||||||
|
|
||||||
if Config.System.Debug then print("^6Bridge^7: ^2Retrieving ^3Stash^2 with ^7"..stashResource) end
|
|
||||||
if stashItems then
|
|
||||||
for _, item in pairs(stashItems) do
|
|
||||||
local itemInfo = Items[item.name:lower()]
|
|
||||||
if itemInfo then
|
|
||||||
local indexNum = #items+1 -- Added to help recreate missing slot numbers
|
|
||||||
items[(item.slot and item.slot) or indexNum] = {
|
|
||||||
name = itemInfo.name or nil,
|
|
||||||
amount = tonumber(item.amount) or tonumber(item.count),
|
|
||||||
info = item.info or "",
|
|
||||||
label = itemInfo.label or nil,
|
|
||||||
description = itemInfo.description or "",
|
|
||||||
weight = itemInfo.weight or nil,
|
|
||||||
type = itemInfo.type or nil,
|
|
||||||
unique = itemInfo.unique or nil,
|
|
||||||
useable = itemInfo.useable or nil,
|
|
||||||
image = itemInfo.image or nil,
|
|
||||||
slot = (item.slot and item.slot) or indexNum,
|
|
||||||
}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if Config.System.Debug then print("^6Bridge^7: ^3GetStashItems^7: ^2Stash information for ^7'^6"..stashName.."^7' ^2retrieved^7") end
|
|
||||||
end
|
|
||||||
return items
|
|
||||||
end
|
|
||||||
|
|
||||||
function stashRemoveItem(stashItems, stashName, items) local amount = amount and amount or 1
|
|
||||||
if GetResourceState(OXInv):find("start") then
|
|
||||||
for k, v in pairs(items) do
|
|
||||||
exports[OXInv]:RemoveItem(stashName, k, v)
|
|
||||||
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OXInv, k, v) end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif GetResourceState(QSInv):find("start") then
|
|
||||||
for k, v in pairs(items) do
|
|
||||||
for l in pairs(stashItems) do
|
|
||||||
if stashItems[l].name == k then
|
|
||||||
if (stashItems[l].amount - v) <= 0 then
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
|
|
||||||
end
|
|
||||||
stashItems[l] = nil
|
|
||||||
else
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
|
|
||||||
end
|
|
||||||
exports[QSInv]:RemoveItemIntoStash(stashName, k, v, l)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif GetResourceState(CoreInv):find("start") then
|
|
||||||
for k, v in pairs(items) do
|
|
||||||
exports[CoreInv]:removeItemExact(stashName, k, v)
|
|
||||||
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..CoreInv, k, v) end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif GetResourceState(CodeMInv):find("start") then
|
|
||||||
for k, v in pairs(items) do
|
|
||||||
for l in pairs(stashItems) do
|
|
||||||
if stashItems[l].name == k then
|
|
||||||
if (stashItems[l].amount - v) <= 0 then
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
|
|
||||||
end
|
|
||||||
stashItems[l] = nil
|
|
||||||
else
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..CodeMInv, k, v)
|
|
||||||
end
|
|
||||||
stashItems[l].amount -= v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName.."^7'")
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif GetResourceState(OrigenInv):find("start") then
|
|
||||||
for k, v in pairs(items) do
|
|
||||||
exports[OrigenInv]:RemoveFromStash(stashName, k, v)
|
|
||||||
if Config.System.Debug then print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..OrigenInv, k, v) end
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif GetResourceState(QBInv):find("start") then
|
|
||||||
for k, v in pairs(items) do
|
|
||||||
for l in pairs(stashItems) do
|
|
||||||
if stashItems[l].name == k then
|
|
||||||
if (stashItems[l].amount - v) <= 0 then
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^2None of this item left in stash ^3Stash^7", k, v)
|
|
||||||
end
|
|
||||||
stashItems[l] = nil
|
|
||||||
else
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^2Removing item from ^3Stash^2 with ^7"..QBInv, k, v)
|
|
||||||
end
|
|
||||||
stashItems[l].amount -= v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^3saveStash^7: ^2Saving ^3QB^2 stash ^7'^6"..stashName.."^7'")
|
|
||||||
end
|
|
||||||
MySQL.Async.insert('INSERT INTO stashitems (stash, items) VALUES (:stash, :items) ON DUPLICATE KEY UPDATE items = :items', { ['stash'] = stashName, ['items'] = json.encode(stashItems) })
|
|
||||||
else
|
|
||||||
print("^4ERROR^7: ^2No Inventory detected ^7- ^2Check ^3exports^1.^2lua^7")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
RegisterNetEvent(GetCurrentResourceName()..":server:stashRemoveItem", stashRemoveItem)
|
|
||||||
|
|
||||||
function stashhasItem(stashItems, items, amount)
|
|
||||||
local invs = {OXInv, QSInv, CoreInv, CodeMInv, OrigenInv, QBInv}
|
|
||||||
local foundInv = ""
|
|
||||||
for _, inv in ipairs(invs) do
|
|
||||||
if GetResourceState(inv):find("start") then
|
|
||||||
foundInv = inv:gsub("%-", "^7-^6"):gsub("%_", "^7_^6")
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if type(items) ~= "table" then items = { [items] = amount and amount or 1, } end
|
|
||||||
local hasTable = {}
|
|
||||||
for item, amount in pairs(items) do
|
|
||||||
local count = 0
|
|
||||||
for _, itemData in pairs(stashItems) do
|
|
||||||
if itemData and (itemData.name == item) then
|
|
||||||
count += (itemData.amount or 1)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local debugMsg = string.format("^6Bridge^7: ^3stashHasItem^7[^6%s^7]: %s '%s' ^3%d^7/^3%d^7", foundInv, (count >= amount and "^5FOUND^7" or "^1NOT FOUND^7"), item, count, amount)
|
|
||||||
if Config.System.Debug then print(debugMsg) end
|
|
||||||
|
|
||||||
hasTable[item] = { hasItem = (count >= amount), count = count }
|
|
||||||
end
|
|
||||||
for k, v in pairs(hasTable) do if v.hasItem == false then return false, hasTable end end
|
|
||||||
return true, hasTable
|
|
||||||
end
|
|
||||||
|
|
||||||
if IsDuplicityVersion() then
|
|
||||||
if GetResourceState(OXLibExport):find("start") then
|
|
||||||
createCallback(GetCurrentResourceName()..':server:canCarry', function(source, itemTable) local result = canCarry(itemTable, source) return result end)
|
|
||||||
else
|
|
||||||
createCallback(GetCurrentResourceName()..':server:canCarry', function(source, cb, itemTable) local result = canCarry(itemTable, source) cb(result) end)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function canCarry(itemTable, src)
|
|
||||||
local resultTable = {}
|
|
||||||
if src then
|
|
||||||
if GetResourceState(OXInv):find("start") then
|
|
||||||
for k, v in pairs(itemTable) do
|
|
||||||
resultTable[k] = exports[OXInv]:CanCarryItem(src, k, v)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif GetResourceState(QSInv):find("start") then
|
|
||||||
for k, v in pairs(itemTable) do
|
|
||||||
resultTable[k] = exports[OXInv]:CanCarryItem(src, k, v)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif GetResourceState(CoreInv):find("start") then
|
|
||||||
--??
|
|
||||||
|
|
||||||
elseif GetResourceState(CodeMInv):find("start") then
|
|
||||||
for k, v in pairs(itemTable) do
|
|
||||||
local weight = Items[k].weight
|
|
||||||
resultTable[k] = exports[CodeMInv]:CanCarryItem(src, weight, v)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif GetResourceState(OrigenInv):find("start") then
|
|
||||||
for k, v in pairs(itemTable) do
|
|
||||||
resultTable[k] = exports[OrigenInv]:canCarryItem(src, k, v)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif GetResourceState(QBInv):find("start") then
|
|
||||||
local Player = Core.Functions.GetPlayer(src)
|
|
||||||
local items = Player.PlayerData.items
|
|
||||||
local weight, totalWeight = 0, 0
|
|
||||||
if not items then return false end
|
|
||||||
for _, item in pairs(items) do weight += item.weight * item.amount end
|
|
||||||
totalWeight = tonumber(weight)
|
|
||||||
|
|
||||||
for k, v in pairs(itemTable) do
|
|
||||||
local itemInfo = Items[k]
|
|
||||||
if not itemInfo and not Player.Offline then
|
|
||||||
triggerNotify(nil, 'Item does not exist', 'error', src)
|
|
||||||
resultTable[k] = true
|
|
||||||
else
|
|
||||||
resultTable[k] = (totalWeight + (Items[k]['weight'] * v)) <= 120000
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return resultTable
|
|
||||||
end
|
|
||||||
|
|
||||||
function getRandomReward(itemName) -- intended for job scripts
|
|
||||||
if Config.Rewards.RewardPool then
|
|
||||||
local reward = false
|
|
||||||
if type(Config.Rewards.RewardItem) == "string" then Config.Rewards.RewardItem = { Config.Rewards.RewardItem } end
|
|
||||||
for k, v in pairs(Config.Rewards.RewardItem) do
|
|
||||||
if v == itemName then reward = true break end
|
|
||||||
end
|
|
||||||
if reward then
|
|
||||||
removeItem(itemName, 1)
|
|
||||||
local totalRarity = 0
|
|
||||||
for i=1, #Config.Rewards.RewardPool do
|
|
||||||
totalRarity += Config.Rewards.RewardPool[i].rarity
|
|
||||||
end
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^3getRandomReward^7: ^2Total Rarity ^7'^6"..totalRarity.."^7'")
|
|
||||||
end
|
|
||||||
|
|
||||||
local randomNum = math.random(1, totalRarity)
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^3getRandomReward^7: ^2Random Number ^7'^6"..randomNum.."^7'")
|
|
||||||
end
|
|
||||||
local currentRarity = 0
|
|
||||||
for i=1, #Config.Rewards.RewardPool do
|
|
||||||
currentRarity += Config.Rewards.RewardPool[i].rarity
|
|
||||||
if randomNum <= currentRarity then
|
|
||||||
if Config.System.Debug then
|
|
||||||
print("^6Bridge^7: ^3getRandomReward^7: ^2Selected toy ^7'^6"..Config.Rewards.RewardPool[i].item.."^7'")
|
|
||||||
end
|
|
||||||
addItem(Config.Rewards.RewardPool[i].item, 1)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
20
exports.lua
20
exports.lua
@@ -1,20 +0,0 @@
|
|||||||
Exports = {
|
|
||||||
QBExport = "qb-core",
|
|
||||||
QBXExport = "qbx_core",
|
|
||||||
ESXExport = "es_extended",
|
|
||||||
OXCoreExport = "ox_core",
|
|
||||||
|
|
||||||
OXInv = "ox_inventory",
|
|
||||||
QBInv = "qb-inventory",
|
|
||||||
QSInv = "qs-inventory",
|
|
||||||
CoreInv = "core_inventory",
|
|
||||||
CodeMInv = "codem-inventory",
|
|
||||||
OrigenInv = "origen_inventory",
|
|
||||||
|
|
||||||
OXLibExport = "ox_lib",
|
|
||||||
|
|
||||||
QBMenuExport = "qb-menu",
|
|
||||||
|
|
||||||
QBTargetExport = "qb-target",
|
|
||||||
OXTargetExport = "ox_target"
|
|
||||||
}
|
|
||||||
1168
functions.lua
1168
functions.lua
File diff suppressed because it is too large
Load Diff
@@ -1,14 +0,0 @@
|
|||||||
name "Jim_Bridge"
|
|
||||||
author "Jimathy"
|
|
||||||
version "1.0.14"
|
|
||||||
description "Framework Bridge By Jimathy"
|
|
||||||
fx_version "cerulean"
|
|
||||||
game "gta5"
|
|
||||||
lua54 'yes'
|
|
||||||
|
|
||||||
files {
|
|
||||||
'exports.lua',
|
|
||||||
'functions.lua',
|
|
||||||
'wrapper.lua',
|
|
||||||
'crafting.lua',
|
|
||||||
}
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
1.0.14
|
|
||||||
1395
wrapper.lua
1395
wrapper.lua
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user