Recreate Repo from GTAVAlive

This commit is contained in:
Custommuscle2 2022-12-17 14:14:01 -05:00
parent 1b389ae8b8
commit 4be60ee03c
21 changed files with 2386 additions and 0 deletions

7
.vscode/extensions.json vendored Normal file
View File

@ -0,0 +1,7 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the extensions.json format
"recommendations": [
"dbaeumer.vscode-eslint"
]
}

26
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,26 @@
// A launch configuration that launches the extension inside a new window
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
{
"version": "0.2.0",
"configurations": [
{
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
]
},
{
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/test/suite/index"
]
}
]
}

9
.vscodeignore Normal file
View File

@ -0,0 +1,9 @@
.vscode/**
.vscode-test/**
test/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
**/jsconfig.json
**/*.map
**/.eslintrc.json

Binary file not shown.

1
LICENSE Normal file
View File

@ -0,0 +1 @@
FOR CSTM INTERNAL USE ONLY

24
README Normal file
View File

@ -0,0 +1,24 @@
# CSTM Games Resource Generator
This is an ***INTERNAL USE ONLY*** tool for generating a FiveM Resource using our structure that we have outlined during the GCONFIG update. This will produce you a folder with the correct naming schemes, folder structure, and settings to allow for a plug and play experience. Edit what you need to and remove/add anything you need to the provided files. If you have any updates/request for thing in the generator let Chase know so he can get it in a plugin update and get that uploaded to the repository.
Right click on your resources folder in your explorer window on the left hand side of your screen and select "Generate FiveM Resource From Template" and follow the prompts on the screen and it will create the following folder structure and fill out the fxmanifest.lua with the info provided.
```markdown
├── RESOURCE CODE
│ ├── fxmanifest.lua
│ ├── initConfig.json
│ ├── SERVER
│ │ ├── server.lua
│ ├── CLIENT
│ │ ├── client.lua
│ ├── MENUS
│ │ ├── readme.txt
```
# Disclaimer
Yes you can indeed make a resource folder yourself. Yes this is a fair bit cheating, but this ensure that the files you are starting with are a good foundation to work from and you are less likely to trip and mess up.

168
extension.js Normal file
View File

@ -0,0 +1,168 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const { readFileSync, readdirSync, mkdirSync, writeFileSync } = require('fs');
const vscode = require('vscode');
var extensionPath = "";
// this method is called when your extension is activated
// your extension is activated the very first time the command is executed
/**
* @param {vscode.ExtensionContext} context
*/
function activate(context) {
loadInputs();
let disposable = vscode.commands.registerCommand('CSTM-fivem.generate-resource', function (uri) {
loadInputs(uri.fsPath)
});
extensionPath = context.extensionPath + "/template"
context.subscriptions.push(disposable);
}
// this method is called when your extension is deactivated
function deactivate() {}
var InputData = {
resourceCode : {
title : "Resource Code",
placeholder : "Used for the folder name: GOD, GSR, SELAPI, ...",
nextInput : "resourceName",
value : "",
input : null
},
resourceName : {
title : "Resource name",
placeholder : "B_Jobs, Phone, esx_garage, ...",
nextInput : "description",
value : "",
input : null
},
description : {
title : "Resource description",
placeholder : "This resource is ...",
nextInput : "",
value : "",
input : null
}
}
var startInput = "resourceCode"
function loadInputs(resource) {
for (const key in InputData) {
InputData[key].input = vscode.window.createInputBox();
InputData[key].input.title = InputData[key].title;
InputData[key].input.placeholder = InputData[key].placeholder;
InputData[key].input.onDidAccept(function() {
if (InputData[key].input.value.trim().length > 0) {
InputData[key].value = InputData[key].input.value
InputData[key].input.hide()
if (InputData[key].nextInput != "") {
InputData[InputData[key].nextInput].input.show()
} else {
startProcessing(resource)
}
} else {
vscode.window.showErrorMessage(`You need to complete this input (${InputData[key].title}).`)
}
})
if (startInput == key) {
InputData[key].input.show();
}
}
}
function startProcessing(url) {
var folder = getGeneratedFolder("");
mkdirSync(`${url}/${InputData.resourceCode.value}`)
writeFolder(`${url}/${InputData.resourceCode.value}`, folder);
vscode.window.showInformationMessage(`You just created a new FiveM Lua Resource named '${InputData.resourceName.value}'.`)
}
function Folder(url) {
var folder = {
url : url,
files : {},
folders : {}
}
return folder
}
function getGeneratedFolder(url) {
var folder = Folder(url)
var files = readdirSync(extensionPath + url, { withFileTypes: true, encoding : 'utf-8' });
for (const file of files) {
if (file.isDirectory()) {
folder.folders[file.name] = getGeneratedFolder(`${url}/${file.name}`)
} else {
folder.files[file.name] = readFileSync(`${extensionPath + url}/${file.name}`, {encoding : 'utf-8'})
for (const key in InputData) {
folder.files[file.name] = folder.files[file.name].replace("${" + key + "}", InputData[key].value)
}
}
}
return folder;
}
function writeFolder(url, folder) {
url = url
for (const key in folder.files) {
writeFileSync(url + "/"+ key, folder.files[key], {encoding : 'utf-8'});
}
for (const key in folder.folders) {
var fold = folder.folders[key]
mkdirSync(url + "/" + folder.url + fold.url)
writeFolder(url + "/" + folder.url + fold.url, fold)
}
}
module.exports = {
activate,
deactivate
}

