Skip to content

Player Events

Fired when a player successfully connects to the server

ParametersTypeDescription
player*PlayerScriptObjectPlayer who joined
data*dict{'user': str, 'uuid': str, 'ip': str, 'date': datetime, 'logged-in': bool}
delayint / floatWait before running the block, in seconds
@player.on_join(player, data):
player.log(f'Welcome to {server}, {player}!')

Fired when a player disconnects from the server

ParametersTypeDescription
player*PlayerScriptObjectPlayer who left
data*dict{'user': str, 'uuid': str, 'ip': str, 'date': datetime, 'logged-in': bool, 'playtime': timedelta}
delayint / floatWait before running the block, in seconds
@player.on_leave(player, data):
server.broadcast(f'Goodbye, {player}!')
server.log(f'{player} was online for {data["playtime"]}')

Fired when a player sends a message in the chat, excluding commands

ParametersTypeDescription
player*PlayerScriptObjectPlayer who sent the message
message*strMessage content
delayint / floatWait before running the block, in seconds
@player.on_message(player, message):
if "can i have op" in message.lower():
acl.ban_player(player)

Fired when a player dies from another player, or the environment

ParametersTypeDescription
player*PlayerScriptObjectVictim
enemy*PlayerScriptObject / NoneAttacker, or None if environmental
message*strMessage content
delayint / floatWait before running the block, in seconds
@player.on_death(player, enemy, message):
if enemy:
enemy.log(f"Did you know: murder is a crime {enemy}?")
acl.ban_player(enemy)
else:
player.log(f"You should really be more careful {player}!")

Fired upon a player earning an advancement

ParametersTypeDescription
player*PlayerScriptObjectAwarded player
advancement*strAdvancement title; see all advancement titles
delayint / floatWait before running the block, in seconds
@player.on_achieve(player, advancement):
if advancement == 'Stone Age':
player.log_success(f'Seriously {player}?? Pick... on someone your own size!')

Used for registering custom commands and augmenting existing ones

ParametersTypeDescription
player*PlayerScriptObjectPlayer who executed the command
command*strDefine the command verb
argumentsdictArgument map for execution: {'arg1': True, 'arg2': False, ...}
  • Argument names are arbitrary. Values can be retrieved with arguments['name']
  • True denotes a required argument; optional arguments must follow all required arguments
permissionstrRestricts execution to privileged users; can be 'anyone', 'op', 'server', or a custom permission. Defaults to 'anyone'
descriptionstrDescription displayed in the !help menu; the entry will only be shown to users who meet the minimum permission level
hiddenboolDefaults to False. Hides the command from !help and suppresses automatic permission/syntax error feedback, but permission and argument validation still apply. This is used for augmenting existing commands
@player.on_alias(player, command='test', arguments={'arg1': True, 'arg2': False}, permission='op'):
server.log(f'{player.name} executed {command} with the following arguments: {arguments}')

Following the above example when a player with the anyone privilege executes !test foo bar:

  • amscript will determine that the player doesn’t meet the minimum permission and will fail
  • Permission tree order is: server > op > anyone

Following the above example when a player with the op or server privilege executes !test foo bar:

  • arguments will be converted to {'arg1': 'foo', 'arg2': 'bar'} after execution, and can be accessed in the function as such
  • Calling arguments['arg1'] will return the value of 'foo'