<commit_before>-- ////////////////////////////////////
-- //			MYSQL				 //
-- ////////////////////////////////////		
sqlUsername = exports.mysql:getMySQLUsername()
sqlPassword = exports.mysql:getMySQLPassword()
sqlDB = exports.mysql:getMySQLDBName()
sqlHost = exports.mysql:getMySQLHost()
sqlPort = exports.mysql:getMySQLPort()

handler = mysql_connect(sqlHost, sqlUsername, sqlPassword, sqlDB, sqlPort)

function checkMySQL()
	if not (mysql_ping(handler)) then
		handler = mysql_connect(sqlHost, sqlUsername, sqlPassword, sqlDB, sqlPort)
	end
end
setTimer(checkMySQL, 300000, 0)

function closeMySQL()
	if (handler) then
		mysql_close(handler)
	end
end
addEventHandler("onResourceStop", getResourceRootElement(getThisResource()), closeMySQL)
-- ////////////////////////////////////
-- //			MYSQL END			 //
-- ////////////////////////////////////

-- CELL PHONES
function callSomeone(thePlayer, commandName, phoneNumber, ...)
	local logged = getElementData(thePlayer, "loggedin")
	
	if (logged==1) then
		if (exports.global:doesPlayerHaveItem(thePlayer, 2)) then -- 2 = Cell phone item
			if not (phoneNumber) then
				outputChatBox("SYNTAX: /call [Phone Number]", thePlayer, 255, 194, 14)
			else
				local calling = getElementData(thePlayer, "calling")
				
				if (calling) then -- Using phone already
					outputChatBox("You are already using your phone.", thePlayer, 255, 0, 0)
				else
					exports.global:sendLocalMeAction(thePlayer, "takes out a cell phone.")
					if phoneNumber == "911" then
						executeCommandHandler( "911", thePlayer, ... )
					elseif phoneNumber == "081016" then
						if not executeCommandHandler( "081016", thePlayer ) then
							outputChatBox("You get a dead tone...", thePlayer, 255, 194, 14)
						end
					else
						local found, foundElement = false
						
						for key, value in ipairs(exports.pool:getPoolElementsByType("player")) do
							local logged = getElementData(value, "loggedin")
							
							if (logged==1) then
								local number = getElementData(value, "cellnumber")
								if (number==tonumber(phoneNumber)) then
									found = true
									foundElement = value
								end
							end
							
							if (found) then
								if not (exports.global:doesPlayerHaveItem(foundElement, 2)) then -- Check the target has a phone, if not, they weren't found
									found, foundElement = false
								end
							end
						end
						
						local money = getElementData(thePlayer, "money")
						
						if (money<10) then
							outputChatBox("You cannot afford a call.", thePlayer, 255, 0, 0)
						elseif not (found) then--or (foundElement==thePlayer) then -- Player with this phone number isnt online...
							outputChatBox("You get a dead tone...", thePlayer, 255, 194, 14)
						else
							local targetCalling = getElementData(foundElement, "calling")
							
							if (targetCalling) then
								outputChatBox("You get a busy tone.", thePlayer)
							else
								setElementData(thePlayer, "calling", foundElement, false)
								setElementData(thePlayer, "called", true, false)
								setElementData(foundElement, "calling", thePlayer, false)
								
								-- local player
								exports.global:applyAnimation(thePlayer, "ped", "phone_in", 1.0, 1.0, 0.0, false, true, true)
								toggleAllControls(thePlayer, true, true, true)
								setTimer(startPhoneAnim, 1000, 2, thePlayer)
								
								--player around target and target start ringing
								local x, y, z = getElementPosition(foundElement)
								local phoneSphere = createColSphere(x, y, z, 10)
								for _,nearbyPlayer in ipairs(getElementsWithinColShape(phoneSphere)) do
									triggerClientEvent(nearbyPlayer, "startRinging", foundElement, 1)
								end
								destroyElement(phoneSphere)
								
								-- target player
								exports.global:sendLocalMeAction(foundElement, "'s Phone start's to ring.")
								outputChatBox("Your phone is ringing. (( /pickup to answer ))", foundElement, 255, 194, 14)
								
								exports.global:givePlayerAchievement(thePlayer, 16) -- On the Blower
								
								-- Give the target 10 seconds to answer the call
								setTimer(cancelCall, 10000, 1, thePlayer)
								setTimer(cancelCall, 10000, 1, foundElement)
							end
						end
					end
				end
			end
		else
			outputChatBox("Believe it or not, it's hard to dial on a cellphone you do not have.", thePlayer, 255, 0, 0)
		end
	end
end
addCommandHandler("call", callSomeone)
addEvent("remoteCall", true)
addEventHandler("remoteCall", getRootElement(), callSomeone)

function startPhoneAnim(thePlayer)
	exports.global:applyAnimation(thePlayer, "ped", "phone_talk", 1.0, 1.0, 0.0, true, true, true)
	toggleAllControls(thePlayer, true, true, true)