15
jsconfig.json Normal file
View File

@ -0,0 +1,15 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"checkJs": true, /* Typecheck .js files. */
"rootDir": ".",
"baseUrl": "types",
"lib": [
"es6"
]
},
"exclude": [
"node_modules"
]
}

1764
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

69
package.json Normal file
View File

@ -0,0 +1,69 @@
{
"publisher": "CSTM Games",
"name": "CSTM-RESOURCE-GENERATOR",
"displayName": "CSTM Five Alive Resource Generator",
"description": "This is an internal tool to help you in creating a new basic lua resource for FiveAlive",
"version": "0.2.0",
"engines": {
"vscode": "^1.59.0"
},
"categories": [
"Other"
],
"author": {
"name": "CSTM Games"
},
"repository": {
"type": "git",
"url": "https://github.com/Custommuscle2/GTAVAlive"
},
"icon": "preview/fivem.png",
"homepage": "https://github.com/Custommuscle2/GTAVAlive",
"license": "GPLv3",
"keywords": [
"fivem",
"lua",
"resource",
"script",
"gta",
"generator"
],
"activationEvents": [
"onCommand:CSTM-fivem.generate-resource"
],
"main": "./extension.js",
"files": [
"template/fxmanifest.lua"
],
"directories": {},
"contributes": {
"commands": [
{
"command": "CSTM-fivem.generate-resource",
"title": "Generate FiveM Resource From Template"
}
],
"menus": {
"explorer/context": [{
"when": "explorerResourceIsFolder",
"command": "CSTM-fivem.generate-resource"
}]
}
},
"scripts": {
"lint": "eslint .",
"pretest": "npm run lint",
"test": "node ./test/runTest.js"
},
"devDependencies": {
"@types/vscode": "^1.59.0",
"@types/glob": "^7.1.3",
"@types/mocha": "^8.2.2",
"@types/node": "14.x",
"eslint": "^7.27.0",
"glob": "^7.1.7",
"mocha": "^8.4.0",
"typescript": "^4.3.2",
"vscode-test": "^1.5.2"
}
}

BIN
preview/fivem.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

BIN
preview/video-preview.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.8 MiB

View File

@ -0,0 +1,6 @@
If you need to create a menu please add it here in this folder then declare it properly in the fxmanifest.
add "menuv" to your dependencies
add '@menuv/menuv.lua' and 'menu/*.lua' to your client_scripts declaration.

View File

