I'd like to setup my bukkit server to run a small script (like, giving players basic items) when players respawn or enter a world for the first time (or cause every 10th respawn to be in another place). Is there a plugin to do this with bukkit?
2 Answers
Yes, it is possible to run a script on certain events like respawning or first join.
You will need two plugins to do be able to do this: Autorun and CommandHelper. This will assume you have both fully installed.
For this example, I want two commands to run when a player logs on.
Decide what commands you want to use
Create a new alias/macro in Commandhelpers config.txt with the following syntax:
/macro_name = /command_1 \/command_2
Do a server reload
In game, create a Autorun identifier for your macro:
/addacommand identifier_name macro_name
Now bind the identifier to run when a player joins:
/setjoincommand identifier_name
Done.
This is a very simplified way of doing something like this, and both plugins are capable of much more. For instance Autorun can run commands when a player walks over a defined block; and Command helper can be used as an advanced scripting plugin.
Always make sure to read the instructions for both plugins before you start. However, you probably only need to read the beginners section of Commandhelper, as the rest covers very advanced scripting information.
Hope this answers your question.
-
Since this answer was written back in 2012, CommandHelper now has the ability to bind to events, so Autorun is no longer required. I'll submit a separate answer with details :) Commented Mar 5, 2021 at 4:08
-
Also, the
config.txt
no longer exists and is replaced byaliases.msa
instead - with the same functionality. Commented Mar 5, 2021 at 13:01
Since the other (marked correct) answer was written in 2012, CommandHelper now supports binding to events and therefore this is possible with only CommandHelper installed as a plugin.
Install plugin CommandHelper. Download it here: https://builds.enginehub.org/job/commandhelper
Restart your server to generate configuration
Add the following to
plugins/CommandHelper/main.ms
bind('player_spawn', null, null, @event) {
// Do something here, like sending them a message.
msg('Oops, that was silly of you!');
}
- Run
/reloadaliases
from the server console to activate it (or restart server)
CommandHelper uses a language called MethodScript, and the API documentation with a list of functions and how to use them can be found here: https://methodscript.com/docs/3.3.4/API.html
If you want to hook into different events (e.g. player_join
as well), you may be interested in the Event API documentation: https://methodscript.com/docs/3.3.4/Event_API.html
Specific functions you may be interested in:
- Giving players basic items (see pgive_item)
- Change respawn location (intercept
player_spawn
event as in the example above, but change the spawn location withmodify_event('x', 123)
and similar for y/z) - Tracking if they are up to their 10th respawn (take a look at
store_value
/get_value
, as you can use them to store a counter value like 'player.respawnCount')
-
1Great to know, thanks! Unfortunately I haven't used bukkit for years and can't test this... Maybe nowadays a simple command block can also achieve this 🤔– ZommuterCommented Mar 5, 2021 at 7:52
-
@Zommuter - Yeah, I noticed it was an old question :) Thought I'd answer for the benefit of others that come across it. Command blocks are powerful, but I don't think they can hook into e.g. the player respawn event. Commented Mar 5, 2021 at 13:03
-
1I stand corrected! It looks like command blocks can detect a respawn - gaming.stackexchange.com/questions/336529/… - but CH would be more flexible. Depending on the use case, it's entirely possible command blocks could be enough though. Commented Mar 5, 2021 at 13:07
kit
for an easy example, and maybe a different one every 10th respawn. Or making them invulnerable for the first minute unless they leave the spawning region earlier, if you prefer a challenge ;-)