end
	

function cancelCall(thePlayer)
	local phoneState = getElementData(thePlayer, "phonestate")
	
	if (phoneState==0) then
		setElementData(thePlayer, "calling", nil, false)
		setElementData(thePlayer, "called", nil, false)
	end
end

function answerPhone(thePlayer, commandName)
	local logged = getElementData(thePlayer, "loggedin")
	
	if (logged==1) then
		if (exports.global:doesPlayerHaveItem(thePlayer, 2)) then -- 2 = Cell phone item
			local phoneState = getElementData(thePlayer, "phonestate")
			local calling = getElementData(thePlayer, "calling")
			
			if (calling) then
				if (phoneState==0) then
					local target = calling
					outputChatBox("You picked up the phone.", thePlayer)
					outputChatBox("They picked up the phone.", target)
					exports.global:sendLocalMeAction(thePlayer, "takes out a cell phone.")
					setElementData(thePlayer, "phonestate", 1, false) -- Your in an actual call
					setElementData(calling, "phonestate", 1, false) -- Your in an actual call
					exports.global:sendLocalMeAction(thePlayer, "answers their cellphone.")
					
					local x, y, z = getElementPosition(target)
					local phoneSphere = createColSphere(x, y, z, 10)
					for _,nearbyPlayer in ipairs(getElementsWithinColShape(phoneSphere)) do
						triggerClientEvent(nearbyPlayer, "stopRinging", target)
					end
					destroyElement(phoneSphere)
					
					exports.global:applyAnimation(calling, "ped", "phone_in", 1.0, 1.0, 0.0, false, true, true)
					toggleAllControls(calling, true, true, true)
					setTimer(startPhoneAnim, 1000, 2, calling)
				end
			elseif not (calling) then
				outputChatBox("Your phone is not ringing.", thePlayer, 255, 0, 0)
			elseif (phoneState==1) or (phoneState==2) then
				outputChatBox("Your phone is already in use.", thePlayer, 255, 0, 0)
			end
		else
			outputChatBox("Believe it or not, it's hard to use a cellphone you do not have.", thePlayer, 255, 0, 0)
		end
	end
end
addCommandHandler("pickup", answerPhone)

function hangupPhone(thePlayer, commandName)
	local logged = getElementData(thePlayer, "loggedin")
	
	if (logged==1) then<commit_msg>fixed #1000: Ringtone doesn't stop when picking up the phone<commit_after>-- ////////////////////////////////////
-- //			MYSQL				 //
-- ////////////////////////////////////		
sqlUsername = exports.mysql:getMySQLUsername()
sqlPassword = exports.mysql:getMySQLPassword()
sqlDB = exports.mysql:getMySQLDBName()
sqlHost = exports.mysql:getMySQLHost()
sqlPort = exports.mysql:getMySQLPort()

handler = mysql_connect(sqlHost, sqlUsername, sqlPassword, sqlDB, sqlPort)

function checkMySQL()
	if not (mysql_ping(handler)) then
		handler = mysql_connect(sqlHost, sqlUsername, sqlPassword, sqlDB, sqlPort)
	end
end
setTimer(checkMySQL, 300000, 0)

function closeMySQL()
	if (handler) then
		mysql_close(handler)
	end
end
addEventHandler("onResourceStop", getResourceRootElement(getThisResource()), closeMySQL)
-- ////////////////////////////////////
-- //			MYSQL END			 //
-- ////////////////////////////////////

