-
Notifications
You must be signed in to change notification settings - Fork 26
Added Discord Logs #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,9 @@ function Modules.DriftCounter.GetCurrentAngle() | |
| end | ||
| end | ||
|
|
||
| function Modules.DriftCounter.SendDriftDataToServer(points) | ||
| TriggerServerEvent('drift:logToDiscord', points) | ||
| end | ||
| -- Cleaning the cache to avoid any memory leak as the system will load up every vehicule entity the player goes in. If the entity is deleted or not in range it will be removed from the list to avoid memory leaks | ||
| function Modules.DriftCounter.CleanUpCache() | ||
| for veh, allowed in pairs(Modules.DriftCounter.CachedAllowedVeh) do | ||
|
|
@@ -94,17 +97,23 @@ function Modules.DriftCounter.StartChainBreakLoop() | |
| Modules.DriftCounter.FadeInHud() | ||
| end | ||
| TriggerEvent(ConfigShared.DriftStartEvent) | ||
|
|
||
| Citizen.CreateThread(function() | ||
| Modules.Utils.RealWait(Modules.DriftCounter.ChainCooldown, function(cb, timeLeft) | ||
| Modules.DriftCounter.ChainTimeLeft = timeLeft - (timeLeft * 2) -- Duh | ||
| if Modules.DriftCounter.IsDrifting then | ||
| cb(false, ConfigShared.DriftChainTime) | ||
| end | ||
| end) | ||
|
|
||
| -- Once the drift ends and before resetting the variables, log the points | ||
| if ConfigShared.UseDefaultUI then | ||
| Modules.DriftCounter.FadeOutHud() | ||
| end | ||
| TriggerEvent(ConfigShared.DriftFinishedEvent, Modules.DriftCounter.CurrentPoints) | ||
| Modules.DriftCounter.SendDriftDataToServer(Modules.DriftCounter.CurrentPoints) -- Add this line here | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Add this line here" ? |
||
|
|
||
| -- Resetting the drift variables | ||
| Modules.DriftCounter.ChainCooldown = ConfigShared.DriftChainTime | ||
| Modules.DriftCounter.ChainLoopStarted = false | ||
| Modules.DriftCounter.CurrentPoints = 0 | ||
|
|
@@ -114,6 +123,7 @@ function Modules.DriftCounter.StartChainBreakLoop() | |
| end | ||
| end | ||
|
|
||
|
|
||
| function Modules.DriftCounter.FadeInHud() | ||
| Citizen.CreateThread(function() | ||
| Modules.DriftCounter.InAnimation = true | ||
|
|
@@ -191,3 +201,4 @@ end) | |
| AddEventHandler(ConfigShared.ToggleEvent, function() | ||
| Modules.DriftCounter.IsEnabled = not Modules.DriftCounter.IsEnabled | ||
| end) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| ConfigShared = {} | ||
| ConfigShared.devmod = false -- Keep the UI on by default, usefull when tweaking UI | ||
| ConfigShared.UseDefaultUI = true -- Set this to false if you want to use your own UI | ||
|
|
||
| ConfigShared.DiscordLog = 'WEBHOOK HERE' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add an toggle for this, as not everyone would like this feature |
||
|
|
||
| ConfigShared.DriftChainTime = 5000 -- Time in MS | ||
| ConfigShared.AddStaticPointOnDrifting = true -- Add a static number of point on every frame when the player is drifting | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| -- server.lua | ||
| RegisterServerEvent('drift:logToDiscord') | ||
| AddEventHandler('drift:logToDiscord', function(points) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just a nit pick, but I prefer RegisterNetEvent, and also fusion the Register and the Handler RegisterNetEvent('drift:logToDiscord', function(points) ....
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also not a fan of the points arg not being processed. That mean a cheater could abuse the event, send whatever text he want and spam the discord with it. Maybe filter the arg to only allow numbers, that would at least prevent cheaters from sending whatever they want |
||
| local discordWebhook = ConfigShared.DiscordLog -- Replace with your webhook URL | ||
| local playerName = GetPlayerName(source) | ||
| local playerIdentifier = GetPlayerIdentifier(source, 0) -- 0 for license identifier | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Be carefull with this as depending if the user has steam open or not, the Identifier could change, giving either the steamID, or License |
||
|
|
||
| local message = { | ||
| { | ||
| ["color"] = 16711680, | ||
| ["title"] = "**Drift Points Logged**", | ||
| ["description"] = "Player: " .. playerName .. "\nSteam License: " .. playerIdentifier .. "\nPoints: " .. points, | ||
| ["footer"] = { | ||
| ["text"] = "Drift Logging System By Clin", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand you want to leave your mark, but ... eh, at least give the option for the user to change this in the config |
||
| }, | ||
| } | ||
| } | ||
|
|
||
| PerformHttpRequest(discordWebhook, function(err, text, headers) end, 'POST', json.encode({username = 'Drift Logger', embeds = message}), { ['Content-Type'] = 'application/json' }) | ||
| end) | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a config option, check if logs are enabled or not before sending the event