@ -0,0 +1,48 @@
--BEGIN CONFIG
--Global Constants
local LOG_LEVEL = 4
local RESOURCE_CODE = GetResourceMetadata(GetCurrentResourceName(), "resource_code", 0)
--Global Constants
--LOCAL VARIABLES
local config = {}
--END CONFIG
-----------------------------------------------------------------------------------------------
-------------------
--YOUR CODE HERE---
--HAPPY CODING!----
-------------------
------------------------------------------------------------------------------------------------
--Config Syncing Function DO NOT TOUCH unless you know what you are doing.
RegisterNetEvent(RESOURCE_CODE..":ConfigUpdate_cl")
AddEventHandler(RESOURCE_CODE..":ConfigUpdate_cl", function(cfg)
local config = cfg
for i, qResult in pairs(config) do
Log("QRESULT.CONFIGNAME "..qResult.ConfigName, 4)
if qResult.ConfigName == "LOG_LEVEL" then
LOG_LEVEL = qResult.ConfigValue
elseif qResult.ConfigName == "CHANGEME" then
CHANGE_ME = qResult.ConfigValue
end
end
end)
--SLF Server Logging Function DO NOT TOUCH unless you know what you are doing.
function Log(message, logLevel)
if tonumber(LOG_LEVEL) >= logLevel then
exports.SLF:LogToClient(RESOURCE_CODE, logLevel, message)
end
end
function GetSID(UUID)
Log("Requesting SID for UUID: "..UUID, 4)
local SID = exports.SPH:GetSID(UUID)
Log("Retreived SID: "..SID.." for UUID: "..UUID, 4)
return SID
end

41
template/fxmanifest.lua Normal file
View File

