Functions in Load are not working. Where is the mistake?

Runes of Magic/Radiant Arcana (http://www.runesofmagic.com)
Message
Author
Danni
Posts: 59
Joined: Sat Nov 09, 2013 6:24 pm

Functions in Load are not working. Where is the mistake?

#1 Post by Danni » Sat Nov 09, 2013 7:38 pm

Hi everyone,

I am working on a kind of complicated script in order not to get caught by Gamemaster or being observed by to many people.
Unfortunately I am always a kind of a noob. So I tried to read all the posts in order to get more knowledge about this stuff.

to understand each function's purpose ... :

function waitForEventStart()
if there is no Event Clock, bot goes to a place, and come back again in order to refresh the Display.
if the event did not start yet it will check until it does
if the event started it will break the waiting and goes to the next command

doquest()
it will repeat doing a specific order of functions until a message in the zone appeared and than change to the next active channel

quest()
it will get 2 quest. the second quest give an Item which will fulfil the first one.
sometimes , because of Lag etc. the items is not immediately in the bag, therefore it will only complete the first quest if it is complete, if not it will cancel the second quest and try it again.
It will do these quest until a specific message is shown in the Zone Chat.

restTilEvent()
it will rest until a specific time and then goes on with the script

channel()
it will change to the next active channel

people()
it will check how many people are around and pause the script if necessary.

GMdetectionname()
it will check every 10 sec. if these gamemaster are nearby, if they are, bot log out immediately ....Since the the Detection userfunction does not really work anymore. Do not know why.

unStick3()
it will check if I got somewhere stuck. after 3 tries of getting free if will check in what zone the char is. If it is not one of the three it will log out. Can I just put this function into the script or do I need to put it into my profile, since I only want this function when I am doing this script?

The bot should only use the first WP and check first which Zone it is in order to know what to do next. The WPs after that are only needed and should only be used if a function calls for them. Meaning the char should only stay at one point.

Here is my script

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<waypoints>
<onload>

YourTargetScore = 6000

function waitForEventStart()
	repeat
	yrest(1000) -- check every second
	local namePE,messagePE,namePH,ScorePE,Count , IsScoreVisible= RoMScript("PE_GetInfo(1)")
		if (ScorePE == nil) then
			printf("Score is nil, oh no!")
			__WPL:setWaypointIndex(__WPL:findWaypointTag("Timer"));
			return
		end
		if Count == 2 and YourTargetScore > ScorePE then break end
		until false
	local namePE,messagePE,namePH,ScorePE,Count , IsScoreVisible= RoMScript("PE_GetInfo(1)")
	if Count ~= 2 or ScorePE >= YourTargetScore then
		__WPL:setWaypointIndex(__WPL:findWaypointTag("Home"));
	end
end

function doquest()  

      	local endmsg = getTEXT("|cffffff75Regional event has ended successfully!|r")

	repeat
        	yrest(10)
         	quest()
		GMdetectionname()
		people()
     	until getLastWarning(endmsg, 10)

	EventMonitorStart("Tug of War Between Two Sides", "WARNING_MESSAGE");
	local time, moreToCome, msg = EventMonitorCheck("Tug of War Between two Sides",1) 
	if msg == endmsg then
      		local currentchannel = RoMScript("GetCurrentParallelID()")
      		local newChannel = currentchannel
      		repeat
         		newChannel = newChannel + 1
         		if newChannel > RoMScript("GetNumParalleZones()") then
            			newChannel = 1
         		end
      		until RoMScript("IsZoneChannelOnLine("..newChannel..")") or newChannel == currentchannel
      			if newChannel ~= currentchannel then
         			sendMacro("ChangeParallelID("..newChannel..");");
         			player:rest(30)
         			local id = RoMScript("GetCurrentParallelID()")
         			if id ~= newChannel then
            				RoMScript("ChangeChar(\"current\",nil,"..newChannel..")")
            				waitForLoadingScreen()
            				yrest(3000)
      			end
	end
end

function doquest3()  
      	local endmsg = getTEXT("|cffffff75Regional event has ended successfully!|r")

	repeat
        	yrest(10)
         	quest()
		GMdetectionname()
		people()
     	until getLastWarning(endmsg, 10)
end

function quest()
       	player:target_NPC("xxxxxx");
	AcceptQuestByName(xxxxx1);
	AcceptQuestByName(xxxxx2);
	repeat
	queststate = getQuestStatus(xxxxxx1);
    		if queststate == "complete" then		
		CompleteQuestByName(xxxxx1);
		else
		CancelQuest(xxxxx2);yrest(500);
		end
	until getLastWarning(endmsg, 10)
end

function restTilEvent()
	repeat
	yrest(700)
	until os.date("*t").min%20 == 10
   	
	yrest(10000)
   	local curtime = os.date("*t")
   	local curmins = curtime.min	
	local cursecs = curtime.sec
   	if curmins > 48 then
      		curmins = curmins - 47
   	elseif curmins > 28 then
      		curmins = curmins - 27
   	elseif curmins > 8 then
     		curmins = curmins - 7
   	else
      		curmins = curmins + 10
   	end
   	local resttime = ((20 - curmins) * 60) - cursecs
   	print("resting for "..resttime.." seconds")
   	yrest(resttime*1000)
end

function channel()
	sendMacro("ChangeParallelID("..newChannel..");");
        player:rest(30)
	local id = RoMScript("GetCurrentParallelID()")
        if id ~= newChannel then
        	RoMScript("ChangeChar(\"current\",nil,"..newChannel..")")
            	waitForLoadingScreen()
            	yrest(3000)
	end
end

function people()
	if CountPlayers() > 3 then
   		print("Waiting till it's less crowded")
   		repeat
      		yrest(15000)
   		until 4 > CountPlayers(nil,true) 
	end
end

function GMdetectionname()

EventMonitorStart("detectGMname", "CHAT_MSG_SYSTEM");
sendMacro("AskPlayerInfo(\'Master\');");yrest(150);

local time, moreToCome, msg = EventMonitorCheck("detectGMname", "1")
if msg ~= nil then
RoMScript("Logout();");
end

EventMonitorStop("detectGMname")

end

registerTimer("GMdetection", secondsToTimer(10), GMdetectionname);function GMdetectionname()
end

function unStick3()
	waitForLoadingScreen();
	if getZoneId() ~= number(a1) then
	RoMScript("Logout();");
		waitForLoadingScreen();
		if getZoneId() ~= number(a2) then
		RoMScript("Logout();");
			waitForLoadingScreen();
			if getZoneId() ~= number(a3) then
			RoMScript("Logout();");
			end
		end
	end
end		

</onload>

<!-- #  1 --><waypoint x="-9414" z="-18353" y="932" tag="Home">
	if getZoneId() == number(a1) then
		waitForEventStart()
    		doquest()
	end
	if getZoneId() == number(a2) then
		doquest()
	end
	if getZoneId() == number(a3) then
		doquest3()
		restTilEvent()
		channel()
	end
	__WPL:setWaypointIndex(__WPL:findWaypointTag("Home));
</waypoint>
<!-- #  2 --><waypoint x="-9397" z="-18357" y="932" tag="Timer">	
	__WPL:setForcedWaypointType("TRAVEL")	
</waypoint>
<!-- #  3 --><waypoint x="-9257" z="-18444" y="904">	</waypoint>
<!-- #  4 --><waypoint x="-9175" z="-18543" y="895">	</waypoint>
<!-- #  5 --><waypoint x="-9065" z="-18758" y="851">	</waypoint>
<!-- #  6 --><waypoint x="-8936" z="-18846" y="863">	</waypoint>
<!-- #  7 --><waypoint x="-8885" z="-18921" y="882">	</waypoint>
<!-- #  8 --><waypoint x="-8885" z="-18920" y="881">	</waypoint>
<!-- #  9 --><waypoint x="-8854" z="-18991" y="905">	</waypoint>
<!-- # 10 --><waypoint x="-8806" z="-19152" y="905">	</waypoint>
<!-- # 11 --><waypoint x="-8592" z="-19389" y="905">	</waypoint>
<!-- # 12 --><waypoint x="-8730" z="-19168" y="907">	</waypoint>
<!-- # 13 --><waypoint x="-8839" z="-19000" y="898">	</waypoint>
<!-- # 14 --><waypoint x="-8960" z="-18804" y="856">	</waypoint>
<!-- # 15 --><waypoint x="-9097" z="-18740" y="851">	</waypoint>
<!-- # 16 --><waypoint x="-9166" z="-18529" y="886">	</waypoint>
<!-- # 17 --><waypoint x="-9269" z="-18424" y="907">	</waypoint>
<!-- # 18 --><waypoint x="-9386" z="-18362" y="931">	</waypoint>
</waypoints>
Unfortunately like I mentioned I am a noob and it does not work. MM give me following message:

Code: Select all

7:28am - ...ktop/micromacro ROM/scripts/rom/classes/waypointlist.lua:83: Failed
to compile and run Lua code for waypointlist onLoad event.
Can someone help me out :) ?

Thank your for your time and sry for any inconvenience.
Last edited by Danni on Mon Nov 18, 2013 8:41 pm, edited 3 times in total.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Functions in Load are not working. Where is the mistake?

#2 Post by rock5 » Sat Nov 09, 2013 10:46 pm

Copy the whole contents of the onload and put it in another file, lets call it 'myfile_onload.lua'. Make sure you pull it in the same folder as the waypoint file. Then change the onload so it looks like this

Code: Select all

<onload>
    include("myfile_onload.lua")
</onload>
Then when you get an error it will give you more information such as what line number it is at.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Danni
Posts: 59
Joined: Sat Nov 09, 2013 6:24 pm

Re: Functions in Load are not working. Where is the mistake?

#3 Post by Danni » Sat Nov 09, 2013 11:24 pm

Thx rock5 for the fast reply.

While I was waiting for some reply I took a try of the R5Hacks.

But now when I try to work on the script again I get following MM message:

Code: Select all

12:14am - scripts\rom/bot.lua:53: ...ong-Lenovo/Desktop/micromacro ROM/scripts/r
om/macros.lua:60: attempt to index global 'settings' (a nil value)
I done the suggestion about a separate lua file.

Now I am not sure why MM doesn't work anymore.....because of R5Hacks, which files I have pasted into the rom/script folder and therefore for example replace the address lua OR because of the new separate lua file inside the waypoint folder

Do I have to delete and redownload the MM?

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Functions in Load are not working. Where is the mistake?

#4 Post by rock5 » Sun Nov 10, 2013 9:25 am

R5Hacks sits in it's own folder and is completely separate to rombot in the 'rom' folder so it shouldn't affect it. The folder structure should look like this;

Code: Select all

micromacro/
           scripts/
                  r5hacks/                 
                  rom/
                     cache/
                     classes/
                     database/
                     etc.
I'm not sure what happened but if you messed up your bot you might have to check it out again. Don't forget to backup any waypoints, profiles and userfunctions you may have added.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Danni
Posts: 59
Joined: Sat Nov 09, 2013 6:24 pm

Re: Functions in Load are not working. Where is the mistake?

#5 Post by Danni » Sun Nov 10, 2013 11:12 am

Thx rock5.

I put R5Hacks in the correct folder and Reloaded rom from SVN. Now MM works again.

After I run the script, it says it misses an "end" at a function. This I have corrected it. BUT now it give m this message on MM:

Code: Select all

 0:5am - scripts\rom/bot.lua:943: Failed to compile and run Lua code for waypoint#2


But on WP 2 i haven't put any functions at all, only that it should regard all following WPs as typ=Travel

Where lies the problem?

Thx u

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Functions in Load are not working. Where is the mistake?

#6 Post by rock5 » Sun Nov 10, 2013 12:16 pm

I think the bot counts the onload so waypoint 2 is actually waypoint 1. Do you have code in waypoint 1?
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Danni
Posts: 59
Joined: Sat Nov 09, 2013 6:24 pm

Re: Functions in Load are not working. Where is the mistake?

#7 Post by Danni » Sun Nov 10, 2013 12:19 pm

Code: Select all

<!-- #  1 --><waypoint x="-9414" z="-18353" y="932" tag="Home">
   if getZoneId() == number(a1) then
      waitForEventStart()
          doquest()
   end
   if getZoneId() == number(a2) then
      doquest()
   end
   if getZoneId() == number(a3) then
      doquest3()
      restTilEvent()
      channel()
   end
   __WPL:setWaypointIndex(__WPL:findWaypointTag("Home));
</waypoint>
<!-- #  2 --><waypoint x="-9397" z="-18357" y="932" tag="Timer">   
   __WPL:setForcedWaypointType("TRAVEL")   
</waypoint>
<!-- #  3 --><waypoint x="-9257" z="-18444" y="904">   </waypoint>
Yes I do. Every function is in WP1.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Functions in Load are not working. Where is the mistake?

#8 Post by rock5 » Sun Nov 10, 2013 12:43 pm

Code: Select all

   __WPL:setWaypointIndex(__WPL:findWaypointTag("Home));
"Home" should have quotes on both sides.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Danni
Posts: 59
Joined: Sat Nov 09, 2013 6:24 pm

Re: Functions in Load are not working. Where is the mistake?

#9 Post by Danni » Sun Nov 10, 2013 1:00 pm

lol ,thx ,true didn't saw that XD

Code: Select all

function GMdetectionname()

EventMonitorStart("detectGMname", "CHAT_MSG_SYSTEM");
sendMacro("AskPlayerInfo(\'Master\);");yrest(150);

local time, moreToCome, msg = EventMonitorCheck("detectGMname", "1")
if msg ~= nil then
RoMScript("Logout();");
end

EventMonitorStop("detectGMname")

end

registerTimer("GMdetection", secondsToTimer(10), GMdetectionname);function GMdetectionname()
end
It realize now the first WP, but when it is checking the function above. I get 2 new problems:
1. I only want to logout if the three Gamemasters are somewhere nearby. NOW as soon it checked all three it will logout immediately. I thought :

Code: Select all

if msg ~= nil then
RoMScript("Logout();");
means it will only logout if MM recieve a valid message, THAT they are nearby NOT the opposite Xp
2. I get this message on MM

Code: Select all

We successfully target NPC Papp Hesof and try to open the dialog window.
Use MACRO: Executing RoMScript "AskPlayerInfo('Nohdrael');".
Use MACRO: Executing RoMScript "AskPlayerInfo('Kiareko');".
Must specify message string when calling 'getLastWarning()'.
Use MACRO: Executing RoMScript "AskPlayerInfo('Lonarhune');".
Must specify message string when calling 'getLastWarning()'.
Must specify message string when calling 'getLastWarning()'.

what does "Must specify message string when calling 'getLastWarning()'." mean?
Last edited by Danni on Tue Nov 19, 2013 3:50 am, edited 1 time in total.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Functions in Load are not working. Where is the mistake?

#10 Post by rock5 » Sun Nov 10, 2013 1:32 pm

1. What you are doing is trying to capture the output from the AskPlayerInfo command. I think that will always output something, whether any are online or not. You could check what the message says. Eg.

Code: Select all

if not string.find(msg, "Search failed") then
But you would have to check each one individually.

2. getLastWarning (and getLastAlert) are special functions that allow you to check the last time certain messages appeared without having to set up an event monitor. For example player:fight will check for a couple of warning messages if it failed to cast. Actually that's the only place the bot uses it. The error message just means it tried to use the command without message argument.

I'm not sure why you get that error message. Were you fighting at the time? Are you sure yo aren't using any code that uses that function?
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Danni
Posts: 59
Joined: Sat Nov 09, 2013 6:24 pm

Re: Functions in Load are not working. Where is the mistake?

#11 Post by Danni » Sun Nov 10, 2013 5:49 pm

Thx u.

I applied the suggestion and I do not get log out,

Code: Select all


function GMdetectionname()

	EventMonitorStart("detectGMname", "CHAT_MSG_SYSTEM");
		sendMacro("AskPlayerInfo(\'Master\');");yrest(250);
		local time, moreToCome, msg = EventMonitorCheck("detectGMname", "1")
		if not string.find(msg, "Search failed") then
		RoMScript("Logout();");
	end
	EventMonitorStop("detectGMname")
	end

	registerTimer("GMdetection", secondsToTimer(10), GMdetectionname);function GMdetectionname()
end
but now I get following message on MM and bot stoped

Code: Select all

Use MACRO: Executing RoMScript "AskPlayerInfo('Masterl');".
The game client did not crash.
6:35am - ...p/micromacro ROM/scripts/rom/waypoints/myfile_onload.lua:128: bad argument #1 to 'find' (string expected, got nil)
Secondly is one time in the end

Code: Select all

EventMonitorStop("detectGMname")
	end

	registerTimer("GMdetection", secondsToTimer(10), GMdetectionname);function GMdetectionname()
end

enough to tell MM to check all three names every 10 sec. or do I need to put this code after each [coloEventMonitorStart("detectGMname", "CHAT_MSG_SYSTEM")r]

About the getLastWarning, I used it in 3 places:

Code: Select all

function doquest()  

      	local endmsg = getTEXT("|cffffff75Regional event has ended successfully!|r")

	repeat
        	yrest(10)
         	quest()
		GMdetectionname()
		people()
     	until getLastWarning(endmsg, 10)

	EventMonitorStart("Tug of War Between Two Sides", "WARNING_MESSAGE");
	local time, moreToCome, msg = EventMonitorCheck("Tug of War Between two Sides",1) 
	if msg == endmsg then
      		local currentchannel = RoMScript("GetCurrentParallelID()")
      		local newChannel = currentchannel
      		repeat
         		newChannel = newChannel + 1
         		if newChannel > RoMScript("GetNumParalleZones()") then
            			newChannel = 1
         		end
      		until RoMScript("IsZoneChannelOnLine("..newChannel..")") or newChannel == currentchannel
      			if newChannel ~= currentchannel then
         			sendMacro("ChangeParallelID("..newChannel..");");
         			player:rest(30)
         			local id = RoMScript("GetCurrentParallelID()")
         			if id ~= newChannel then
            				RoMScript("ChangeChar(\"current\,nil,"..newChannel..")")
            				waitForLoadingScreen()
            				yrest(3000)
         			end
      			end
	end
end

function doquest3()  
      	local endmsg = getTEXT("|cffffff75Regional event has ended successfully!|r")

	repeat
        	yrest(10)
         	quest()
		GMdetectionname()
		people()
     	until getLastWarning(endmsg, 10)
end

function quest()
       	player:target_NPC("Papp Hesof");
	AcceptQuestByName(425597);
	AcceptQuestByName(425598);
	repeat
	queststate = getQuestStatus(425597);
    		if queststate == "complete" then		
		CompleteQuestByName("425597");
		else
		CancelQuest(425598);yrest(500);
		end
	until getLastWarning(endmsg, 10)
end
Depending on which Channel I am, it will start with either the functions doquest() or doquest3() AND than goes to quest().
Inside the functions doquest() or doquest3() I wrote local endmsg = getTEXT("|cffffff80Regional event has ended successfully!|r) so I thought, that I already defined for what kind of message MM should look for.

And I just realize another point:

Code: Select all

function waitForEventStart()
	repeat
	yrest(1000) -- check every second
	local namePE,messagePE,namePH,ScorePE,Count , IsScoreVisible= RoMScript("PE_GetInfo(1)")
		[color=#0000FF]if (ScorePE == nil) then[/color]
			printf("Score is nil, oh no!")
			__WPL:setWaypointIndex(__WPL:findWaypointTag("Timer"));
			return
		end
		if Count == 0 and YourTargetScore > ScorePE then break end
		until false
	local namePE,messagePE,namePH,ScorePE,Count , IsScoreVisible= RoMScript("PE_GetInfo(1)")
	if Count ~= 2 or ScorePE >= YourTargetScore then
		__WPL:setWaypointIndex(__WPL:findWaypointTag("Home"));
	end
end
With this waitForEventStart() function I want the bot to check if there is a Event Clock. If not, it should go on to use the WP from WP2.

Code: Select all

<!-- #  2 --><waypoint x="-9175" z="-18543" y="895" typ="TRAVEL" tag="Timer">	</waypoint>
But now it only print in MM the "Oh no!" part and just talk with the NPC anyway without getting the clock, meaning it just start the script. But I wanted that it wait until the Event really starts.
Last edited by Danni on Tue Nov 19, 2013 3:49 am, edited 1 time in total.

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Functions in Load are not working. Where is the mistake?

#12 Post by rock5 » Mon Nov 11, 2013 12:23 am

Danni wrote:but now I get following message on MM and bot stoped

Code: Select all

Use MACRO: Executing RoMScript "AskPlayerInfo('Nohdrael');".
The game client did not crash.
6:35am - ...p/micromacro ROM/scripts/rom/waypoints/myfile_onload.lua:128: bad argument #1 to 'find' (string expected, got nil)
This means it didn't wait long enough for the output of the AskPlayerInfo command so there were no messages. You should increase the wait, currently you have a 250ms yrest, and add a check for msg having a value eg.

Code: Select all

if msg and not string.find(msg, "Search failed") then
There is a problem with this code. If another chat message appears at just the wrong time then it will pick it up and because it doesn't = "Search failed" it will log off. You should instead do a search for the characters name which appears if they are online or any part of the message you get when they are online. So something like this.

Code: Select all

if msg and string.find(msg, 'Nohdrael') then
Danni wrote:enough to tell MM to check all three names every 10 sec. or do I need to put this code after each EventMonitorStart("detectGMname", "CHAT_MSG_SYSTEM");
You could do only one EventMonitorStart but the longer the time between the EventMonitorStart and checking for messages, the higher the risk of picking up other random chat. It's probably safest to do the EventMonitorStart just before each AskPlayerInfo. But you could probably do one EventMonitorStart if you then check for all messages eg.

Code: Select all

function GMdetectionname()

	EventMonitorStart("detectGMname", "CHAT_MSG_SYSTEM");
	sendMacro("AskPlayerInfo(\'Nohdrael\');"); yrest(750);
	sendMacro("AskPlayerInfo(\'Kiareko\');"); yrest(750);
	sendMacro("AskPlayerInfo(\'Lonarhune\');"); yrest(750);
	
	repeat
		local time, moreToCome, msg = EventMonitorCheck("detectGMname", "1")
		if msg and string.find(msg, ".*%(.*%).*%(.*%).*%(.*%).*%(.*%)") then
			RoMScript("Logout();");
			break
		end
	until moreToCome == false

	EventMonitorStop("detectGMname")
end

registerTimer("GMdetection", secondsToTimer(10), GMdetectionname);function GMdetectionname()
I discovered that if you do AskPlayerInfos too quickly after one another then only the first one works. I had to use a 750ms pause to make it work. You might have to adjust it for your system. That means this function takes over 2 seconds. Registered timers should usually be very fast. I'm not 100% sure but I think the yrests will yield back to the main program so it should be ok. It's not as if it stops doing the rest of the code for 2s. To be sure just try it and see. You should also change the name of the event "GMdection" or it might conflict with the gmmonitor userfunction.
Danni wrote:About the getLastWarning, I used it in 3 places:
The last time you use it you don't specify endmsg, that's why you get the error. Either specify it again or make it a global variable. It's wrong anyway. You are not using getTEXT properly. getTEXT is for getting the local language version of a string using a code word or text, eg. getTEXT("SC_ZONE_PE_3TH_ST1OVER") will return "Regional event has ended successfully!" on an English client. I don't think the color is part of the message. I think all warnings are orange/red and all alerts are yellow. I see from the color code that you are expecting a yellow message. It's probably an alert then, so you should be using getLastAlert.
Danni wrote:But now it only print in MM the "Oh no!" part and just talk with the NPC anyway without getting the clock, meaning it just start the script. But I wanted that it wait until the Event really starts.
The function looks ok. The problem is probably where you use the function. You have to understand that when you set the waypoint index it doesn't stop the current code, it just sets the next waypoint you will be going to when you do finish the current code. So if you have in a waypoint

Code: Select all

<waypoint .....>
    waitForEventStart()
    do some other stuff
</waypoint>
It will still "do some other stuff" even if the next waypoint have changed. There are probably a number of ways to fix this. Probably the easiest is to put waitForEventStart() in a waypoint by itself or make sure it's the last thing in the waypoint.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Danni
Posts: 59
Joined: Sat Nov 09, 2013 6:24 pm

Re: Functions in Load are not working. Where is the mistake?

#13 Post by Danni » Mon Nov 11, 2013 1:21 pm

I replace the getLastWarning into getLastAlert as well change the last function, so I do not get the MM Warning any more. Thank you. But now I am curios? How do I make the endmsg into a global variable? :ugeek:

I also took the function GMdetectionname() above. Thx you for the help and changed the name as well the yrest into 800. but I am wondering:

What does ".*%(.*%).*%(.*%).*%(.*%).*%(.*%)" in
local time, moreToCome, msg = EventMonitorCheck("detectGMname", "1")
if msg and string.find(msg, ".*%(.*%).*%(.*%).*%(.*%).*%(.*%)") then
RoMScript("Logout();");
break
end
excaltly do? :ugeek:

Another problem I found, but I don't know WHY it does that now, that sometimes after it take the first quest and the second quest, which fulfil the first quest, it somehow is not able to complete the quest, although the char did open the dialogue with the corresponding NPC. :?:

Code: Select all

function quest()
       	player:target_NPC(NpcID);
	AcceptQuestByName(numberQ1);yrest(500);
	AcceptQuestByName(numberQ2);yrest(1300);
	queststate = getQuestStatus(numberQ1);
    		if queststate == "complete" then
		player:target_NPC(NpcID);yrest(500);
		CompleteQuestByName(numberQ1);yrest(500);
		else
		CancelQuest(numberQ2);yrest(500);
		end
end
A new problem arise again, which is that I want after the char reach WP2 it will check, which Channel (Zone) it is and than do the doquest() function until theLastAlert, AFTER that it should only once check if the Gamemaster are nearby by using the Detectionname() than if they are not nearby , the char should change the Zone (Channel) and do it all over again.

The WP I am using would be now like this:

Code: Select all

<!-- #  1 --><waypoint x="-9276" z="-18431" y="907" tag="Home">
		waitForEventStart()
</waypoint>
<!-- #  2 --><waypoint x="-9414" z="-18353" y="932">
	yrest(2000)
	if getZoneId() == number(a1) then
		doquest()
		Detectionname()
	end
	if getZoneId() == number(a1) then
		doquest()
		Detectionname()
	end
	if getZoneId() == number(a1) then
		doquest()
		Detectionname3()
	end
	__WPL:setWaypointIndex(__WPL:findWaypointTag("Home"));
And the Function for the Detections are:

Code: Select all

function DetectionnameAll()

   	EventMonitorStart("detectMaster", "CHAT_MSG_SYSTEM");
   		sendMacro("AskPlayerInfo(\'Nohdrael\');"); yrest(800);
   		sendMacro("AskPlayerInfo(\'Kiareko\');"); yrest(800);
   		sendMacro("AskPlayerInfo(\'Lonarhune\');"); yrest(800);
   
   		repeat
      			local time, moreToCome, msg = EventMonitorCheck("detectMaster", "1")
      			if msg and string.find(msg, ".*%(.*%).*%(.*%).*%(.*%).*%(.*%)") then
         			RoMScript("Logout();");
         			break
			elseif msg and not string.find(msg, ".*%(.*%).*%(.*%).*%(.*%).*%(.*%)") then
         			channelAll()
         			break
      			end
   		until moreToCome == false

   	EventMonitorStop("detectMaster")
	end

	registerTimer("Detection", secondsToTimer(10), Detectionname);function Detectionname()
end

function Detectionname3()

   	EventMonitorStart("detectMaster", "CHAT_MSG_SYSTEM");
   		sendMacro("AskPlayerInfo(\'Nohdrael\');"); yrest(800);
   		sendMacro("AskPlayerInfo(\'Kiareko\');"); yrest(800);
   		sendMacro("AskPlayerInfo(\'Lonarhune\');"); yrest(800);
   
   		repeat
      			local time, moreToCome, msg = EventMonitorCheck("detectMaster", "1")
      			if msg and string.find(msg, ".*%(.*%).*%(.*%).*%(.*%).*%(.*%)") then
         			RoMScript("Logout();");
         			break
			elseif msg and not string.find(msg, ".*%(.*%).*%(.*%).*%(.*%).*%(.*%)") then
         			restTilEvent()
				channel()
         			break
      			end
   		until moreToCome == false

   	EventMonitorStop("detectMaster")
	end

	registerTimer("Detection", secondsToTimer(10), Detectionname3);function Detectionname3()
end
But now MM give this message:
2:0am - [string "..."]:2: ...p/micromacro ROM/scripts/rom/waypoints/myfile_onload.lua:137: Error: Non-function type passed to registerTimer() where a function is expected.
What do I have to change at the register Timer? :?:

User avatar
BlubBlab
Posts: 948
Joined: Fri Nov 30, 2012 11:33 pm
Location: My little Pony cafe

Re: Functions in Load are not working. Where is the mistake?

#14 Post by BlubBlab » Mon Nov 11, 2013 8:26 pm

The function must be pre registerTimer, your function is past the call so you register nil.
Remember this is a script language.
Jack-of-all-trades, but master-of-only of a few :D

My Reps:
https://github.com/BlubBlab/Micromacro-with-OpenCV (My version of MM2 with OpenCV and for MS Visual Studio)
https://github.com/BlubBlab/rom-bot (rombot with no stop WP and advanced human emulation mode and some other extensions)
https://github.com/BlubBlab/Micromacro-2-Bot-Framework ( A work in progress )
My Tools : viewtopic.php?f=10&t=6226

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Functions in Load are not working. Where is the mistake?

#15 Post by rock5 » Tue Nov 12, 2013 7:24 am

Danni wrote:What does ".*%(.*%).*%(.*%).*%(.*%).*%(.*%)" exactly do?
It's a pattern. I can't go into it too much because it's a huge subject. It took me ages to figure out patterns. Basically .* means anything. %( and %) mean brackets. The % is needed to tell the pattern that you mean brackets literately because brackets have special meaning in patterns. So the pattern matches anything (anything) anything (anything) anything (anything) anything (anything). Does that look familiar? :)
Danni wrote:Another problem I found, but I don't know WHY it does that now, that sometimes after it take the first quest and the second quest, which fulfil the first quest, it somehow is not able to complete the quest, although the char did open the dialogue with the corresponding NPC. :?:
I'm not sure I understand. Do you have to complete the second quest to complete the first one? Because you don't complete the second one.
Danni wrote: end

registerTimer("Detection", secondsToTimer(10), Detectionname3);function Detectionname3()
end
I think your problem is you are registering the function inside itself. The register has to be out side the function. Actually I don't even think you need to register the function. You only register the function if you want it checked continuously but it looks like you only want to run it at certain times. So you only need the function itself.

Code: Select all

         repeat
               local time, moreToCome, msg = EventMonitorCheck("detectMaster", "1")
               if msg and string.find(msg, ".*%(.*%).*%(.*%).*%(.*%).*%(.*%)") then
                  RoMScript("Logout();");
                  break
         elseif msg and not string.find(msg, ".*%(.*%).*%(.*%).*%(.*%).*%(.*%)") then
                  channelAll()
                  break
               end
         until moreToCome == false
This looks wrong. This checks the messages one at a time. So you want to check all of them for gms before doing channelAll(). You might have to use a variable. Eg. before the repeat add

Code: Select all

local found = false
If it finds a gm do

Code: Select all

found=true
Then after the repeat loop ends you can do

Code: Select all

if not found then
    channelAll()
end
That might work.
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Danni
Posts: 59
Joined: Sat Nov 09, 2013 6:24 pm

Re: Functions in Load are not working. Where is the mistake?

#16 Post by Danni » Tue Nov 12, 2013 4:15 pm

Thx Blublab for your reply, now I learned something new.
Thank you rock5 for the explaination and your help, it seems that this function is working now.
Danni wrote:
Another problem I found, but I don't know WHY it does that now, that sometimes after it take the first quest and the second quest, which fulfil the first quest, it somehow is not able to complete the quest, although the char did open the dialogue with the corresponding NPC. :?:

I'm not sure I understand. Do you have to complete the second quest to complete the first one? Because you don't complete the second one.
As for that problem, .… the problem have been solved.

But I just realize an old problem has not been solve yet. I want that MM will do some kind of quests UNTIL it says in the Zone "Regional event has ended." OR "Regional event has ended succesfully!" and for that purpose I am using these functions:

Code: Select all

function doquest()  

      	local endmsg = getTEXT("SC_ZONE_PE_3TH_ST1OVER")

	repeat
        	yrest(10)
         	quest()
		people()
     	until getLastAlert(endmsg, 3)
end

function quest()
       	player:merchant();
	AcceptQuestByName(XXXXXX);
	CompleteQuestByName(XXXXX);
end

function people()
	if CountPlayers() > 3 then
   		print("Waiting till it's less crowded")
   		repeat
      		yrest(15000)
   		until 4 > CountPlayers(nil,true) 
	end
end
BUT now it is just keep on doing the quest() function, although the Alert has already been displayed in the Zone Chat. It seems like the "until" does not work....why?

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Functions in Load are not working. Where is the mistake?

#17 Post by rock5 » Wed Nov 13, 2013 2:33 am

The alerts and warnings are what appear in the middle of the screen, not in chat. Are those messages appearing on he screen?

Also getLastAlert(endmsg, 3) only returns the alert message if it appeared in the last 3 seconds. If people() delayed the loop then it might miss the message. The function returns the time of the last message so if you leave off the 3 you can check the time to see if it's a new message eg.

Code: Select all

function doquest() 

         local endmsg = getTEXT("SC_ZONE_PE_3TH_ST1OVER")
         local msgtime = getLastAlert(endmsg) or 0
   repeat
            yrest(10)
            quest()
            people()
            local newtime = getLastAlert(endmsg) or 0
    until newtime  > msgtime
end
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Danni
Posts: 59
Joined: Sat Nov 09, 2013 6:24 pm

Re: Functions in Load are not working. Where is the mistake?

#18 Post by Danni » Sat Nov 16, 2013 8:28 pm

Sry for the late, reply, was busy these few days. Thx Rock5 for the input

Yes those "alerts & warning" do show up in the middle of the screen, as well like when you accepting/completing/deleting quests. and these warning are as well in the chat :)

Unfortunately the problem, that the bot keeps on doing the quest, meaning ignoring the "End of the Event & switching the channel" still exsist ... :?:

I am using this code now:

Code: Select all

function doquest() 
       	local endmsg = getTEXT("SC_ZONE_PE_3TH_ST1OVER")
       	local msgtime = getLastAlert(endmsg) or 0
   	repeat
          	yrest(10)
            	player:merchant(NPC-ID);
		AcceptQuestByName(Quest1);
		AcceptQuestByName(Quest2);yrest(600);
		CompleteQuestByName(Quest1);
		CancelQuest(Quest2)
            	local newtime = getLastAlert(endmsg) or 0
    	until newtime  > msgtime
which is triggerd by

Code: Select all

<!-- #  2 --><waypoint x="-9364" z="-18330" y="928">
	yrest(2000)
	if getZoneId() == ZONE-ID then
		doquest()
		people()
		Detectionname()
Since it was a concern that the people() function will interfere with the doquest() function, I now keep it out of the original loop and it should only be done after doquest() is finish.

But somehow doquest() does not realize the Ending....Why? What can I change?

Regards
Danni

User avatar
rock5
Posts: 12173
Joined: Tue Jan 05, 2010 3:30 am
Location: Australia

Re: Functions in Load are not working. Where is the mistake?

#19 Post by rock5 » Sat Nov 16, 2013 11:29 pm

It looks ok to me. Are you sure it's not working and that it's not just looping back and doing that waypoint again? Maybe you could add a print messages to help figure out what's happening.

Code: Select all

function doquest()
          local endmsg = getTEXT("SC_ZONE_PE_3TH_ST1OVER")
		  print("endmsg is ".. endmsg)
          local msgtime = getLastAlert(endmsg) or 0
		  print("msgtime is "..msgtime)
      repeat
             yrest(10)
               player:merchant(NPC-ID);
      AcceptQuestByName(Quest1);
      AcceptQuestByName(Quest2);yrest(600);
      CompleteQuestByName(Quest1);
      CancelQuest(Quest2)
               local newtime = getLastAlert(endmsg) or 0
			   print("newtime = "..newtime)
       until newtime  > msgtime
	   print("endmsg detected")
  • Please consider making a small donation to me to support my continued contributions to the bot and this forum. Thank you. Donate
  • I check all posts before reading PMs. So if you want a fast reply, don't PM me but post a topic instead. PM me for private or personal topics only.
  • How to: copy and paste in micromacro
    ________________________
    Quote:
    • “They say hard work never hurt anybody, but I figure, why take the chance.”
          • Ronald Reagan

Danni
Posts: 59
Joined: Sat Nov 09, 2013 6:24 pm

Re: Functions in Load are not working. Where is the mistake?

#20 Post by Danni » Sun Nov 17, 2013 1:18 am

Code: Select all

Forced waypoint type 'TRAVEL' set by user.
Moving to waypoint #2, (-9396, -18342)
endmsg is Regional event has ended successfully!
msgtime is 0
We try to find NPC (NPC-ID):
We successfully target NPC (NPC-Name) and try to open the dialog window.
Quest accepted: Quest1
Quest accepted: Quest2
Quest completed: Quest1
newtime = 0
We try to find NPC (NPC-ID):
We successfully target NPC (NPC-Name) and try to open the dialog window.
Quest accepted: Quest1
Quest accepted: Quest2
Quest completed: Quest1
newtime = 0
We try to find NPC (NPC-ID):
We successfully target NPC (NPC-Name) and try to open the dialog window.
Quest accepted: Quest1
Quest accepted: Quest2
Quest completed: Quest1
newtime = 0
We try to find NPC (NPC-ID):
We successfully target NPC (NPC-Name) and try to open the dialog window.
Quest accepted: Quest1
Quest accepted: Quest2
Quest completed: Quest1
newtime = 0
We try to find NPC (NPC-ID):
We successfully target NPC (NPC-Name) and try to open the dialog window.
Quest accepted: Quest1
Quest accepted: Quest2
Quest completed: Quest1
newtime = 0
We try to find NPC (NPC-ID):
We successfully target NPC (NPC-Name) and try to open the dialog window.
Quest accepted: Quest1
Quest accepted: Quest2
Quest completed: Quest1
newtime = 0
We try to find NPC (NPC-ID):
We successfully target NPC (NPC-Name) and try to open the dialog window.
Quest accepted: Quest1
Quest accepted: Quest2
Quest completed: Quest1
newtime = 0
We try to find NPC (NPC-ID):
We successfully target NPC (NPC-Name) and try to open the dialog window.
Quest accepted: Quest1
Quest accepted: Quest2
Quest completed: Quest1
newtime = 0
We try to find NPC (NPC-ID):
We successfully target NPC (NPC-Name) and try to open the dialog window.
Quest accepted: Quest1
Quest accepted: Quest2
Quest completed: Quest1
newtime = 0
At the last 3 repeats the event was already finished. I guess at newtime it should tell how much time is left, ZERO means that it is done? Since it is always ZERO I guess something does not work ? :?:

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests