Rûn Cookbook: The World
Recipes for doors, shops, quests, enemies and scenes. Each has been run in the engine in Test mode. The numbering goes on from Rûn Cookbook: Logic.
Before you start
The recipes use an item cook_key, an item cook_ring and a quest cook_lamb. Make them on their pages in the asset manager, or at the console:
itemdef cook_key Iron_Key
itemdef cook_ring Silver_Ring
itemdef cook_ring price 40
savedata items
questdef cook_lamb The_Lost_Lamb
questdef cook_lamb stage lamb_found Find the lamb
questdef cook_lamb stage lamb_home Bring it home
savedata questsitemdef and questdef make the rows in memory and savedata writes them into the project's data files.
14. A locked door
The door's event runs [use] when she presses the use key at it. Without the key it stops at [locked].
[use]
if count(cook_key) < 1
run cook_door locked
end
say The key turns.
flag set cook_door_open
[locked]
say It is locked. There must be a key somewhere.It is locked. There must be a key somewhere.15. Giving and taking
[use]
give cook_key 1
gold 50
if count(cook_key) >= 1 and gold >= 50
take cook_key 1
gold -50
give cook_ring 1
say You trade the key and some coin for a ring.print(Player.Count("cook_ring"))116. A shop that opens on a condition
A trader who sells only to those who have done the quest's first stage:
[talk]
if quest(cook_lamb) >= 1
say Welcome back, shepherd.
else
say Find my lamb first, then we can talk trade.Find my lamb first, then we can talk trade.When the condition holds, add shop <villager> on the line after the welcome to open the villager's counter. See Shops.
17. A quest step
Finish a stage by its flag or its number, and read how many are done:
[use]
quest cook_lamb lamb_foundprint(Player.QuestStage("cook_lamb"))118. Saving a choice
[use]
set cook_sided marsh
flag set cook_chose[use]
require flag cook_chose : undecided
if flag(cook_chose)
say You stand with the {cook_sided} folk.
[undecided]
say You have not chosen yet.Both the variable and the flag ride the save. See Rûn Saving State.
19. A healing spring
[use]
heal 100%
fx hit_spark player
say The water mends you.20. Making and removing things
object create puts a thing into the world with a name; object destroy takes everything of that name away.
[use]
object create barrier cook_wall 900 500 128 32
wait 2
object destroy cook_wall21. A loop over the enemies
number alive = 0
for (number i = 0; i < World.EnemyCount(); i = i + 1) {
if (World.Enemy(i).alive) alive = alive + 1
}
print("enemies standing:", alive)enemies standing: 022. A custom damage rule
Every hit she takes is halved while the flag cook_warded is up:
before damage(number amount, text target) {
if (target == "player" && World.Flag("cook_warded")) amount = amount / 2
}23. A boss with phases
A live program watches the boss and raises a flag for each phase; the phases' events read the flags. World.Enemy(i) hands out a foe with its .hp and .maxHp.
on update(number dt) {
for (number i = 0; i < World.EnemyCount(); i = i + 1) {
Foe f = World.Enemy(i)
if (f.type == "cook_ogre" && f.alive) {
if (f.hp < f.maxHp / 2 && !World.Flag("ogre_angry")) {
World.FlagSet("ogre_angry")
}
}
}
}An event script, run from a controller whose condition is flag(ogre_angry), plays the second phase: new words, a shake, more foes.
24. A cutscene
Take the controls, move the camera, speak, and give everything back:
[use]
lock
letterbox on
camera zoom 2 1
wait 1
say The bridge is out.
wait 2
camera follow
letterbox off
unlockA scene where several things happen at once is a block script; see Block Scripts and Cutscenes.
25. A line in the dialog box, with no villager
[use]
speak Old Sign : The mine is closed.26. A zone that notices who walks in
[enter]
if zoneher
say You step onto the old stones.
add cook_steps 1
[exit]
say The stones fall quiet.The stones fall quiet.