On the onchat event is there a way to search for a non-player issued message; such as a response for a new player joining.
Here is my coding that I have so far.
IFMATCHES(%CHAT%,"A new recruit,");
WAIT(1);
ECHO(/h Welcome!);
WAIT(5);
ECHO(/h Escape from the dungeon!);
WAIT(5);
ECHO(/h Please use /greylist to complete your registration process.);
ENDIF;
On the onchat event is there a way to search for a non-player issued message; such as a response for a new player joining.
Here is my coding that I have so far.
IFMATCHES(%CHAT%,"A new recruit,");
WAIT(1);
ECHO(/h Welcome!);
WAIT(5);
ECHO(/h Escape from the dungeon!);
WAIT(5);
ECHO(/h Please use /greylist to complete your registration process.);
ENDIF;
So, essentially, you want to make a macro that detects when a new player joins the game, and then say the above?
To do this efficiently, you will probably need to use a regex to match against the chat string. To get the correct string, I need you to do this:
First, I need you to put this in your onChat:
set(@&lastchat,%CHAT%);
Then, I need you to bind this to a key (doesn't matter which):
echo("%@&lastchat%")
Then, in your options, enable "Store sent messages in local history".
Now, the next time a new player joins your server, I need you to activate that macro up there. You will need to do it immediately after they join, or else you will not get the correct message.
After that, you will need to open the chat bar and press up. Copy all of that text (by holding shift and pressing the arrow keys) and pm it to me. I will then be able to make you a quick regex to detect a new player. I can also get you their name if you want.
The problem with what you have now is that if someone says "A new recruit," in the chat, it will trigger, and you probably don't want that.
Ok, I tried that but all it did was say %JOINEDPLAYER%. I also tried "$${ECHO(%JOINEDPLAYER%)}$$" But it said "?7Steve?f."
How can I configure it to use "&" instead of "?"? Or, is there another way that I should be doing it?
Also, can I use the joinedplayer variable outside of a script like that?
Lastly, It seemed to be working as expected, but then i noticed that when i would join, it would fire the event for every player currently online as if they had just joined.
Edit: I am trying to figure the language out slowly but surely. What language is this? Java?
Sorry If I am asking silly, simple questions. If you could, please point me to somewhere I could learn this.
I am actually trying to do something like this aswell:
On the onchat event is there a way to search for a non-player issued message; such as a response for a new player joining.
Here is my coding that I have so far.
IFMATCHES(%CHAT%,"A new recruit,");
WAIT(1);
ECHO(/h Welcome!);
WAIT(5);
ECHO(/h Escape from the dungeon!);
WAIT(5);
ECHO(/h Please use /greylist to complete your registration process.);
ENDIF;
Is there any way to use the onChat event to answer questions that have the keywords I can define? Also, not have it detect my message so it doesn't cause an endless loop. And if you can, add some kind of spam control so if it DOES go crazy it will stop itself.
Ok, I tried that but all it did was say %JOINEDPLAYER%. I also tried "$${ECHO(%JOINEDPLAYER%)}$$" But it said "?7Steve?f."
How can I configure it to use "&" instead of "?"? Or, is there another way that I should be doing it?
Also, can I use the joinedplayer variable outside of a script like that?
Lastly, It seemed to be working as expected, but then i noticed that when i would join, it would fire the event for every player currently online as if they had just joined.
Events are still a little experimental at the moment so sorry you're having problems. The main issue is that some servers seem to contaminate the player names with colour codes so I need to make sure that the colour codes are stripped. The reason you're seeing "?" being transmitted is that the mod strips any invalid characters in the chat prior to transmitting the message and replaces them with "?", this is to avoid being kicked by the server for sending invalid characters.
You can use the JOINEDPLAYER variable outside of the event handler by writing it to a new shared variable using SET. String variables need to be preceded by ampersand, and shared variables by at, so a shared string variable looks like "@&lastjoined". All user-defined variables must be lower case. Put this in the onPlayerJoined event to capture the value to a shared string variable:
Edit: I am trying to figure the language out slowly but surely. What language is this? Java?
Sorry If I am asking silly, simple questions. If you could, please point me to somewhere I could learn this.
The language is a custom language designed to provide the specific functionality offered by the mod, it's based (very) loosely on various other languages, but not any particular one. It has its own (pretty simple) syntax and commands and the current authoritative source is the readme.txt.
Is there any way to use the onChat event to answer questions that have the keywords I can define? Also, not have it detect my message so it doesn't cause an endless loop. And if you can, add some kind of spam control so if it DOES go crazy it will stop itself.
Flood control is something I will look at in a future version, the best solution for now is to test your script output using LOG and then change it to ECHO once you're sure it's working right.
Currently there is no fixed format for minecraft chat, so the problem of parsing the inbound chat is a fairly common one but not easily surmounted. If you play mainly on one server with a particular format then it's easier, but can still be tricky. The main issue is that there is no definitive way to tell which player said what, or even if it was you because the chat comes back as plain text in a format determined by the server.
This doesn't mean it's impossible, it just means it's a bit of a pain. The answer (most of the time) is to formulate a regular expression which will allow you strip out the wheat from the chaff in terms of the player name and the actual message. For example for vanilla, we know that the player name will always be encased in < > so we can use the following regexp in the onChat handler to store the last player name and last message in two global variables that can be used later:
This works because we know that valid player names can only contain between 2 and 16 characters and will be wrapped in < >. Unfortunately you will have to formulate a regex for your server if you don't play on vanilla.
Once that obstacle is overcome, responding to questions becomes pretty easy:
MATCH(%CHAT%,"^<(\w{2,16})> (.*)$",&chatplayer,1);
MATCH(%CHAT%,"^<(\w{2,16})> (.*)$",&chatmessage,2);
IF(&chatplayer != PLAYER);
IFMATCHES(%&chatmessage%,"where.+?(buy|sell).+?items");
ECHO("You can buy and sell items at FooTown in Bar");
ELSE;
IFMATCHES(%&chatmessage%,"who.+?moderators");
ECHO("The moderators are Bill and Ted");
ENDIF;
ENDIF;
ENDIF;
As just a simple example. Sorry if there are typos in there, I'm typing this direct into the forum which can sometimes lead to mess-ups.
On a completely unrelated note, Dratcha sent me his macros folder and I immediately identified the source of his problem, which highlights a misunderstanding about EXEC versus using the $$<file.txt> include syntax. Re-posting my response here in case it helps anyone else.
Quote from Mumfrey »
Aha, I see the problem straight away: you are using EXEC to call the script rather than using an include.
To clarify, local variables are stored in whatever "template" triggers the macro, the template is the definition of the macro which is attached to a key or event. The template itself is used as the context for a running macro and that is where local variables are stored.
Thus, if you have the following template:
$${TOGGLE(foo);LOG(%foo%);}$$
when you run the macro, the flag "foo" is stored in the template and next time you run the macro the value of "foo" will have been rememebered. This means if you copy the same template to another key, the other key will have its own version of the local flags, and the two macros won't interfere with each other.
Some macros are too long to go in the template, but you can include a file into the maco using $$<filename.txt> which literally just inserts the contents of the file directly into the template, but, it's still linked to the same template!
Imagine you have a file, "test.txt" which contains
TOGGLE(foo);LOG(%foo%);
If you bind a key to
$${$$<text.txt>}$$
when you run the macro, the text from the file will be inserted and produce the following macro
$${TOGGLE(foo);LOG(%foo%);}$$
which is what we wanted!
EXEC is a different story, EXEC is for creating tasks which have their own local variables and scope. The "template" in this case is a temporary template created specifically for the purpose of running the task. This means that they cannot store their local variables because every time you call EXEC you effectively create a brand new template. For this reason you should avoid using EXEC unless you need to run a task.
Hope this all makes sense now, basically replace your EXEC calls with ordinary includes and you should be good to go.
So an exec simply has it's own variables, but everything else works the same?
(wanna be sure before i start using it =P)
Also, does the same exec in the same code remember it's own variables, or are they deleted as soon as it finishes?
Basically an include just inlines the text file's contents directly into the macro, therefore local variables and instance variables are available to the included file because it's essentially just inserted directly as if it had been typed in.
EXEC can access shared variables and globals but any local variables are only available within the scope of that single EXEC, this is because each call to EXEC actually creates a brand new template which has no awareness of the scope of the macro that launched it, these local variables are also not persisted so you're correct in your assertion that they will be deleted when the spun off task terminates.
EXEC is useful for running scripts as "tasks" and I added it to go hand in hand with onJoinGame to allow named tasks to be spun off (rather than having everything running in the context of onJoinGame making it hard to determine which task to stop!).
In general, avoid using EXEC for anything except this because includes are lighter-weight and more flexible.
Sort of, I was trying to outline the differences between the two approaches. For example includes can obviously contain parameters like $$f and $$[name] because they're in the context of the original macro. Whereas an EXEC'd script cannot use parameters except for those passed to it as part of the EXEC command.
I'm having similar troubles comparing variables to numbers =P
For example, IF(%LEVEL% > 10) and IF(%LEVEL% < 10)
The second one seems to be always true, while the first was always false at levels 36-40
I also couldn't get timed FOV to work correctly
i have a script that takes my number and does FOV(#, 2) with it, but it only works once, after that it always zooms in, and always jumps back when it's reached some point
By only works the first time mean i should specify, to reset it i have to drag the default fov slider in minecraft's options menu
the script still keeps it's variables and nothing else changes, i have no idea how they could possibly affect each other
How do you pass parameters to an EXEC o.O?, are those used before execution just automatically given to it
how about those written after the EXEC
Found a strange thing with using: echo("/tp $$u");
I use this:
I have it on my end key.
if(test);
unset(test)
stop(end);
else;
Set(test);
echo("/tp $$u");
;Some more code in here, just some Wait and sending another server command.
unset(test)
endif;
The echo("/tp $$u"); part gets triggerd even if the flag is true (or false, gets confused by flags :P).
This is correct. Actually it's not executing the ECHO command but it will of course prompt for the value of $$u during compilation because the compiler knows nothing about the conditionals, they are not processed until the final macro is executed.
I also couldn't get timed FOV to work correctly
i have a script that takes my number and does FOV(#, 2) with it, but it only works once, after that it always zooms in, and always jumps back when it's reached some point
These are available inside the EXEC'd script as parameters $$[1], $$[2] and so on, or as variables named var1, var2 etc. No variables from the scope of the invoking macro are passed to the EXEC instance, it's a completely new template.
Oh, they work on their own?, Awesome, thanks
----------------------------------------------------------------------------------------------------------------------------------
I think i had it disabled because i had some weird flashing, do i need it?, i can turn it back on
i still don't understand why such a thing could happen though..
----------------------------------------------------------------------------------------------------------------------------------
oh, that's even more useful =D, thanks
@acuena:
i don't think so..., the closest you could get that i can think of is to have another button open player selection and it would wait until you selected a new player from the list
The server message sent out when a new player joins for the first time is "A new recruit, [There user name] has joined!". This message is a server broadcast and is not attached to a user name. So, what about using just the first and last of the text to identify for and then capture the user name to be reused in the welcome message to give it a personized feel. I do not have much coding skills for this so is rather confusing.
Would it be possible to get the list of regions that exist in the plugin called WorldGuard?
This is a really neat idea, I personally use worldguard and keep my regions in a preset list but I think it's common enough to be worthwhile adding as an additional custom list. Added to the feature list to implement.
The server message sent out when a new player joins for the first time is "A new recruit, [There user name] has joined!". This message is a server broadcast and is not attached to a user name. So, what about using just the first and last of the text to identify for and then capture the user name to be reused in the welcome message to give it a personized feel. I do not have much coding skills for this so is rather confusing.
Are there any colour codes in the message? If there are not any then this should do the trick:
onChat
IFMATCHES(%CHAT%,"a new recruit, (\w{2,16}) has joined");
MATCH(%CHAT%,"a new recruit, (\w{2,16}) has joined",&recruitname,1);
ECHO("Welcome %&recruitname%!");
ENDIF;
If there are colour codes in the message you'll need to modify it slightly but basically that should work.
If it was only one admin adding regions that would be a way to do it but if there is more than one it could get a bit tricky.
Indeed, the main problem is that the auto-discovery method I currently use is prone to contamination from ordinary chat. I'm working on a server-side plugin for transmitting certain information direct to the mod that can be used by admins for exactly this kind of thing.
Here is my coding that I have so far.
IFMATCHES(%CHAT%,"A new recruit,");
WAIT(1);
ECHO(/h Welcome!);
WAIT(5);
ECHO(/h Escape from the dungeon!);
WAIT(5);
ECHO(/h Please use /greylist to complete your registration process.);
ENDIF;
So, essentially, you want to make a macro that detects when a new player joins the game, and then say the above?
To do this efficiently, you will probably need to use a regex to match against the chat string. To get the correct string, I need you to do this:
Then, I need you to bind this to a key (doesn't matter which):
Then, in your options, enable "Store sent messages in local history".
Now, the next time a new player joins your server, I need you to activate that macro up there. You will need to do it immediately after they join, or else you will not get the correct message.
After that, you will need to open the chat bar and press up. Copy all of that text (by holding shift and pressing the arrow keys) and pm it to me. I will then be able to make you a quick regex to detect a new player. I can also get you their name if you want.
The problem with what you have now is that if someone says "A new recruit," in the chat, it will trigger, and you probably don't want that.
How can I configure it to use "&" instead of "?"? Or, is there another way that I should be doing it?
Also, can I use the joinedplayer variable outside of a script like that?
Lastly, It seemed to be working as expected, but then i noticed that when i would join, it would fire the event for every player currently online as if they had just joined.
Edit: I am trying to figure the language out slowly but surely. What language is this? Java?
Sorry If I am asking silly, simple questions. If you could, please point me to somewhere I could learn this.
I am actually trying to do something like this aswell:
move forword and have it mine at the same time.
the code or pic would be nice
Events are still a little experimental at the moment so sorry you're having problems. The main issue is that some servers seem to contaminate the player names with colour codes so I need to make sure that the colour codes are stripped. The reason you're seeing "?" being transmitted is that the mod strips any invalid characters in the chat prior to transmitting the message and replaces them with "?", this is to avoid being kicked by the server for sending invalid characters.
You can use the JOINEDPLAYER variable outside of the event handler by writing it to a new shared variable using SET. String variables need to be preceded by ampersand, and shared variables by at, so a shared string variable looks like "@&lastjoined". All user-defined variables must be lower case. Put this in the onPlayerJoined event to capture the value to a shared string variable:
The language is a custom language designed to provide the specific functionality offered by the mod, it's based (very) loosely on various other languages, but not any particular one. It has its own (pretty simple) syntax and commands and the current authoritative source is the readme.txt.
Flood control is something I will look at in a future version, the best solution for now is to test your script output using LOG and then change it to ECHO once you're sure it's working right.
Currently there is no fixed format for minecraft chat, so the problem of parsing the inbound chat is a fairly common one but not easily surmounted. If you play mainly on one server with a particular format then it's easier, but can still be tricky. The main issue is that there is no definitive way to tell which player said what, or even if it was you because the chat comes back as plain text in a format determined by the server.
This doesn't mean it's impossible, it just means it's a bit of a pain. The answer (most of the time) is to formulate a regular expression which will allow you strip out the wheat from the chaff in terms of the player name and the actual message. For example for vanilla, we know that the player name will always be encased in < > so we can use the following regexp in the onChat handler to store the last player name and last message in two global variables that can be used later:
This works because we know that valid player names can only contain between 2 and 16 characters and will be wrapped in < >. Unfortunately you will have to formulate a regex for your server if you don't play on vanilla.
Once that obstacle is overcome, responding to questions becomes pretty easy:
As just a simple example. Sorry if there are typos in there, I'm typing this direct into the forum which can sometimes lead to mess-ups.
On a completely unrelated note, Dratcha sent me his macros folder and I immediately identified the source of his problem, which highlights a misunderstanding about EXEC versus using the $$<file.txt> include syntax. Re-posting my response here in case it helps anyone else.
(wanna be sure before i start using it =P)
Also, does the same exec in the same code remember it's own variables, or are they deleted as soon as it finishes?
'Cause tomorrow spring is here
Basically an include just inlines the text file's contents directly into the macro, therefore local variables and instance variables are available to the included file because it's essentially just inserted directly as if it had been typed in.
EXEC can access shared variables and globals but any local variables are only available within the scope of that single EXEC, this is because each call to EXEC actually creates a brand new template which has no awareness of the scope of the macro that launched it, these local variables are also not persisted so you're correct in your assertion that they will be deleted when the spun off task terminates.
EXEC is useful for running scripts as "tasks" and I added it to go hand in hand with onJoinGame to allow named tasks to be spun off (rather than having everything running in the context of onJoinGame making it hard to determine which task to stop!).
In general, avoid using EXEC for anything except this because includes are lighter-weight and more flexible.
hmm...
yay, knowledge
'Cause tomorrow spring is here
Sort of, I was trying to outline the differences between the two approaches. For example includes can obviously contain parameters like $$f and $$[name] because they're in the context of the original macro. Whereas an EXEC'd script cannot use parameters except for those passed to it as part of the EXEC command.
For example, IF(%LEVEL% > 10) and IF(%LEVEL% < 10)
The second one seems to be always true, while the first was always false at levels 36-40
I also couldn't get timed FOV to work correctly
i have a script that takes my number and does FOV(#, 2) with it, but it only works once, after that it always zooms in, and always jumps back when it's reached some point
By only works the first time mean i should specify, to reset it i have to drag the default fov slider in minecraft's options menu
the script still keeps it's variables and nothing else changes, i have no idea how they could possibly affect each other
How do you pass parameters to an EXEC o.O?, are those used before execution just automatically given to it
how about those written after the EXEC
'Cause tomorrow spring is here
This is correct. Actually it's not executing the ECHO command but it will of course prompt for the value of $$u during compilation because the compiler knows nothing about the conditionals, they are not processed until the final macro is executed.
See this post for more detail on compilation.
Wrapping a variable in %'s converts it to a string literal, so if your level is 10 you're essentially evaluating
which makes no sense, in fact a string will always evaluate as if it has a very high value. Use the variable in the conditional not its value:
Do you have optifine installed?
EXEC's parameters are
These are available inside the EXEC'd script as parameters $$[1], $$[2] and so on, or as variables named var1, var2 etc. No variables from the scope of the invoking macro are passed to the EXEC instance, it's a completely new template.
----------------------------------------------------------------------------------------------------------------------------------
I think i had it disabled because i had some weird flashing, do i need it?, i can turn it back on
i still don't understand why such a thing could happen though..
----------------------------------------------------------------------------------------------------------------------------------
oh, that's even more useful =D, thanks
@acuena:
i don't think so..., the closest you could get that i can think of is to have another button open player selection and it would wait until you selected a new player from the list
'Cause tomorrow spring is here
This is a really neat idea, I personally use worldguard and keep my regions in a preset list but I think it's common enough to be worthwhile adding as an additional custom list. Added to the feature list to implement.
Are there any colour codes in the message? If there are not any then this should do the trick:
onChat
If there are colour codes in the message you'll need to modify it slightly but basically that should work.
Indeed, the main problem is that the auto-discovery method I currently use is prone to contamination from ordinary chat. I'm working on a server-side plugin for transmitting certain information direct to the mod that can be used by admins for exactly this kind of thing.
Macro/Keybind mod Wiki
This is in development already.