From 8252d42b6a783b92ed2743c30b46a55aa621f352 Mon Sep 17 00:00:00 2001 From: Chase Eller Date: Tue, 24 Mar 2026 21:55:24 -0400 Subject: [PATCH] Coding Update - Updated snippets for SLF to align with new coding processes - Updated templates for resource builder to build to new coding process --- CHANGELOG.md | 7 ++- package.json | 2 +- snippets/cstmcommonfunctions.code-snippets | 72 +++++++++++++++------- template/base/client/client.lua | 42 ++++++------- template/base/server/server.lua | 42 ++++++------- template/withFeature/client/client.lua | 42 ++++++------- template/withFeature/server/server.lua | 42 ++++++------- 7 files changed, 130 insertions(+), 119 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f5d09d7..2f99e90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,4 +20,9 @@ I will use this area to keep up with what i did last. ## [Release 1.1.2] -- Combined the 2 dev tool resources togethter to make one total tool for easier maintaining \ No newline at end of file +- Combined the 2 dev tool resources togethter to make one total tool for easier maintaining + +## [Release 1.1.3] + +- Updated snippets for SLF to align with new coding processes +- Updated templates for resource builder to build to new coding process \ No newline at end of file diff --git a/package.json b/package.json index 452d598..5414c0a 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "cstmgames-fivem-snippets", "displayName": "CSTMGames FiveM Dev Tools", "description": "Development tools for FiveM", - "version": "1.1.2", + "version": "1.1.3", "author": { "name": "Chase Eller", "email": "chase@cstmgames.com", diff --git a/snippets/cstmcommonfunctions.code-snippets b/snippets/cstmcommonfunctions.code-snippets index 3befc53..124df83 100644 --- a/snippets/cstmcommonfunctions.code-snippets +++ b/snippets/cstmcommonfunctions.code-snippets @@ -1,13 +1,4 @@ { - "Setup SLF Vars": { - "prefix": "SLFVARS", - "body": [ - "local CLASS = \"CHANGEME\"--This is the name that the logging framework will use to display your logs in the correct manner", - "local LOG_LEVEL = GetResourceMetadata(GetCurrentResourceName(), \"log_level\", 0)", - "local RESOURCE_CODE = GetResourceMetadata(GetCurrentResourceName(), \"resource_code\", 0)" - ], - "description": "" - }, "Log to SLF": { "prefix": "Log", "body": "Log(\"${1:Your Log Message Here}\", ${2|4,3,2,1|})$0", @@ -48,39 +39,78 @@ ], "description": "Sets up command to be registered" }, - "Server Side SLF Function": { - "prefix": "slfserver", + "SLF Functions and Vars for SERVER.": { + "prefix": "SLFSERVER", "body": [ - "function Log(message, logLevel)", + "--GLOBAL CONSTANTS", + "local CLASS = \"CHANGEME\"--This is the name that the logging framework will use to display your logs in the correct manner", + "local LOG_LEVEL = GetResourceMetadata(GetCurrentResourceName(), \"log_level\", 0)", + "local RESOURCE_CODE = GetResourceMetadata(GetCurrentResourceName(), \"resource_code\", 0)", + "------------------------------------------------------------------------------------------------", + "--SLF Server Logging Function DO NOT TOUCH unless you know what you are doing.", + "", + "---Used to send logs to the server console", + "---@param message any Preformatted message or VARIABLES to be sent to log", + "---@param logLevel integer Level of log, 1-Error, 2-Warn, 3-Info, 4-Debug", + "local function Log(message, logLevel)", " local line = debug.getinfo(2, \"l\").currentline", " local name = debug.getinfo(2, \"n\").name", " if name == \"fn\" then", " name = \"Thread\"", " end", " local value = \"{\"..CLASS..\".\"..name..\"(\"..line..\")} \"..message", - " if tonumber(LOG_LEVEL) >= logLevel then", - " exports.SLF:LogToServer(RESOURCE_CODE, logLevel, value)", + " if logLevel then", + " if tonumber(LOG_LEVEL) >= logLevel then", + " exports.SLF:LogToServer(RESOURCE_CODE, logLevel, value)", + " end", + " else", + " exports.SLF:LogToServer(RESOURCE_CODE, 4, value)", + " Log(\"Warning line was logged without a level value... Logged it as debug as that is the safest route.\", 1)", " end", + "end", + "", + "local function DisLog(message)", + " local line = debug.getinfo(2, \"l\").currentline", + " local name = debug.getinfo(2, \"n\").name", + " if name == \"fn\" then", + " name = \"Thread\"", + " end", + " local value = \"{\"..CLASS..\".\"..name..\"(\"..line..\")} \"..message", + " exports.SLF:LogServerToDiscord(RESOURCE_CODE, message)", "end" ], - "description": "Server Side SLF Function" + "description": "SLF Functions and Vars for SERVER." }, - "Client Side SLF Function": { - "prefix": "slfclient", + "SLF Functions and Vars for CLIENT.": { + "prefix": "SLFCLIENT", "body": [ - "function Log(message, logLevel)", + "--GLOBAL CONSTANTS", + "local CLASS = \"CHANGEME\"--This is the name that the logging framework will use to display your logs in the correct manner", + "local LOG_LEVEL = GetResourceMetadata(GetCurrentResourceName(), \"log_level\", 0)", + "local RESOURCE_CODE = GetResourceMetadata(GetCurrentResourceName(), \"resource_code\", 0)", + "-----------------------------------------------------------------------------------------------", + "--SLF Server Logging Function DO NOT TOUCH unless you know what you are doing", + "---Used to send logs to the client console", + "---@param message any Preformatted message or VARIABLES to be sent to log", + "---@param logLevel integer Level of log, 1-Error, 2-Warn, 3-Info, 4-Debug", + "local function Log(message, logLevel)", " local line = debug.getinfo(2, \"l\").currentline", " local name = debug.getinfo(2, \"n\").name", " if name == \"fn\" then", " name = \"Thread\"", " end", " local value = \"{\"..CLASS..\".\"..name..\"(\"..line..\")} \"..message", - " if tonumber(LOG_LEVEL) >= logLevel then", - " exports.SLF:LogToClient(RESOURCE_CODE, logLevel, value)", + " if logLevel then", + " if tonumber(LOG_LEVEL) >= logLevel then", + " exports.SLF:LogToClient(RESOURCE_CODE, logLevel, value)", + " end", + " else", + " exports.SLF:LogToClient(RESOURCE_CODE, 4, value)", + " Log(\"Warning line was logged without a level value... Logged it as debug as that is the safest route.\", 1)", " end", "end" ], - "description": "Client Side SLF Function" + "description": "SLF Functions and Vars for client." }, "Sets up TriggerClientEvent": { "prefix": "tce", diff --git a/template/base/client/client.lua b/template/base/client/client.lua index 3cfa987..706c3f4 100644 --- a/template/base/client/client.lua +++ b/template/base/client/client.lua @@ -2,29 +2,12 @@ local CLASS = "CHANGEME"--This is the name that the logging framework will use to display your logs in the correct manner local LOG_LEVEL = GetResourceMetadata(GetCurrentResourceName(), "log_level", 0) local RESOURCE_CODE = GetResourceMetadata(GetCurrentResourceName(), "resource_code", 0) ---LOCAL VARIABLES - - - ---END CONFIG ----------------------------------------------------------------------------------------------- - - - -------------------- ---YOUR CODE HERE--- ---HAPPY CODING!---- -------------------- - - - ------------------------------------------------------------------------------------------------- --SLF Server Logging Function DO NOT TOUCH unless you know what you are doing - ---Used to send logs to the client console ---@param message any Preformatted message or VARIABLES to be sent to log ---@param logLevel integer Level of log, 1-Error, 2-Warn, 3-Info, 4-Debug -function Log(message, logLevel) +local function Log(message, logLevel) local line = debug.getinfo(2, "l").currentline local name = debug.getinfo(2, "n").name if name == "fn" then @@ -41,9 +24,20 @@ function Log(message, logLevel) 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 +--LOCAL VARIABLES + +--END CONFIG +----------------------------------------------------------------------------------------------- + + + +------------------- +--YOUR CODE HERE--- +--HAPPY CODING!---- +------------------- + + + + + + diff --git a/template/base/server/server.lua b/template/base/server/server.lua index 1b91213..26226f9 100644 --- a/template/base/server/server.lua +++ b/template/base/server/server.lua @@ -2,29 +2,13 @@ local CLASS = "CHANGEME"--This is the name that the logging framework will use to display your logs in the correct manner local LOG_LEVEL = GetResourceMetadata(GetCurrentResourceName(), "log_level", 0) local RESOURCE_CODE = GetResourceMetadata(GetCurrentResourceName(), "resource_code", 0) ---Global Variables ---LOCAL VARIABLES - - ---END CONFIG ------------------------------------------------------------------------------------------------ - - - -------------------- ---YOUR CODE HERE--- ---HAPPY CODING!---- -------------------- - - - ------------------------------------------------------------------------------------------------ --SLF Server Logging Function DO NOT TOUCH unless you know what you are doing. ---Used to send logs to the server console ---@param message any Preformatted message or VARIABLES to be sent to log ---@param logLevel integer Level of log, 1-Error, 2-Warn, 3-Info, 4-Debug -function Log(message, logLevel) +local function Log(message, logLevel) local line = debug.getinfo(2, "l").currentline local name = debug.getinfo(2, "n").name if name == "fn" then @@ -41,7 +25,7 @@ function Log(message, logLevel) end end -function DisLog(message) +local function DisLog(message) local line = debug.getinfo(2, "l").currentline local name = debug.getinfo(2, "n").name if name == "fn" then @@ -50,10 +34,20 @@ function DisLog(message) local value = "{"..CLASS.."."..name.."("..line..")} "..message exports.SLF:LogServerToDiscord(RESOURCE_CODE, message) end +--Global Variables + +--LOCAL VARIABLES + + +--END CONFIG +----------------------------------------------------------------------------------------------- + + + +------------------- +--YOUR CODE HERE--- +--HAPPY CODING!---- +------------------- + + -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 \ No newline at end of file diff --git a/template/withFeature/client/client.lua b/template/withFeature/client/client.lua index 3cfa987..706c3f4 100644 --- a/template/withFeature/client/client.lua +++ b/template/withFeature/client/client.lua @@ -2,29 +2,12 @@ local CLASS = "CHANGEME"--This is the name that the logging framework will use to display your logs in the correct manner local LOG_LEVEL = GetResourceMetadata(GetCurrentResourceName(), "log_level", 0) local RESOURCE_CODE = GetResourceMetadata(GetCurrentResourceName(), "resource_code", 0) ---LOCAL VARIABLES - - - ---END CONFIG ----------------------------------------------------------------------------------------------- - - - -------------------- ---YOUR CODE HERE--- ---HAPPY CODING!---- -------------------- - - - ------------------------------------------------------------------------------------------------- --SLF Server Logging Function DO NOT TOUCH unless you know what you are doing - ---Used to send logs to the client console ---@param message any Preformatted message or VARIABLES to be sent to log ---@param logLevel integer Level of log, 1-Error, 2-Warn, 3-Info, 4-Debug -function Log(message, logLevel) +local function Log(message, logLevel) local line = debug.getinfo(2, "l").currentline local name = debug.getinfo(2, "n").name if name == "fn" then @@ -41,9 +24,20 @@ function Log(message, logLevel) 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 +--LOCAL VARIABLES + +--END CONFIG +----------------------------------------------------------------------------------------------- + + + +------------------- +--YOUR CODE HERE--- +--HAPPY CODING!---- +------------------- + + + + + + diff --git a/template/withFeature/server/server.lua b/template/withFeature/server/server.lua index 1b91213..26226f9 100644 --- a/template/withFeature/server/server.lua +++ b/template/withFeature/server/server.lua @@ -2,29 +2,13 @@ local CLASS = "CHANGEME"--This is the name that the logging framework will use to display your logs in the correct manner local LOG_LEVEL = GetResourceMetadata(GetCurrentResourceName(), "log_level", 0) local RESOURCE_CODE = GetResourceMetadata(GetCurrentResourceName(), "resource_code", 0) ---Global Variables ---LOCAL VARIABLES - - ---END CONFIG ------------------------------------------------------------------------------------------------ - - - -------------------- ---YOUR CODE HERE--- ---HAPPY CODING!---- -------------------- - - - ------------------------------------------------------------------------------------------------ --SLF Server Logging Function DO NOT TOUCH unless you know what you are doing. ---Used to send logs to the server console ---@param message any Preformatted message or VARIABLES to be sent to log ---@param logLevel integer Level of log, 1-Error, 2-Warn, 3-Info, 4-Debug -function Log(message, logLevel) +local function Log(message, logLevel) local line = debug.getinfo(2, "l").currentline local name = debug.getinfo(2, "n").name if name == "fn" then @@ -41,7 +25,7 @@ function Log(message, logLevel) end end -function DisLog(message) +local function DisLog(message) local line = debug.getinfo(2, "l").currentline local name = debug.getinfo(2, "n").name if name == "fn" then @@ -50,10 +34,20 @@ function DisLog(message) local value = "{"..CLASS.."."..name.."("..line..")} "..message exports.SLF:LogServerToDiscord(RESOURCE_CODE, message) end +--Global Variables + +--LOCAL VARIABLES + + +--END CONFIG +----------------------------------------------------------------------------------------------- + + + +------------------- +--YOUR CODE HERE--- +--HAPPY CODING!---- +------------------- + + -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 \ No newline at end of file