Skip to content
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

ESX version, map blips, markers to quicklaunch race, shared races #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
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
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
13 changes: 12 additions & 1 deletion StreetRaces/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 15 additions & 11 deletions StreetRaces/port_sv.lua
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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+")
Expand Down
113 changes: 112 additions & 1 deletion StreetRaces/races_cl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
9 changes: 9 additions & 0 deletions StreetRaces/races_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)