Page 1 of 2
Monitor chat ... if event XYZ, then load WP/file
Posted: Fri Nov 04, 2011 11:02 pm
by Edamh
Is it possible to monitor chat and if event XYZ is being broadcast, then run/load a specific WP file or specific WP within a file?
For example, I may want to bot outside OS. Then if the notice about the harpies outside OS shows up on chat, I would want the bot to load a specific WP that includes that area with the harpies. After the event (the end also being noted by another msg in chat), I would want the bot to go back to the original route outside OS.
Is possible to monitor chat and load WP accordingly? If so, any pointers or tips on how to do so? Thanks.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Sat Nov 05, 2011 12:48 am
by lisa
Yup, mind you if you load a WP while you are far away from any of the new WP coords it will try to run up cliffs to get to the nearest coords of the WP. If you make the new WP cover the entire map then it would be fine.
You will need to start a monitor event.
I'll use GM detect as an example.
So you can call this function from an onload Wp or profile
startGMDetect()
Code: Select all
function startGMDetect()
if settings.profile.options.GMDETECT == true then
unregisterTimer("GMdetection");
printf("GM detection started\n");
EventMonitorStart("GMdetect", "CHAT_MSG_SYSTEM");
registerTimer("GMdetection", secondsToTimer(5), GMdetection);
end
end
I changed it to be CHAT_MSG_SYSTEM as you want to monitor system messages.
So this will make it do the function GMdetection() every 5 seconds.
in the GMdetection() you will need code to check for the text you want.
Code: Select all
repeat
local time, moreToCome, name, msg = EventMonitorCheck("GMdetect", "4,1")
What you will be after is what msg means.
do a check for msg
you want to then check to see if msg is anything like what you want, can do a string.find for that.
Obviously change the **** for what ever it is you are looking for in the message.
then just tell bot what you want to do
Add it together and looks like this
Code: Select all
repeat
local time, moreToCome, name, msg = EventMonitorCheck("GMdetect", "4,1")
if msg ~= nil then
if string.find(msg,"****") then
loadPaths("**")
end
end
until moreToCome == false
So remember this used names from the gmdetect as an example, so you should change names to what you want. It should be enough to get you started atleast.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Sat Nov 05, 2011 7:25 am
by Edamh
Thanks much. Will give it a try later today.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Sat Nov 05, 2011 9:53 am
by Edamh
So I loaded the following in the <onLoad> section of my waypoint file but the bot never started even though the system message showed up in chat. Thoughts?
Code: Select all
function startEVENTDetect()
if settings.profile.options.GMDETECT == true then
unregisterTimer("EVENTdetection");
printf("EVENT detection started\n");
EventMonitorStart("EVENTdetect", "CHAT_MSG_SYSTEM");
registerTimer("EVENTdetection", secondsToTimer(5), EVENTdetection);
end
end
repeat
local time, moreToCome, name, msg = EventMonitorCheck("EVENTdetect", "4,1")
if msg ~= nil then
if string.find(msg,"<START TEXT HERE>") then
__WPL:setWaypointIndex(__WPL:findWaypointTag("START"));
end
if string.find(msg,"<END TEXT HERE>") then
__WPL:setWaypointIndex(__WPL:findWaypointTag("GOTOSLEEP"));
end
end
until moreToCome == false
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Sat Nov 05, 2011 9:29 pm
by lisa
Code: Select all
registerTimer("EVENTdetection", secondsToTimer(5), EVENTdetection);
This part makes it call a function with the name that is the 3rd argument, in this case EVENTdetection, the one without the ""
So if you do it all purely in onload of a WP then do it like this.
Code: Select all
function EVENTdetection()
repeat
local time, moreToCome, name, msg = EventMonitorCheck("EVENTdetect", "4,1")
if msg ~= nil then
if string.find(msg,"<START TEXT HERE>") then
__WPL:setWaypointIndex(__WPL:findWaypointTag("START"));
end
if string.find(msg,"<END TEXT HERE>") then
__WPL:setWaypointIndex(__WPL:findWaypointTag("GOTOSLEEP"));
end
end
until moreToCome == false
end
function startEVENTDetect()
unregisterTimer("EVENTdetection");
printf("EVENT detection started\n");
EventMonitorStart("EVENTdetect", "CHAT_MSG_SYSTEM");
registerTimer("EVENTdetection", secondsToTimer(5), EVENTdetection);
end
startEVENTDetect()
Don't forget the startEVENTDetect() as you still need to call the function at some stage.
This won't get you stuck in a loop though, so it will still go to the nearest set of coords when you start the WP.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Thu Jan 12, 2012 4:05 pm
by gloover
Hey lisa, hi rock.
How can I realize this:
toon1 stay at the position (e.a waypoint1) until sended message (from toon2) in group chat ("come" or somesing else) was detected and how to send a message into a group-chat-frame?
thx in advance!
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Mon Sep 17, 2012 12:57 pm
by grande
Lisa, okay... so I was mincing between your "LOL" eventmonitortest and an attempt to --make it work-- with monitoring system chat and then I stumbled on this post.
This works fine but I want to try something else, further down
Code: Select all
<!-- # 1 --><waypoint x="-18556" z="-18129" y="999"> EventMonitorStart("Test", "CHAT_MSG_SAY");
sendMacro("SendChatMessage('LOL','SAY');")
yrest(1000)
local time, moreToCome, msg = EventMonitorCheck("Test", "1") if string.find(msg, "LOL") then printf("Event monitoring works fine.\n")
player:sleep()
end
</waypoint>
</waypoints>
The code below gives a string error. Studied a bit and learned string.find is looking for the text. Unfortunately it doesn't seem like the system chat gets logged the same OR (more likely) I'm assigning the event monitor incorrectly. I read about EventMonitorCheck saving to a log... is this a real-time log or is it saved somewhere I can view?
Code: Select all
<!-- # 1 --><waypoint x="-18556" z="-18129" y="999"> EventMonitorStart("Test", "CHAT_MSG_SYSTEM");
sendMacro("SendSystemChat(PE_GetPOBInfo( 1 , 0 ),'SYSTEM');")
yrest(1000)
local time, moreToCome, msg = EventMonitorCheck("Test", "1")
if string.find(msg, "Time remaining") then
printf("Event monitoring works fine.\n")
player:sleep()
end
</waypoint>
</waypoints>
Another swing and a miss as I tried to make the code look more like yours LOL
Code: Select all
<!-- # 1 --><waypoint x="-18556" z="-18129" y="999"> EventMonitorStart("Test", "CHAT_MSG_SYSTEM");
sendMacro("SendSystemChat(PE_GetPOBInfo( 1 , 0 ),'SYSTEM');")
yrest(1000)
local time, moreToCome, msg = EventMonitorCheck("Test", "1") if string.find(msg, "PE_GetPOBInfo( 1 , 0 )") then printf("Event monitoring works fine.\n")
player:sleep()
end
</waypoint>
</waypoints>
So now, after reading this thread it looks like my solution is this?
Code: Select all
</onLoad>
function EVENTdetection()
repeat
local time, moreToCome, name, msg = EventMonitorCheck("EVENTdetect", "4,1")
if msg ~= nil then
if string.find(msg,"Positive Effect") then
__WPL:setWaypointIndex(__WPL:findWaypointTag("START"));
end
if string.find(msg,"Time remaining") then
__WPL:setWaypointIndex(__WPL:findWaypointTag("GOTOSLEEP"));
end
end
until moreToCome == false
end
function startEVENTDetect()
unregisterTimer("EVENTdetection");
printf("EVENT detection started\n");
EventMonitorStart("EVENTdetect", "CHAT_MSG_SYSTEM");
registerTimer("EVENTdetection", secondsToTimer(5), EVENTdetection);
end
startEVENTDetect()
</onLoad>
And then at a WP
Code: Select all
<!-- # 1 --><waypoint x="-18556" z="-18129" y="999">
sendMacro("SendSystemChat(PE_GetPOBInfo( 1 , 0 ),'SYSTEM');")
yrest(100)
EVENTdetection()
</waypoint>
</waypoints>
So I changed the system message to look for above to "Positive Effect" and "Time remaining" based on what I know "sendMacro("SendSystemChat(PE_GetPOBInfo( 1 , 0 ),'SYSTEM');")" will return in the system chat window.
Once startEVENTDetect() is initiated in the /onLoad section do I need to call it again at a specific WP or does it just run continually as long as the WP is running?
Thx again and again
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Mon Sep 17, 2012 1:17 pm
by rock5
Why do you want to do this? Why print the values returned from the function and then monitor the chat, when you can just return the values from the function?
Code: Select all
local namePOB , itype , ikind , nowvalue, doolsill = RoMScript("PE_GetPOBInfo( 1 , 0 )")
I'm not sure what the returned values are but I copied those variable names from the publicencounterframe.lua file.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Mon Sep 17, 2012 1:24 pm
by grande
The "PE_GetPOBInfo( 1 , 0 )" gives different outputs such as "Positive Effect" and "Time remaining". I want it to do different WP based on that text. I don't know how to make "local namePOB , itype , ikind , nowvalue, doolsill = RoMScript("PE_GetPOBInfo( 1 , 0 )")" do that.
However, the event monitor test seemed like a way. If it would print something then surely it would load a waypoint.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Mon Sep 17, 2012 2:44 pm
by rock5
Its simple really. PE_GetPOBInfo( 1 , 0 ) is an ingame function that returns 5 values. When you use
Code: Select all
/script SendSystemChat(PE_GetPOBInfo( 1 , 0 ))
you are telling it to print the values the function returns but because SendSystemChat can't print multiple values it only prints the first. If you wanted to you could do this
Code: Select all
/script aa,bb,cc,dd,ee = PE_GetPOBInfo( 1 , 0 )
and then print each of those 5 values.
Now in the bot, if you use
Code: Select all
msg = RoMScript("PE_GetPOBInfo( 1 , 0 )")
because there is only one variable it will only capture the first value which is the one you've been playing with. But if you want to look at all the values that function returns you could do
Code: Select all
aa,bb,cc,dd,ee = RoMScript("PE_GetPOBInfo( 1 , 0 )")
RoMScript can return any values, variables or function outputs just like they do in game.
Hope that helps.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Mon Sep 17, 2012 10:06 pm
by grande
Ahhh.... edit here.. lol. Think I got it. So "namePOB" was the key I couldn't seem to grasp. right there in front of my face. grrrr
Code: Select all
<!-- # 1 --><waypoint x="1" z="9" y="8">
EventMonitorStart("Test", "CHAT_MSG_SYSTEM");
sendMacro("SendSystemChat(PE_GetPOBInfo( 1 , 0 ));")
yrest(1000)
local namePOB = RoMScript("PE_GetPOBInfo( 1 , 0 )")
if string.find(namePOB, "Positive Effect") then
printf("Positive Effect!!!!.\n")
else
if string.find(namePOB, "Time remaining") then
printf("Time remaining!!!!.\n")
end
end
</waypoint>
omgosh i must need sleep or more than 24 hours in a day. don't know how you guys get it. I blame my lack of attention to detail as diminished by lack of sleep. menal acuity shot need zzzzzzZZZZzzzZZZzz
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Tue Sep 18, 2012 12:41 am
by lisa
I think the point you seem to be missing is you don't need to monitor chat or print it.
try this.
Code: Select all
<!-- # 1 --><waypoint x="1" z="9" y="8">
local namePOB = RoMScript("PE_GetPOBInfo( 1 , 0 )")
if string.find(namePOB, "Positive Effect") then
printf("Positive Effect!!!!.\n")
elseif string.find(namePOB, "Time remaining") then
printf("Time remaining!!!!.\n")
else print("value returned is "..namePOB)
end
</waypoint>
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Tue Sep 18, 2012 6:53 am
by grande
Thanks so much again. For this part:
Code: Select all
else print("value returned is "..namePOB)
seems it returns w/e else the current status of namePOB is but why are the ".." in front of namePOB needed?
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Tue Sep 18, 2012 7:25 am
by BillDoorNZ
the .. concatenates the two strings together
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Tue Sep 18, 2012 7:48 am
by lisa
grande wrote:but why are the ".." in front of namePOB needed?
Ok a string is any text inside " "
So "lollies" is a string
a variable is something that has a value, defined or not.
lollies = "fruit"
As an example if you have this
Code: Select all
lollies = "Fruit"
print("Lollies "..lollies)
it will print
You need the .. to tell MM that the next thing is a variable and you want it used with the string. I can't think of a better way to explain it.
So as extra info
print("Lollies "..lollies.." are yummy")
will print
Lollies Fruit are yummy
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Tue Sep 18, 2012 1:24 pm
by grande
Ahh yes, excellent thx again and again and again Lisa. your description makes it crystal clear.
So the ".." pulls out whatever may be the current result/status of the namePOB equation.
Like Bill said, concatenates the string component namePOB to whatever the current status is.
If it's blank, as in on a bugged channel would it just fail and stop the MM or would it just print nil? I can mess with it later.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Fri Nov 16, 2012 10:47 am
by Edamh
I am trying to monitor party chat, and I am trying to use the code above. Here's what I have:
Code: Select all
function EVENTdetection()
repeat
cprintf(cli.yellow,"Inside EVENTdetection function; inside repeat ... until \n");
local time, moreToCome, name, msg = EventMonitorCheck("EVENTdetect", "4,1")
if msg ~= nil then
if string.find(msg,"msg1") then
cprintf(cli.lightblue,"msg1 received in PARTY chat. \n");
__WPL:setWaypointIndex(__WPL:findWaypointTag("START"));
end
if string.find(msg,"msg2") then
cprintf(cli.lightblue,"msg2 received in PARTY chat. \n");
__WPL:setWaypointIndex(__WPL:findWaypointTag("SLEEP"));
end
end
until moreToCome == false
end
function startEVENTDetect()
unregisterTimer("EVENTdetection");
printf("EVENT detection started\n");
EventMonitorStart("EVENTdetect", "CHAT_MSG_PARTY");
registerTimer("EVENTdetection", secondsToTimer(10), EVENTdetection);
end
I can trigger the print line to show that msg1 or msg2 are received. However, the code loops infinitely displaying my yellow screen prints, and doesn't escape the
repeat ... until in function
EVENTdetection
What am I missing? How do I escape the
repeat ... until and actually go to the specified waypoints? Thanks.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Fri Nov 16, 2012 7:02 pm
by lisa
The code itself looks fine, only thing I can come up with is the timer is set to 10 seconds, so if you type in party chat a few times before it actually calls the function then it will print in MM for each time.
Try setting it to 1 second calls and see if it helps.
Code: Select all
registerTimer("EVENTdetection", secondsToTimer(1), EVENTdetection);
As a side note I added some functions to party.lua to make it easier to monitor party chat.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Fri Nov 16, 2012 9:18 pm
by Edamh
lisa wrote:The code itself looks fine, only thing I can come up with is the timer is set to 10 seconds, so if you type in party chat a few times before it actually calls the function then it will print in MM for each time.
Try setting it to 1 second calls and see if it helps.
Code: Select all
registerTimer("EVENTdetection", secondsToTimer(1), EVENTdetection);
As a side note I added some functions to party.lua to make it easier to monitor party chat.
I tried changing the 10 seconds to 1, but it still doesn't escape the
repeat...until. Here's what shows up in the MM window:
The bot just stands there, then.
Re: Monitor chat ... if event XYZ, then load WP/file
Posted: Fri Nov 16, 2012 11:27 pm
by rock5
Just because it keeps printing that message doesn't necessarily mean it's stuck in that loop. It might be stuck somewhere else and the timed event is doing it's thing every second. Where did you start monitoring the event? How did you start it? If you comment out the line that starts the monitor does it still get stuck?