Hi there! I’m trying to figure out how to get when a bullet hits a marker. I’ve tried multiple ways but they don’t seem to work. So now I’m asking for help. I’ve provided the code down below. Thank’s for your help!
function startFlick360Game(gamemodeIndex, gamemode)
local playerPed = PlayerPedId()
FreezeEntityPosition(playerPed, true)
SetEntityInvincible(playerPed, true)
GiveWeaponToPed(playerPed, GetHashKey('WEAPON_HEAVYPISTOL'), 1000, false, true)
SetCurrentPedWeapon(playerPed, GetHashKey('WEAPON_HEAVYPISTOL'), true)
SetPedInfiniteAmmo(playerPed, true, GetHashKey('WEAPON_HEAVYPISTOL'))
SetPedInfiniteAmmoClip(playerPed, true)
toggleHudUIs(false)
DisplayRadar(false)
isGameActive = true
gameStats = { score = 0, timeLeft = 60, shotsFired = 0, shotsHit = 0, accuracy = 0 }
SendNUIMessage({
action = 'openGamemodeStatsUI',
score = gameStats.score,
timeLeft = gameStats.timeLeft,
accuracy = gameStats.accuracy
})
local targets = gamemode.targetLocations
local currentTargetCoords = nil
local function selectNewTarget()
local newTarget = targets[math.random(#targets)]
currentTargetCoords = vector3(newTarget.x, newTarget.y, newTarget.z + 0.5)
end
selectNewTarget()
CreateThread(function()
while isGameActive do
if currentTargetCoords then
DrawMarker(28, currentTargetCoords.x, currentTargetCoords.y, currentTargetCoords.z + 0.5, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.5, 0.5, 0.5, 255, 0, 0, 100, false, true, 2, false, nil, nil, false)
end
Wait(0)
end
end)
CreateThread(function()
local startTime = GetGameTimer()
while isGameActive do
local elapsed = math.floor((GetGameTimer() - startTime) / 1000)
gameStats.timeLeft = math.max(0, 60 - elapsed)
if IsPedShooting(playerPed) then
gameStats.shotsFired = gameStats.shotsFired + 1
local hit, impactCoords = GetPedLastWeaponImpactCoord(playerPed)
if hit and currentTargetCoords then
local distance = #(impactCoords - currentTargetCoords)
if distance < 0.5 then
gameStats.score = gameStats.score + 400
gameStats.shotsHit = gameStats.shotsHit + 1
selectNewTarget()
else
gameStats.score = gameStats.score - 100
end
end
end
gameStats.accuracy = gameStats.shotsFired > 0 and math.floor((gameStats.shotsHit / gameStats.shotsFired) * 100) or 0
SendNUIMessage({
action = 'updateGamemodeStatsUI',
score = gameStats.score,
timeLeft = gameStats.timeLeft,
accuracy = gameStats.accuracy
})
if gameStats.score >= 20000 or gameStats.timeLeft <= 0 then
resetGamemode(gamemodeIndex, gamemode)
break
end
Citizen.Wait(0)
end
end)
end