optimize this code ``` RegisterNetEvent('qb-graffiti:firsttimegraffiti', function(sprays)
for i, spray in next, sprays do
if Config.EnableContest then
exports[Config.TargetFolderName]:AddTargetModel(Props(), {
options = {
{
index = 1,
type = "client",
action = function(graffiti)
QBCore.Functions.TriggerCallback('ol-graffiti:server:canReplace', function(result)
print(result)
if result then
QBCore.Functions.Notify('You can't do this now', 'error')
else
local coords = GetEntityCoords(graffiti)
TriggerServerEvent('qb-graffiti:server:addtodiscorver', coords)
end
end) end,
icon = Config.Text.TARGET_GRAFFITI.DIS_ICON,
label = Config.Text.TARGET_GRAFFITI.DISCOVER,
canInteract = function()
QBCore.Functions.TriggerCallback('ol-graffiti:server:getgang', function(result)
if QBCore.Functions.GetPlayerData().gang.name == result then
getgang = false
else
getgang = true
end
end)
return getgang
end,
},
{
index = 2,
action = function(entity)
QBCore.Functions.TriggerCallback('ol-graffiti:server:canReplace', function(result)
if result then
QBCore.Functions.Notify('You can't do this now', 'error')
else
TriggerEvent('qb-spray:startContest', entity)
end
end)
end,
icon = Config.Text.TARGET_GRAFFITI.CONTEST_ICON,
label = Config.Text.TARGET_GRAFFITI.CONTEST,
canInteract = function()
QBCore.Functions.TriggerCallback('ol-graffiti:server:getgang', function(result)
if QBCore.Functions.GetPlayerData().gang.name == result then
getgang = false
else
getgang = true
end
end)
return getgang
end,
},
{
index = 3,
action = function(entity)
TriggerEvent('qb-spray:deleteGraffiti', entity)
end,
icon = Config.Text.TARGET_GRAFFITI.SCRA_ICON,
label = Config.Text.TARGET_GRAFFITI.SCRATCH,
canInteract = function()
QBCore.Functions.TriggerCallback('ol-graffiti:server:canReplace', function(result)
if result then
fahad = true
else
fahad = false
end
end)
print(fahad)
return fahad
end,
},
{
index = 4,
action = function(entity)
TriggerEvent('qb-spray:startReplace', entity)
end,
icon = Config.Text.TARGET_GRAFFITI.SCRA_ICON,
label = 'replace',
canInteract = function()
QBCore.Functions.TriggerCallback('ol-graffiti:server:canReplace', function(result)
if result then
fahad = true
else
fahad = false
end
end)
return fahad
end,
},
{
index = 5,
action = function(entity)
TriggerEvent('qb-spray:DeleteSpray', entity)
end,
icon = Config.Text.TARGET_GRAFFITI.SCRA_ICON,
label = 'Delete Spray',
canInteract = function()
if QBCore.Functions.GetPlayerData().gang.name == 'mafia' and QBCore.Functions.GetPlayerData().gang.grade.level == 3 then
return true
else
return false
end
end,
},
},
distance = 2.0,
})
else
exports[Config.TargetFolderName]:AddTargetModel(props, {
options = {
{
index = 1,
type = "client",
action = function(graffiti)
local coords = GetEntityCoords(graffiti)
TriggerServerEvent('qb-graffiti:server:addtodiscorver', coords)
end,
icon = Config.Text.TARGET_GRAFFITI.DIS_ICON,
label = Config.Text.TARGET_GRAFFITI.DISCOVER,
},
{
index = 2,
action = function(entity)
TriggerEvent('qb-spray:deleteGraffiti', entity)
end,
icon = Config.Text.TARGET_GRAFFITI.SCRA_ICON,
label = Config.Text.TARGET_GRAFFITI.SCRATCH,
},
},
distance = 2.0,
})
end
end
end)