[SOLVED] Optimisation Problem in Code

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Post Reply
Message
Author
kutalmismete
Posts: 25
Joined: Thu May 26, 2016 6:26 am

[SOLVED] Optimisation Problem in Code

#1 Post by kutalmismete » Sat Oct 15, 2016 8:23 am

Code: Select all

repeat
			print('Active.')
			checkChat();
			if swapCheck == true then
				print('Battle Mode!')
				RoMScript("TargetUnit('raid1target');");
				target = player:getTarget();
				followTank();
				MScd = getCD(493546)
				PScd = getCD(493545)
				FTcd = getCD(495174)	
				if FTcd == 0 then
					RoMScript("MoveRaidMember(9, 6)")
					RoMScript("SetTitleRequest(530467)");
					player:cast("ALL_FIRE_TRAINING")
					RoMScript("MoveRaidMember(6, 9)")
					RoMScript("SendChatMessage('done', 'WHISPER', 0, '3rdguy')");
				end
				if (MScd == 0 or PScd == 0) and target and player:hasBuff(503827) then
					RoMScript("TargetUnit('raid1target');");
					player:cast("DRUID_WITHERING_SEED")
					if player:hasBuff(503827) then
						player:cast("DRUID_WEAKENING_SEED")
					end
				end
				getTank();
				followTank();
				healAll();
				if messageCh == "stop" and nameCh == "1stguy" then
					DWInactive = true
					print('Stopped.')
				end
			end
			if swapCheck == false then
				print('Heal Mode!')
				if messageParty == "buff" and nameParty ~= nil then
					sendPartyChat('Buffing...')
					player:cast("DRUID_AWAKENING_OF_THE_WILD")
					RoMScript("MoveRaidMember(9, 6);");
					player:cast("DRUID_AWAKENING_OF_THE_WILD")
					RoMScript("MoveRaidMember(6, 9);");
				end
				if messageWhisper == "done" and nameWhisper == "2ndguy" then
					swapCheck = true
				end 
				getTank();
				followTank();
				healAll();
			end
			yrest(100)
		until false
When I make swapCheck true or false, I can't use event monitor. Its like random. If swapCheck is set, script couldn't monitor my chat. But when I spam it, somehow it read. There is no problem with them. Only problem is, when I set swapCheck, event monitor doesn't work. There must be coding optimisation problem so I need help. Thanks in advance. NOTE: most of the functions are custom.
Last edited by kutalmismete on Tue Nov 01, 2016 12:56 am, edited 1 time in total.

kenzu38
Posts: 279
Joined: Sun Dec 02, 2012 8:52 am

Re: Optimisation Problem in Code

#2 Post by kenzu38 » Sat Oct 22, 2016 8:32 am

Can't tell with the code you posted. Post your checkChat() code too since it can be the source of the problem.

kutalmismete
Posts: 25
Joined: Thu May 26, 2016 6:26 am

Re: Optimisation Problem in Code

#3 Post by kutalmismete » Sun Oct 23, 2016 7:08 am

Code: Select all

function checkTankHP()
	local MEFcd = getCD(493529)
	getTank();
	raidTank = player:getTarget();
	if (raidTank.HP < raidTank.MaxHP/100*50) and raidTank.HP > 1 then
		if MEFcd == 0 then
			player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
		else
			getTank(target);
			player:cast("DRUID_MOTHER_EARTHS_PROTECTION")
			getTank();
			if player:hasBuff(503827) then
				player:cast("DRUID_RECOVER")
			else
				player:cast("DRUID_RESTORE_LIFE")
			end
		end
	elseif (raidTank.HP < raidTank.MaxHP/100*90) and (raidTank.HP > raidTank.MaxHP/100*50) and raidTank.HP > 1 then
		if MEFcd == 0 then
			player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
		else
			if player:hasBuff(503827) then
				player:cast("DRUID_RECOVER")
			else
				player:cast("DRUID_RESTORE_LIFE")
			end
		end
	elseif (raidTank.MaxHP/100*95 > raidTank.HP) and (	raidTank.HP > raidTank.MaxHP/100*90) and raidTank.HP > 1 then
		player:cast("DRUID_BLOSSOMING_LIFE");
	end
end

Code: Select all


