Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions client/module/modules/drift_counter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ function Modules.DriftCounter.GetCurrentAngle()
end
end

function Modules.DriftCounter.SendDriftDataToServer(points)
Copy link
Contributor

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

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
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand All @@ -114,6 +123,7 @@ function Modules.DriftCounter.StartChainBreakLoop()
end
end


function Modules.DriftCounter.FadeInHud()
Citizen.CreateThread(function()
Modules.DriftCounter.InAnimation = true
Expand Down Expand Up @@ -191,3 +201,4 @@ end)
AddEventHandler(ConfigShared.ToggleEvent, function()
Modules.DriftCounter.IsEnabled = not Modules.DriftCounter.IsEnabled
end)

2 changes: 1 addition & 1 deletion config/config_shared.lua
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'
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down
4 changes: 4 additions & 0 deletions fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ client_scripts {
"client/module/modules/ui_native_pages/*.lua",
}

server_scripts {
"server.lua"
}

-- server_scripts {
-- "server/modules/*.lua",
-- }
20 changes: 20 additions & 0 deletions server.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
-- server.lua
RegisterServerEvent('drift:logToDiscord')
AddEventHandler('drift:logToDiscord', function(points)
Copy link
Contributor

Choose a reason for hiding this comment

The 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) ....

Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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",
Copy link
Contributor

Choose a reason for hiding this comment

The 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)