Alchemist's Awakening

Alchemist's Awakening

Not enough ratings
Scripting commands
By Osaris Games
This guide will help you script your custom blocks, items, weapons and powers.

[Work in progress, please check back later]
   
Award
Favorite
Favorited
Unfavorite
Introduction
Alchemist's Awakening comes with a powerful scripting language similar to Lua which lets you create really unique custom items and weapons and share then in the Steam Workshop.

Custom entities contain a number of listeners for event, which you can script using commands:
  • OnCreated: called when the entity is first created.
  • OnUpdate: called at every frame is the entity is loaded.
State-dependent listeners are called only for the current state of the entity. You can change the state using the command setState otherstate
  • OnUpdate: called at every frame is the entity is loaded.
  • OnClick: called when a player uses the Right click on an entity.
  • OnLeftClick: called when a player uses the Right click on an entity.
  • OnClickRelease: called when the use use the Right click on an entity.
  • OnLeftClickRelease: called when the use use the Right click on an entity.
  • OnMenuClose: called when a menu was opened (for example, to ask the user something) and closed.
  • OnCollide: called when a player or another entity is colliding the entity.

Variables and members
Variables
There are two types of variable: &variable will be a world global variable, which value is shared between all entities, and $variable will be an entity local variable, accessible only within one instance of an entity (but shared between all its different functions and states).

Variables can contain numbers, string, or entities. When you want to assign entities or string, please specify the type:
Example:
$i = 1
&j = $i
entity $entity = this.owner
string &text = "Hello, world"

A few pre-defined global variables exist in all worlds:
  • &timestamp contains the number of seconds since the world was created
  • &time contains the time in hour (0 to 24), for example 6.5 represent 6h30 AM
  • &deltatime contains the elapsed time, in second, since the last frame (arount 0.016 s at 60 FPS)
  • &name
  • &gamemode will be 0 is the world is in Survival or 1 for Creative mode
  • &type
  • &seed the random seed of the world
  • &details
  • &generator flat world or normal
  • &sealevel
  • &spawnx
  • &spawny spawn postition of every player
  • &spawnz
  • &monsters
  • &weather
  • &timespeed
(some of these variables are not set yet)

Similarly, each entities have a few pre-defined local variables:
  • $name contains the name of the entity
  • $timeLived contains the age in seconds
  • $realDeltaTime contains the time since the last update of the entity. It can be useful because entities are not updated when they are in a chunk which is not loaded, so you need to use $realDeltaTime to know for how much time the entity has not been updated.
  • $birthDate contains the birthDate in seconds relative to the creation of the world.

Entity members
Members are similar to local variables, but they can be accessed from another entity.
For example:
$variable = target.gamemode
owner.x = owner.x + &deltatime * 5

Here as the different entity members:
  • x
  • y contains the current position of the entity
  • z
  • speedx
  • speedy contains the current speed of the entity
  • speedz
  • dirx
  • diry contains the current looking direction of the entity
  • dirz
  • accx
  • accy contains the current acceleration of the entity
  • accz
  • anglex
  • angley
  • life contains the current life percent of the entity
  • gamemode will be 0 is the entity is in Survival or 1 for Creative mode
  • xp
  • score
  • armor reduces damages taken
  • blockx
  • blocky target block position (set by the raycast command)
  • blockz
  • targetx
  • targety target position
  • targetz
  • type 1: Player, 2: Other player, 3: Mob, 4: Attack, 5:Custom creature, 6:Weapon, 7:Item
  • typeid subtype id
  • name current name

Here are the accessors to entities:
this : the current entity
attached : if the entity is the tool, "attached" represent the entity currently holding it
target : the target of the entity (can be changed using acquireTarget command)
player : the entity which is clicking or colliding with the current entity
player.target : the current target of the entity which is clicking or colliding
player.attached
owner : the creator of the current entity
owner.target : the current target of the creator of the current entity


Script syntax
Syntax

You can create functions using this syntax:
function name
...
end

You'll then be able to call a function using:
call name
from any of the listeners commands of this entity (not necessarily the same listener).
or timer name time to wait time before calling it (note: only one timer can be set for each entity. Calling timer again with another function before time will cancel the first timer.)