function checkHP(_int)
	local MEFcd = getCD(493529)
	if _int == 1 then
		checkTankHP();
		RoMScript("TargetUnit('raid1');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 2 then
		checkTankHP();
		RoMScript("TargetUnit('raid2');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 3 then
		checkTankHP();
		RoMScript("TargetUnit('raid3');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 4 then
		checkTankHP();
		RoMScript("TargetUnit('raid4');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 5 then
		checkTankHP();
		RoMScript("TargetUnit('raid5');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 6 then
		checkTankHP();
		RoMScript("TargetUnit('raid6');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 7 then
		checkTankHP();
		RoMScript("TargetUnit('raid7');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 8 then
		checkTankHP();
		RoMScript("TargetUnit('raid8');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 9 then
		checkTankHP();
		RoMScript("TargetUnit('raid9');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 10 then
		checkTankHP();
		RoMScript("TargetUnit('raid10');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 11 then
		checkTankHP();
		RoMScript("TargetUnit('raid11');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	elseif _int == 12 then
		checkTankHP();
		RoMScript("TargetUnit('raid12');");
		raidTarget = player:getTarget();
		if (raidTarget.MaxHP/100*95 > raidTarget.HP) and (	raidTarget.HP > raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			player:cast("DRUID_BLOSSOMING_LIFE");
		elseif (raidTarget.HP < raidTarget.MaxHP/100*90) and raidTarget.HP > 1 then
			if MEFcd == 0 then
				player:cast("DRUID_MOTHER_EARTHS_FOUNTAIN")
			else
				if player:hasBuff(503827) then
					player:cast("DRUID_RECOVER")
				else
					player:cast("DRUID_RESTORE_LIFE")
				end
			end
		end
	end
end

Code: Select all

function healAll()
	checkHP(1);
	checkHP(2);
	checkHP(3);
	checkHP(4);
	checkHP(5);
	checkHP(9);
end

Code: Select all

function getTank(_string)
	if tank == 1 then
		RoMScript("TargetUnit('raid1');");
		if _string == "target" then
			RoMScript("TargetUnit('raid1target');");
		end
	elseif tank == 2 then
		RoMScript("TargetUnit('raid2');");
		if _string == "target" then
			RoMScript("TargetUnit('raid2target');");
		end
	elseif tank == 3 then
		RoMScript("TargetUnit('raid3');");
		if _string == "target" then
			RoMScript("TargetUnit('raid3target');");
		end
	elseif tank == 4 then
		RoMScript("TargetUnit('raid4');");
		if _string == "target" then
			RoMScript("TargetUnit('raid4target');");
		end
	elseif tank == 5 then
		RoMScript("TargetUnit('raid5');");
		if _string == "target" then
			RoMScript("TargetUnit('raid5target');");
		end
	elseif tank == 6 then
		RoMScript("TargetUnit('raid6');");
		if _string == "target" then
			RoMScript("TargetUnit('raid6target');");
		end
	elseif tank == 7 then
		RoMScript("TargetUnit('raid7');");
		if _string == "target" then
			RoMScript("TargetUnit('raid7target');");
		end
	elseif tank == 8 then
		RoMScript("TargetUnit('raid8');");
		if _string == "target" then
			RoMScript("TargetUnit('raid8target');");
		end
	elseif tank == 9 then
		RoMScript("TargetUnit('raid9');");
		if _string == "target" then
			RoMScript("TargetUnit('raid9target');");
		end
	elseif tank == 10 then
		RoMScript("TargetUnit('raid10');");
		if _string == "target" then
			RoMScript("TargetUnit('raid10target');");
		end
	elseif tank == 11 then
		RoMScript("TargetUnit('raid11');");
		if _string == "target" then
			RoMScript("TargetUnit('raid11target');");
		end
	elseif tank == 12 then
		RoMScript("TargetUnit('raid12');");
		if _string == "target" then
			RoMScript("TargetUnit('raid12target');");
		end
	elseif tank == nil then
		RoMScript("TargetUnit('raid1');");
		if _string == "target" then
			RoMScript("TargetUnit('raid1target');");
		end
	end
	return tank
end

Code: Select all

function checkChat()
	time, moreToCome, nameWhisper, messageWhisper = EventMonitorCheck("checkWhisper","4,1",true)
	time, moreToCome, nameParty, messageParty = EventMonitorCheck("checkParty","4,1",true)
	time, moreToCome, nameCh, messageCh = EventMonitorCheck("checkCh","4,1",true)
end
EDIT: Its working now.
Changed/added those;

Code: Select all

function healAll()
	checkHP(1);
	cmdCheck()
	checkHP(2);
	cmdCheck()
	checkHP(3);
	cmdCheck()
	checkHP(4);
	cmdCheck()
	checkHP(5);
	cmdCheck()
	checkHP(9);
	cmdCheck()
end
function cmdCheck()
	checkChat()
	if messageWhisper == "done" and nameWhisper == "a nick" then
				swapCheck = true
	end
	if messageParty == "buff" then
		sendPartyChat('Buffing...')
		player:cast("DRUID_AWAKENING_OF_THE_WILD")
		yrest(100)
		RoMScript("MoveRaidMember(9, 6);");
		yrest(50)
		player:cast("DRUID_AWAKENING_OF_THE_WILD")
		yrest(100)
		RoMScript("MoveRaidMember(6, 9);");
	end
end

User avatar
Bill D Cat
Posts: 555
Joined: Sat Aug 10, 2013 8:13 pm
Location: Deep in the Heart of Texas

Re: Optimisation Problem in Code

#4 Post by Bill D Cat » Sun Oct 23, 2016 11:24 am

One thing I notice in the latest scripts you posted is that one of the conditions you always check is to see if the player's HP > 1 before casting. Wouldn't this be better to either be > 0 or >= 1 since in the rare instance the player had their health reduced to exactly 1 HP your healer would not try to heal them and they would likely die pretty soon afterwards.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 27 guests