<commit_before>backupBlip = nil
backupPlayer = nil

function removeBackup(thePlayer, commandName)
	if (exports.global:isPlayerAdmin(thePlayer)) then
		if (backupPlayer~=nil) then
			destroyElement(backupBlip)
			removeEventHandler("onPlayerQuit", backupPlayer, destroyBlip)
			removeEventHandler("savePlayer", backupPlayer, destroyBlip)
			backupPlayer = nil
			backupBlip = nil
			outputChatBox("Backup system reset!", thePlayer, 255, 194, 14)
		else
			outputChatBox("Backup system did not need reset.", thePlayer, 255, 194, 14)
		end
	end
end
addCommandHandler("resetbackup", removeBackup, false, false)

function backup(thePlayer, commandName)
	local duty = tonumber(getElementData(thePlayer, "duty"))
	local theTeam = getPlayerTeam(thePlayer)
	local factionType = getElementData(theTeam, "type")
	
	if (factionType==2) and (duty>0) then
		if (backupBlip) and (backupPlayer~=thePlayer) then -- in use
			outputChatBox("There is already a backup beacon in use.", thePlayer, 255, 194, 14)
		elseif not (backupBlip) then -- make backup blip
			backupPlayer = thePlayer
			local x, y, z = getElementPosition(thePlayer)
			backupBlip = createBlip(x, y, z, 0, 3, 255, 0, 0, 255, 255, 32767)
			exports.pool:allocateElement(backupBlip)
			attachElements(backupBlip, thePlayer)
			
			addEventHandler("onPlayerQuit", thePlayer, destroyBlip)
			addEventHandler("savePlayer", thePlayer, destroyBlip)
			
			setElementVisibleTo(backupBlip, getRootElement(), false)
			
			for key, value in ipairs(getPlayersInTeam(theTeam)) do
				local duty = tonumber(getElementData(value, "duty"))
				
				if (duty>0) then
					outputChatBox("A unit needs urgent assistance! Please respond ASAP!", value, 255, 194, 14)
					setElementVisibleTo(backupBlip, value, true)
				end
			end
			
			
			for key, value in ipairs(exports.pool:getPoolElementsByType("player")) do
				local duty = getElementData(value, "duty")
				
				if (getPlayerTeam(value)~=theTeam) or (duty==0) then
					setElementVisibleTo(backupBlip, value, false)
				end
			end
		elseif (backupBlip) and (backupPlayer==thePlayer) then -- in use by this player
			for key, value in ipairs(getPlayersInTeam(theTeam)) do
			
				local duty = getElementData(value, "duty")
				
				if (duty>0) then
					outputChatBox("The unit no longer requires assistance. Resume normal patrol", value, 255, 194, 14)
				end
			end
			
			destroyElement(backupBlip)
			removeEventHandler("onPlayerQuit", thePlayer, destroyBlip)
			removeEventHandler("savePlayer", thePlayer, destroyBlip)
			backupPlayer = nil
			backupBlip = nil
		end
	end
end<commit_msg>More opts<commit_after>backupBlip = nil
backupPlayer = nil

function removeBackup(thePlayer, commandName)
	if (exports.global:isPlayerAdmin(thePlayer)) then
		if (backupPlayer~=nil) then
			destroyElement(backupBlip)
			removeEventHandler("onPlayerQuit", backupPlayer, destroyBlip)
			removeEventHandler("savePlayer", backupPlayer, destroyBlip)
			backupPlayer = nil
			backupBlip = nil
			outputChatBox("Backup system reset!", thePlayer, 255, 194, 14)
		else
			outputChatBox("Backup system did not need reset.", thePlayer, 255, 194, 14)
		end
	end
end
addCommandHandler("resetbackup", removeBackup, false, false)

function backup(thePlayer, commandName)
	local duty = tonumber(getElementData(thePlayer, "duty"))
	local theTeam = getPlayerTeam(thePlayer)
	local factionType = getElementData(theTeam, "type")
	
	if (factionType==2) and (duty>0) then
		if (backupBlip) and (backupPlayer~=thePlayer) then -- in use
			outputChatBox("There is already a backup beacon in use.", thePlayer, 255, 194, 14)
		elseif not (backupBlip) then -- make backup blip
			backupPlayer = thePlayer
			local x, y, z = getElementPosition(thePlayer)
			backupBlip = createBlip(x, y, z, 0, 3, 255, 0, 0, 255, 255, 32767)
			exports.pool:allocateElement(backupBlip)
			attachElements(backupBlip, thePlayer)
			
			addEventHandler("onPlayerQuit", thePlayer, destroyBlip)
			addEventHandler("savePlayer", thePlayer, destroyBlip)
			
			setElementVisibleTo(backupBlip, getRootElement(), false)
			
			for key, value in ipairs(getPlayersInTeam(theTeam)) do
				local duty = tonumber(getElementData(value, "duty"))
				
				if (duty>0) then
					outputChatBox("A unit needs urgent assistance! Please respond ASAP!", value, 255, 194, 14)
					setElementVisibleTo(backupBlip, value, true)
				end
			end
			
			
			for key, value in ipairs(exports.pool:getPoolElementsByType("player")) do
				local duty = getElementData(value, "duty")
				
				if (getPlayerTeam(value)~=theTeam) or (duty==0) then
					setElementVisibleTo(backupBlip, value, false)
				end
			end
		elseif (backupBlip) and (backupPlayer==thePlayer) then -- in use by this player
			for key, value in ipairs(getPlayersInTeam(theTeam)) do
			
				local duty = tonumber(getElementData(value, "duty"))
				
				if (duty>0) then
					outputChatBox("The unit no longer requires assistance. Resume normal patrol", value, 255, 194, 14)
				end
			end
			
			destroyElement(backupBlip)
			removeEventHandler("onPlayerQuit", thePlayer, destroyBlip)
			removeEventHandler("savePlayer", thePlayer, destroyBlip)
			backupPlayer = nil
			backupBlip = nil
		end
	end
end
{'fraction_non_alphanumeric': 0.09972941631233088, 'fraction_numerical': 0.02435253189022033, 'mean_word_length': 4.60064935064935, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2264103', 'n_tokens_mistral': 1988, 'n_tokens_neox': 1587, 'n_words': 454}