-- CELL PHONES
function callSomeone(thePlayer, commandName, phoneNumber, ...)
	local logged = getElementData(thePlayer, "loggedin")
	
	if (logged==1) then
		if (exports.global:doesPlayerHaveItem(thePlayer, 2)) then -- 2 = Cell phone item
			if not (phoneNumber) then
				outputChatBox("SYNTAX: /call [Phone Number]", thePlayer, 255, 194, 14)
			else
				local calling = getElementData(thePlayer, "calling")
				
				if (calling) then -- Using phone already
					outputChatBox("You are already using your phone.", thePlayer, 255, 0, 0)
				else
					exports.global:sendLocalMeAction(thePlayer, "takes out a cell phone.")
					if phoneNumber == "911" then
						executeCommandHandler( "911", thePlayer, ... )
					elseif phoneNumber == "081016" then
						if not executeCommandHandler( "081016", thePlayer ) then
							outputChatBox("You get a dead tone...", thePlayer, 255, 194, 14)
						end
					else
						local found, foundElement = false
						
						for key, value in ipairs(exports.pool:getPoolElementsByType("player")) do
							local logged = getElementData(value, "loggedin")
							
							if (logged==1) then
								local number = getElementData(value, "cellnumber")
								if (number==tonumber(phoneNumber)) then
									found = true
									foundElement = value
								end
							end
							
							if (found) then
								if not (exports.global:doesPlayerHaveItem(foundElement, 2)) then -- Check the target has a phone, if not, they weren't found
									found, foundElement = false
								end
							end
						end
						
						local money = getElementData(thePlayer, "money")
						
						if (money<10) then
							outputChatBox("You cannot afford a call.", thePlayer, 255, 0, 0)
						elseif not (found) then--or (foundElement==thePlayer) then -- Player with this phone number isnt online...
							outputChatBox("You get a dead tone...", thePlayer, 255, 194, 14)
						else
							local targetCalling = getElementData(foundElement, "calling")
							
							if (targetCalling) then
								outputChatBox("You get a busy tone.", thePlayer)
							else
								setElementData(thePlayer, "calling", foundElement, false)
								setElementData(thePlayer, "called", true, false)
								setElementData(foundElement, "calling", thePlayer, false)
								
								-- local player
								exports.global:applyAnimation(thePlayer, "ped", "phone_in", 1.0, 1.0, 0.0, false, true, true)
								toggleAllControls(thePlayer, true, true, true)
								setTimer(startPhoneAnim, 1000, 2, thePlayer)
								
								--player around target and target start ringing
								local x, y, z = getElementPosition(foundElement)
								local phoneSphere = createColSphere(x, y, z, 10)
								for _,nearbyPlayer in ipairs(getElementsWithinColShape(phoneSphere)) do
									triggerClientEvent(nearbyPlayer, "startRinging", foundElement, 1)
								end
								destroyElement(phoneSphere)
								
								-- target player
								exports.global:sendLocalMeAction(foundElement, "'s Phone start's to ring.")
								outputChatBox("Your phone is ringing. (( /pickup to answer ))", foundElement, 255, 194, 14)
								
								exports.global:givePlayerAchievement(thePlayer, 16) -- On the Blower
								
								-- Give the target 10 seconds to answer the call
								setTimer(cancelCall, 10000, 1, thePlayer)
								setTimer(cancelCall, 10000, 1, foundElement)
							end
						end
					end
				end
			end
		else
			outputChatBox("Believe it or not, it's hard to dial on a cellphone you do not have.", thePlayer, 255, 0, 0)
		end
	end
end
addCommandHandler("call", callSomeone)
addEvent("remoteCall", true)
addEventHandler("remoteCall", getRootElement(), callSomeone)

function startPhoneAnim(thePlayer)
	exports.global:applyAnimation(thePlayer, "ped", "phone_talk", 1.0, 1.0, 0.0, true, true, true)
	toggleAllControls(thePlayer, true, true, true)
end
	

function cancelCall(thePlayer)
	local phoneState = getElementData(thePlayer, "phonestate")
	
	if (phoneState==0) then
		setElementData(thePlayer, "calling", nil, false)
		setElementData(thePlayer, "called", nil, false)
	end
end

function answerPhone(thePlayer, commandName)
	local logged = getElementData(thePlayer, "loggedin")
	
	if (logged==1) then
		if (exports.global:doesPlayerHaveItem(thePlayer, 2)) then -- 2 = Cell phone item
			local phoneState = getElementData(thePlayer, "phonestate")
			local calling = getElementData(thePlayer, "calling")
			
			if (calling) then
				if (phoneState==0) then
					local target = calling
					outputChatBox("You picked up the phone.", thePlayer)
					outputChatBox("They picked up the phone.", target)
					exports.global:sendLocalMeAction(thePlayer, "takes out a cell phone.")
					setElementData(thePlayer, "phonestate", 1, false) -- Your in an actual call
					setElementData(calling, "phonestate", 1, false) -- Your in an actual call
					exports.global:sendLocalMeAction(thePlayer, "answers their cellphone.")
					
					local x, y, z = getElementPosition(target)
					local phoneSphere = createColSphere(x, y, z, 10)
					for _,nearbyPlayer in ipairs(getElementsWithinColShape(phoneSphere)) do
						triggerClientEvent(nearbyPlayer, "stopRinging", thePlayer)
					end
					destroyElement(phoneSphere)
					
					exports.global:applyAnimation(calling, "ped", "phone_in", 1.0, 1.0, 0.0, false, true, true)
					toggleAllControls(calling, true, true, true)
					setTimer(startPhoneAnim, 1000, 2, calling)
				end
			elseif not (calling) then
				outputChatBox("Your phone is not ringing.", thePlayer, 255, 0, 0)
			elseif (phoneState==1) or (phoneState==2) then
				outputChatBox("Your phone is already in use.", thePlayer, 255, 0, 0)
			end
		else
			outputChatBox("Believe it or not, it's hard to use a cellphone you do not have.", thePlayer, 255, 0, 0)
		end
	end
end
addCommandHandler("pickup", answerPhone)

function hangupPhone(thePlayer, commandName)
	local logged = getElementData(thePlayer, "loggedin")
	
	if (logged==1) then
{'fraction_non_alphanumeric': 0.12423043095866315, 'fraction_numerical': 0.022720609791849897, 'mean_word_length': 3.1074653822998193, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2397561', 'n_tokens_mistral': 5470, 'n_tokens_neox': 3966, 'n_words': 1196}