diff --git a/README.md b/README.md index fe62703..461e477 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,16 @@ -# FiveM StreetRaces +ORIGINAL: https://github.com/bepo13/FiveM-StreetRaces +# FiveM StreetRaces FiveM resource for street races with custom checkpoints and HUD. ## Installation - 1. Add the StreetRaces folder to your FiveM resources directory -2. Edit your server.cfg and add "start StreetRaces" +2. Edit your server.cfg and add "start StreetRaces" (or "ensure StreetRaces") + +### Added things +1. ESX support (credits to nojdh, https://github.com/bepo13/FiveM-StreetRaces/pull/1) +2. Shared races. Everyone can see, start, edit, delete the races, no longer tied to steam id +3. Map blips where the races begin (first checkpoint) +4. Markers at the blips to quick start the races (no need to type /race start -money- -time-) +5. More configurations: blip color, unique blip names, marker color , quickstart money ammount etc.. +6. video: https://www.youtube.com/watch?v=7VLbqP7pa8A diff --git a/StreetRaces/config.lua b/StreetRaces/config.lua index 0f87cdb..3027a6b 100644 --- a/StreetRaces/config.lua +++ b/StreetRaces/config.lua @@ -9,7 +9,18 @@ config_cl = { checkpointHeight = 10.0, -- Height of 3D checkpoints in meters checkpointBlipColor = 5, -- Color of checkpoint map blips and navigation (see SetBlipColour native reference) hudEnabled = true, -- Enable racing HUD with time and checkpoints - hudPosition = vec(0.015, 0.725) -- Screen position to draw racing HUD + hudPosition = vec(0.015, 0.725), -- Screen position to draw racing HUD + + showBlips = true, -- Draw blips on the map for custom races + blipColor = 3, -- Map blip color + blipsUpdateTime = 30000, -- How often should the client update the blips on the map in milliseconds (dont set it to 0 or a small number, blips will blink or wont even show up) + uniqueBlipNames = false, -- True = blip's name will be the name of the race, False = every blip will be called Custom Race and will be grouped together + quickStartMarkers = true, -- Spawn quickstart markers on the game world. Press ~INPUT_DETONATE~ (G) to start the race lobby + quickStartMarkerColorRed = 0, -- Quickstart marker color red value + quickStartMarkerColorGreen = 128, -- Quickstart marker color green value + quickStartMarkerColorBlue = 255, -- Quickstart marker color blue value + quickStartMoney = 0, -- Quickstart wager + quickStartReadyUpTime = 20 -- Quickstart race wait time in seconds } -- SERVER CONFIGURATION diff --git a/StreetRaces/port_sv.lua b/StreetRaces/port_sv.lua index 7a30a82..9a646be 100644 --- a/StreetRaces/port_sv.lua +++ b/StreetRaces/port_sv.lua @@ -1,29 +1,33 @@ +ESX = nil +TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) + -- Helper function for getting player money function getMoney(source) - -- Add framework API's here (return large number by default) - return 1000000 + local xPlayer = ESX.GetPlayerFromId(source) + local getmoney = xPlayer.getMoney() + return getmoney end -- Helper function for removing player money function removeMoney(source, amount) - -- Add framework API's here + local xPlayer = ESX.GetPlayerFromId(source) + xPlayer.removeMoney(amount) end -- Helper function for adding player money function addMoney(source, amount) - -- Add framework API's here + local xPlayer = ESX.GetPlayerFromId(source) + xPlayer.addMoney(amount) end -- Helper function for getting player name function getName(source) - -- Add framework API's here return GetPlayerName(source) end -- Helper function for notifying players function notifyPlayer(source, msg) - -- Add custom notification here (use chat by default) - TriggerClientEvent('chatMessage', source, "[StreetRaces]", {255, 0, 0}, msg) + TriggerClientEvent('chatMessage', source, "[RACE]", {255,64,64}, msg) end -- Saved player data and file @@ -44,8 +48,8 @@ function loadPlayerData(source) end -- Get player steamID from source and use as key to get player data - local playerId = string.sub(GetPlayerIdentifier(source, 0), 7, -1) - local playerData = playersData[playerId] + -- local playerId = string.sub(GetPlayerIdentifier(source, 0), 7, -1) + local playerData = playersData["all"] -- Return saved player data if playerData == nil then @@ -68,8 +72,8 @@ function savePlayerData(source, data) end -- Get player steamID from source and use as key to save player data - local playerId = string.sub(GetPlayerIdentifier(source, 0), 7, -1) - playersData[playerId] = data + -- local playerId = string.sub(GetPlayerIdentifier(source, 0), 7, -1) + playersData["all"] = data -- Save file local file = io.open(playersDataFile, "w+") diff --git a/StreetRaces/races_cl.lua b/StreetRaces/races_cl.lua index 7c18a1c..b162615 100644 --- a/StreetRaces/races_cl.lua +++ b/StreetRaces/races_cl.lua @@ -17,6 +17,9 @@ local raceStatus = { -- Recorded checkpoints local recordedCheckpoints = {} +-- Blips +local allBlips = {} + -- Main command for races RegisterCommand("race", function(source, args) if args[1] == "clear" or args[1] == "leave" then @@ -40,7 +43,7 @@ RegisterCommand("race", function(source, args) local name = args[2] if name ~= nil and #recordedCheckpoints > 0 then -- Send event to server to save checkpoints - TriggerServerEvent('StreetRaces:saveRace_sv', name, recordedCheckpoints) + TriggerServerEvent('StreetRaces:saveRace_sv', name, recordedCheckpoints) end elseif args[1] == "delete" then -- Check name was provided and send event to server to delete saved race @@ -433,3 +436,111 @@ function Draw2DText(x, y, text, scale) AddTextComponentString(text) DrawText(x, y) end + +-- Updating blips +if config_cl.showBlips == true then + Citizen.CreateThread(function() + while true do + Citizen.Wait(0) + -- Remove current blips + for i, value in pairs(allBlips) do + RemoveBlip(allBlips[i][2]) + end + allBlips = {} + + -- Get new blips + TriggerServerEvent("StreetRaces:getNewCoordsForBlips_sv") + + -- Cooldown + Citizen.Wait(config_cl.blipsUpdateTime) + + end + end) +end + +-- Adding blips to the table (server side calls this) +RegisterNetEvent("StreetRaces:addBlipToTable") +AddEventHandler("StreetRaces:addBlipToTable", function(name, x, y, z) + local blip = AddBlipForCoord(x, y, z) + SetBlipSprite(blip, 315) + SetBlipDisplay(blip, 4) + SetBlipScale (blip, 0.9) + SetBlipColour (blip, config_cl.blipColor) + SetBlipAsShortRange(blip, true) + BeginTextCommandSetBlipName("STRING") + if (config_cl.uniqueBlipNames == true) then + AddTextComponentString(tostring(name)) + else + AddTextComponentString(tostring("Custom Race")) + end + EndTextCommandSetBlipName(blip) + table.insert(allBlips,{name,blip}) +end) + +-- Spawn markers to quickstart races +if config_cl.quickStartMarkers == true then + local gotMessage = false; + Citizen.CreateThread(function() + while true do + Citizen.Wait(0) + for i, value in pairs(allBlips) do + local pedCoords = GetEntityCoords(PlayerPedId()) + local markerPos = GetBlipCoords(allBlips[i][2]) + local distance = #(pedCoords - markerPos) + if distance < 50.0 then + DrawMarker( + 1, + markerPos.x, + markerPos.y, + markerPos.z, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 0.0, + 7.0, + 7.0, + 2.0, + config_cl.quickStartMarkerColorRed, + config_cl.quickStartMarkerColorGreen, + config_cl.quickStartMarkerColorBlue, + 50, + false, + false, + 2, + nil, + nil, + nil, + false + ) + if distance < 10.0 then + if gotMessage == false then + DisplayHelpText("Press ~INPUT_DETONATE~ to launch this race") + --TriggerEvent('chat:addMessage', { + -- color = { 255, 0, 0}, + -- multiline = true, + -- args = {"Me", "You are here"} + --}) + gotMessage = true + end + if IsControlJustReleased(0, 47) and raceStatus.state == RACE_STATE_NONE then + ExecuteCommand("race load " .. allBlips[i][1]) + Citizen.Wait(100) + ExecuteCommand("race start " .. config_cl.quickStartMoney .. " " .. config_cl.quickStartReadyUpTime) + end + else + gotMessage = false + end + end + end + end + end) +end + +-- You can display help texts with this function +function DisplayHelpText(text) + BeginTextCommandDisplayHelp("STRING") + AddTextComponentSubstringPlayerName(text) + DisplayHelpTextFromStringLabel(0, 0, 1, -1) +end \ No newline at end of file diff --git a/StreetRaces/races_sv.lua b/StreetRaces/races_sv.lua index f2098bf..183aa74 100644 --- a/StreetRaces/races_sv.lua +++ b/StreetRaces/races_sv.lua @@ -242,3 +242,12 @@ AddEventHandler("StreetRaces:loadRace_sv", function(name) notifyPlayer(source, msg) end end) + +-- Feeding new race blips to the clients +RegisterNetEvent("StreetRaces:getNewCoordsForBlips_sv") +AddEventHandler("StreetRaces:getNewCoordsForBlips_sv", function() + local playerRaces = loadPlayerData(source) + for name, race in pairs(playerRaces) do + TriggerClientEvent("StreetRaces:addBlipToTable", source, name, race[1].coords.x, race[1].coords.y, race[1].coords.z) + end +end) \ No newline at end of file