How would i create another marker and where you can press E and it does stuff?
I have tried messing around with the code for about 4-5 hours now but i never seem to get the script to know when iâm 1.2 feet away from it,
I have tried copying the local table table and renaming it to table2 and then copying over this code and changing table to table2
Citizen.CreateThread(function()
while true do
Citizen.Wait(5) -- this probably does not need to be every tick. try higher numbers
local playerCoords = GetEntityCoords(GetPlayerPed(-1), false) -- moved this outside of the loop, since you shouldn't need to look up the player's position for each location
for k, coords in pairs(table) do -- the second value returned by pairs is the value, so you don't need to do table[k], you can just access the value directly
local dist = Vdist(playerCoords.x, playerCoords.y, playerCoords.z, coords.x, coords.y, coords.z)
if dist <= 1.2 then
DrawTxt("Press E To Rob The 24/7")
if IsControlJustPressed(1,51) then
if cooldownSecondsRemaining <= 0 then
TriggerEvent('chatMessage', 'Robbery', {255, 0, 0}, " Robbery has been started and alarm has been triggered.")
TriggerServerEvent("24robbery", 2)
handleCooldown()
else
local minutes = math.floor(cooldownSecondsRemaining / 60) -- divide the total seconds remaining by 60 to get minutes, pass it to math.floor to strip off the decimals
local seconds = cooldownSecondsRemaining - minutes * 60 -- get the seconds left that don't make up a full minute
local cooldownMessage = string.format(" This store has recently been robbed! Please wait %dm, %ds", minutes, seconds)
TriggerEvent('chatMessage', 'Robbery', {255, 0, 0}, cooldownMessage)
end
end
end
end
end
end)
I have also tried renaming stuff like playerCoords, coords and dist
to playerCoords2, coords2 and dist2
but it just doesnt work.
Iâm really not sure how to add another location to it and would appreciate any help
full client code (without any code trying to add a second location, altough the second marker code is still there at the top):
local initialCooldownSeconds = 60
local cooldownSecondsRemaining = 0
local table = {
{x = 1961.58, y = 3749.25, z = 31.343738555908} -- Enter the coords of the maker here --
}
Citizen.CreateThread(function()
while true do
Citizen.Wait(5)
for k in pairs(table) do
-- Draw Marker Here --
DrawMarker(1, table[k].x, table[k].y, table[k].z, 0, 0, 0, 0, 0, 0, 1.001, 1.0001, 0.5001, 0, 0, 255, 200, 0, 0, 0, 0)
end
DrawMarker(1, 1982.8, 3053.48, 46.26, 0, 0, 0, 0, 0, 0, 1.001, 1.0001, 0.5001, 0, 0, 255, 200, 0, 0, 0, 0)
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(5) -- this probably does not need to be every tick. try higher numbers
local playerCoords = GetEntityCoords(GetPlayerPed(-1), false) -- moved this outside of the loop, since you shouldn't need to look up the player's position for each location
for k, coords in pairs(table) do -- the second value returned by pairs is the value, so you don't need to do table[k], you can just access the value directly
local dist = Vdist(playerCoords.x, playerCoords.y, playerCoords.z, coords.x, coords.y, coords.z)
if dist <= 1.2 then
DrawTxt("Press E To Rob The 24/7")
if IsControlJustPressed(1,51) then
if cooldownSecondsRemaining <= 0 then
TriggerEvent('chatMessage', 'Robbery', {255, 0, 0}, " Robbery has been started and alarm has been triggered.")
TriggerServerEvent("24robbery", 2)
handleCooldown()
else
local minutes = math.floor(cooldownSecondsRemaining / 60) -- divide the total seconds remaining by 60 to get minutes, pass it to math.floor to strip off the decimals
local seconds = cooldownSecondsRemaining - minutes * 60 -- get the seconds left that don't make up a full minute
local cooldownMessage = string.format(" This store has recently been robbed! Please wait %dm, %ds", minutes, seconds)
TriggerEvent('chatMessage', 'Robbery', {255, 0, 0}, cooldownMessage)
end
end
end
end
end
end)
Citizen.CreateThread(function()
while true do
citizen.wait(5)
local playerCoords = GetEntityCoords(GetPlayerPed(-1), false) -- moved this outside of the loop, since you shouldn't need to look up the player's position for each location
for k, coords in pairs(table) do -- the second value returned by pairs is the value, so you don't need to do table[k], you can just access the value directly
local dist = Vdist(playerCoords.x, playerCoords.y, playerCoords.z, 1982.8, 3053.48, 46.26)
if dist <= 1.2 then
DrawTxt("Press E To Rob The Yellow Jack")
if IsControlJustPressed(1,51) then
if cooldownSecondsRemaining <= 0 then
TriggerEvent('chatMessage', 'Robbery', {255, 0, 0}, " Robbery has been started and alarm has been triggered.")
TriggerServerEvent("24robbery", 2)
handleCooldown()
else
local minutes = math.floor(cooldownSecondsRemaining / 60) -- divide the total seconds remaining by 60 to get minutes, pass it to math.floor to strip off the decimals
local seconds = cooldownSecondsRemaining - minutes * 60 -- get the seconds left that don't make up a full minute
local cooldownMessage = string.format(" This store has recently been robbed! Please wait %dm, %ds", minutes, seconds)
TriggerEvent('chatMessage', 'Robbery', {255, 0, 0}, cooldownMessage)
end
end
end
end
end
end)
Citizen.CreateThread(function()
while true do
Citizen.Wait(1000)
if cooldownSecondsRemaining == 1 then
TriggerEvent('chatMessage', 'Robbery', {255, 0, 0}, "Robbery cooldown is now over.")
end
end
end)
function handleCooldown()
cooldownSecondsRemaining = initialCooldownSeconds
Citizen.CreateThread(function()
while cooldownSecondsRemaining > 0 do
Citizen.Wait(1000)
cooldownSecondsRemaining = cooldownSecondsRemaining - 1
end
end)
end
function DrawTxt(text)
SetTextFont(0)
SetTextProportional(1)
SetTextScale(0.0, 0.45)
SetTextDropshadow(1, 0, 0, 0, 255)
SetTextEdge(1, 0, 0, 0, 255)
SetTextDropShadow()
SetTextOutline()
SetTextEntry("STRING")
AddTextComponentString(text)
DrawText(0.174, 0.855)
end