@ -0,0 +1,41 @@
fx_version 'adamant'
game 'gta5'
resource_code "${resourceCode}"--The Resource Code is used everywhere in our
name "${resourceName}"--This is the "pretty name" of your script. This will be used for any "name facing" code that is displayed to the user
description "${description}" --Explains itself.
author "CSTM Games & KJ4LXC"--Who are you again?
version "0.0.1"
--Dependencies are the resources that your resource and just not do without. Add additional Resource Codes for any other resources that we have not included in the list already if you need to declare them as a dependency.
dependencies {
"GCONFIG",
"SLF",
"SCF"
}
--Shared Scripts are scripts shared between both the server and the client. These will run on both server and client, not run on server and allow the clients to use them. Be careful about using net events in these. Its best to use exports if you need to do something inside them. (SCF for instance.)
-- shared_scripts {
-- 'shared/*.lua'
-- }
--Client Scripts run on the client only.
client_scripts {
'client/*.lua',
'menus/*.lua'
}
--Server Scripts run on the server only.
server_scripts {
'server/*.lua'
}
--Files that need to be provided directly to the client for use (sound files, html for visuals, etc) need to be declared in this section. Blobing is supported (folder/*.lua etc)
-- files {
-- }
log_level '4'
USE_MYSQL '1'--This tells the script to call GCONFIG for its updates and if it isn't in the database add them.

16
template/initConfig.json Normal file
View File

@ -0,0 +1,16 @@
{
"configs": [
{
"name": "LOG_LEVEL",
"value": 4
},
{
"name": "Test1",
"value": "Success"
},
{
"name": "Test2",
"value": 1
}
]
}

112
template/server/server.lua Normal file
View File

@ -0,0 +1,112 @@
--BEGIN CONFIG
--GLOBAL CONSTANTS
local LOG_LEVEL = 4
local RESOURCE_CODE = GetResourceMetadata(GetCurrentResourceName(), "resource_code", 0)
local USE_MYSQL = tonumber(GetResourceMetadata(GetCurrentResourceName(), "USE_MYSQL", 0))
--Global Constants
--Global Variables
--LOCAL VARIABLES
local config = {}
--END CONFIG
-----------------------------------------------------------------------------------------------
-------------------
--YOUR CODE HERE---
--HAPPY CODING!----
-------------------
------------------------------------------------------------------------------------------------
--Config Syncing Function DO NOT TOUCH unless you know what you are doing.
Citizen.CreateThread(function()
local cfgCounter = 0
local RunOnce = true
local RunConfig = true
while RunConfig do
local cfgToLoad = {}
local initconfig = json.decode(LoadResourceFile(GetCurrentResourceName(), "initconfig.json"))
if USE_MYSQL == 1 and RunOnce then
local ready = exports.GCONFIG:IsReady()
if ready then
if cfgCounter <= 3 then
local qResults = exports.GCONFIG:GetConfig(RESOURCE_CODE)
if qResults ~= -1 then
cfgToLoad = exports.GCONFIG:GetConfigWithUNI(RESOURCE_CODE)
RunOnce = false
cfgCounter = 0
else
local initconfig = json.decode(LoadResourceFile(GetCurrentResourceName(), "initConfig.json"))
TriggerEvent("GCONFIG:CreateInitialConfig", RESOURCE_CODE, initconfig)
--INCREMENT COUNTER
cfgCounter = cfgCounter + 1
Log("Config re-running in 1sec to procure updated MySQL values...", 4)
end
elseif cfgCounter > 3 then
Log("Config retry reached max limit, loading config defaults. Check GCONFIG", 1)
RunOnce = false
cfgToLoad = initconfig
else
Log("I have no clue how you have arrived here, something is very wrong...", 1)
end
end
else
Log("RunOnce check aborted as UseMySQL is not TRUE.", 4)
RunOnce = false
cfgToLoad = initconfig
end
if not RunOnce and RunConfig then
UpdateConfigs(cfgToLoad)
RunConfig = false
end
Wait(1000)
end
end)
function UpdateConfigs(cfgJson) --for loop that reads all variables from config file.
Log("Updating Config", 4)
config = cfgJson
for i, qResult in pairs(config) do
Log("QRESULT.CONFIGNAME "..qResult.ConfigName, 4)
if qResult.ConfigName == "LOG_LEVEL" then
LOG_LEVEL = qResult.ConfigValue
elseif qResult.ConfigName == "CHANGEME" then
CHANGE_ME = qResult.ConfigValue
end
end
Wait(1000)
TriggerClientEvent(RESOURCE_CODE..":ConfigUpdate_cl", -1, config)
end
RegisterNetEvent(RESOURCE_CODE..":ConfigUpdate_sv")
AddEventHandler(RESOURCE_CODE..":ConfigUpdate_sv", function(cfgJson)
UpdateConfigs(cfgJson)
Wait(0)
TriggerClientEvent(RESOURCE_CODE..":ConfigUpdate_cl", -1, cfgJson)
end)
RegisterCommand(string.lower(RESOURCE_CODE).."gconfig", function(source, args)
TriggerEvent("GCONFIG:UpdateMe", RESOURCE_CODE, true)
end)
--SLF Server Logging Function DO NOT TOUCH unless you know what you are doing.
function Log(message, logLevel)
if tonumber(LOG_LEVEL) >= logLevel then
exports.SLF:LogToServer(RESOURCE_CODE, logLevel, message)
end
end
function DisLog(message)
exports.SLF:LogServerToDiscord(RESOURCE_CODE, message)
end
function GetSID(UUID)
Log("Requesting SID for UUID: "..UUID, 4)
local SID = exports.SPH:GetSID(UUID)
Log("Retreived SID: "..SID.." for UUID: "..UUID, 4)
return SID
end

View File

23
test/runTest.js Normal file
View File

@ -0,0 +1,23 @@
const path = require('path');
const { runTests } = require('vscode-test');
async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../');
// The path to the extension test script
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
}
main();

View File

@ -0,0 +1,15 @@
const assert = require('assert');
// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
const vscode = require('vscode');
// const myExtension = require('../extension');
suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});

42
test/suite/index.js Normal file
View File

@ -0,0 +1,42 @@
const path = require('path');
const Mocha = require('mocha');
const glob = require('glob');
function run() {
// Create the mocha test
const mocha = new Mocha({
ui: 'tdd',
color: true
});
const testsRoot = path.resolve(__dirname, '..');
return new Promise((c, e) => {
glob('**/**.test.js', { cwd: testsRoot }, (err, files) => {
if (err) {
return e(err);
}
// Add files to the test suite
files.forEach(f => mocha.addFile(path.resolve(testsRoot, f)));
try {
// Run the mocha test
mocha.run(failures => {
if (failures > 0) {
e(new Error(`${failures} tests failed.`));
} else {
c();
}
});
} catch (err) {
console.error(err);
e(err);
}
});
});
}
module.exports = {
run
};