Jump to content

Need help with infinite/long execution.


Recommended Posts

Hi guys. I saw some topics about it but the problem is that I don't have timer in this script but it just gives that error anyway.(İnfinite/long execution). Can you tell me what the problem is with this script ?

Btw, these codes are not leaked at all...

 

local selectedQuests = {{}}
function startStep11(retest)
	local remainHours, remainMinutes, remainSeconds = nil
	local userid = getElementData(client, "account:id")
	local faData = exports.mysql:query_fetch_assoc("SELECT (UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(`forceapp_date`)) AS `secdiff` FROM `force_apps` WHERE `account`='"..userid.."' LIMIT 1")
	if faData and faData["secdiff"] and tonumber(faData["secdiff"]) then
		
		local secdiff = tonumber(faData["secdiff"])
		local secsInADay = 60*60*24
						-- sec,min,hour
		if secdiff < secsInADay then
			remainHours = math.floor((secsInADay-secdiff)/60/60)
			if remainHours <= 0 then
				remainMinutes = math.floor((secsInADay-secdiff)/60)
				if remainMinutes <= 0 then
					remainSeconds = math.floor(secsInADay-secdiff)
				end
			end
		else
			exports.mysql:query_free("DELETE FROM `force_apps` WHERE `account`='"..userid.."' ")
		end
	end
	
	selectedQuests[client] = {}
	local quests = {} 
	local preparedQ = ""
	local mQuery = nil
	
	preparedQ = "SELECT * FROM `applications_questions` WHERE `part`='1' "
	mQuery = exports.mysql:query(preparedQ)
	while true do
		local row = exports.mysql:fetch_assoc(mQuery)
		if not row then break end
		table.insert(quests, row )
	end
	exports.mysql:free_result(mQuery)
	
	while #selectedQuests[client] < 6 do
		local ran = math.random(1, #quests)
		if not isThisQuestSelected(client, quests[ran]) then
			table.insert(selectedQuests[client], quests[ran])
		end
	end
	
	triggerClientEvent(client, "apps:step11", client, selectedQuests[client], retest, remainHours, remainMinutes, remainSeconds)
	selectedQuests[client] = nil
end
addEvent("apps:startStep11", true)
addEventHandler("apps:startStep11", root, startStep11)

function isThisQuestSelected(client, quest)
	for i = 1, #selectedQuests[client] do
		if quest == selectedQuests[client][i] then
			return true
		end
	end
	return false
end

function finishStep1()
	if source and isElement(source) and getElementType(source) == "player" then
		client = source
	end
	local id = getElementData(client, "account:id")
	if id then
		local preparedQuery = "UPDATE `accounts` SET `appstate`='1' WHERE `id`='"..id.."' "
		if exports.mysql:query_free(preparedQuery) then
	    triggerEvent("apps:startStep2", client)
		end
end
end
addEvent("apps:finishStep1", true)
addEventHandler("apps:finishStep1", root, finishStep1)

 

Edited by mehmetejr
...
Link to comment
  • MTA Team

This will loop forever if #quests < 6

	while #selectedQuests[client] < 6 do
		local ran = math.random(1, #quests)
		if not isThisQuestSelected(client, quests[ran]) then
			table.insert(selectedQuests[client], quests[ran])
		end
	end

 

Link to comment
1 minute ago, ccw said:

This will loop forever if #quests < 6


	while #selectedQuests[client] < 6 do
		local ran = math.random(1, #quests)
		if not isThisQuestSelected(client, quests[ran]) then
			table.insert(selectedQuests[client], quests[ran])
		end
	end


 

So what u suggest for it ? I mean how can I fix it ? (I am new to scripting, so still learning)

Link to comment
  • MTA Team
	while #selectedQuests[client] < math.min(6,#quests) do
		local ran = math.random(1, #quests)
		if not isThisQuestSelected(client, quests[ran]) then
			table.insert(selectedQuests[client], quests[ran])
		end
	end

I think this would be better

Link to comment
11 minutes ago, DNL291 said:

Try:


for i=1, #quests do
	if not isThisQuestSelected(client, quests[i]) then
		table.insert(selectedQuests[client], quests[i])
	end
end

 

I think the problem is with my account-system.But thanks for helping anyway :)

4 minutes ago, ccw said:

	while #selectedQuests[client] < math.min(6,#quests) do
		local ran = math.random(1, #quests)
		if not isThisQuestSelected(client, quests[ran]) then
			table.insert(selectedQuests[client], quests[ran])
		end
	end

I think this would be better

I think the problem is with my account-system.But thanks for helping anyway  :)  

Btw, sometimes I get the abort error with 68th line of script.Maybe this is the problem ?

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...