Functions are also really useful when you create a choice:
choice reset
choice "Do it!" call onefunction
choice "Cancel" default
choice show

Another important syntax is the If statement.
if condition then
...
end

Or:

if condition then
...
else if condition then
...
else
...
end

Conditions can be combined using && (and), || (or).
For example:
if target!=null && target.type==3 && target.typeid==golem then
attack fireball 1
end
Commands
[THIS SECTION IS WORK IN PROGRESS]

say <text>
say "Hello world!"

acquireTarget [Launching entity] <radius> [angle]
acquireTarget this 5

attack [Launching entity] <attackid> <strenght>
with attackid being:
  • fireball: 0
  • lightning: 1
  • wind: 2
  • wolf_attack: 3
  • reindeer_attack: 4
  • thief_attack: 5
  • lion_attack: 6
  • stone_tempest: 8
  • punch: 8
  • flames: 10
  • sword: 11
  • golem_attack: 12
attack this fireball 1

setstate <otherState>
setState default

call <function>
call myfunction

timer <function> <time>
timer myfunction 3

display <text> time x y zoom align size r g b a background
display "Bomb has been planted!" 3 0.5 0.5 2 center 0.5 1.0 0 0 0.8 1.0 0.5 0.2 1.0

spawnBlock x y z wood 10
Here are the accepted block types:
smooth_stone stone irregular cube block wood wood_large wood_small wood_medium column column_medium column_large column_small column_very_small slab slope middle_slab wood_very_small empty undef entity stairs glass glass_slab glass_slope glass leaf grass dry_grass flower flower1 flower2

spawnMob wolf this.x+10 this.y this.z this random(360)
spawnmob golem this.x+3 this.y this.z-random(20)
spawnentity 9_oven this.x+10 this.y this.z-random(20)
breakBlock other.x other.y other.z
spawnSchematic arbre3 this.x-10 this.y this.z-random(20)

choice reset
choice addChoice "Go to default state" default
choice addChoice "Call a function" call function name
choice show


give
wait
playsound
transform
transfer
menu
choice
cleardisplay
raycast
raycastbefore

14 Comments
AugeVonBlau 25 Dec, 2021 @ 6:04pm 
Has anyone figured out how to spawn custom mobs? I've got the spawnmob command down, but I can't spawn anything that isn't hostile... soo it kind of defeats the purpose.
Drikon 4 Jul, 2020 @ 2:21am 
I figured out how to get xp to the player when an object on the world is destroyed/absorbed using "XpGain" in Advanced options but not how to give the player Xp when they "craft" an item into the world. I was trying different syntax in OnClick to test what the line of code would look like give the player xp.
Drikon 30 Jun, 2020 @ 12:23pm 
If I wanted to create a crystal mob how would I give the player XP upon a kill and the mob's death drop crystal. I did not see a crystal block type. How do we create a "specific mob kill count per specific Player" variable that saves between sessions. This is so I can give less XP per kill after so many kills of one type of mob.
sarainia.angelsong 23 Apr, 2020 @ 4:57am 
How to change original spawn location for all players, or how to teleport all players to a specific coordinate? :SoraSmile:
ExpA 29 Sep, 2019 @ 5:24am 
and what names has "display" alignment layout? like how can i write bottom_right?
ExpA 29 Sep, 2019 @ 5:22am 
and how can i display a number? like $wind in storage crystal?
ExpA 29 Sep, 2019 @ 1:35am 
what is the "addEffect" does? idk syntax
ShadowM 10 Sep, 2019 @ 6:52pm 
Thank you!
Osaris Games  [author] 10 Sep, 2019 @ 12:42pm 
Give:
Parameter recipient;
Parameter element;
Parameter amount;
Example:
give player frost 20

Note: to give an item the command is
GiveItem:
Parameter id_item;
Parameter recipient;
Example:
giveItem player 72

Transfer:
Parameter element;
Parameter amount;
Example:
transfer frost 20
ShadowM 10 Sep, 2019 @ 7:31am 
Can we have the details of using the commands give and transfer?