Skip to content

Commit c2ff8db

Browse files
authored
Item purchase scripting (#412)
# Description This PR primarily adds an `onPurchase()` script event for items. The intention is that an admin can create an item listed in a shop that can be scripted to do creative things that we may not anticipate, allowing them to leverage shops for other purchases. An initial example has been created/added, which is buying a `room for rent` at the inn. It also addresses some other small typos and bugs. ## Changes - Added `onPurchase()` item script event and documentation - Fixed a typo for a room: `paventment` => `pavement` - Added an example `onPurchase()` event to the inn shop (`room rental`). - Fixed `cancel-on-action` buffs to cancel on leaving to an exit - Renamed "leave" to "downstairs" in Inn room, since "l" (for look) was a little confusingly taking the "leave" exit after sleeping. - Inn room now uses an ephemeral copy per player, so players don't all end up in one instance of the room. - roominfo template had an error, referring to old ZoneInfo. This is fixed. - `buy` was not doing anything when you weren't in a shop. Now provides feedback to the user. - Some small language updates around the `buy` command feedback. ### Links #411
1 parent 428928d commit c2ff8db

File tree

14 files changed

+87
-27
lines changed

14 files changed

+87
-27
lines changed

_datafiles/guides/building/scripting/FUNCTIONS_ROOMS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838
Returns an Object with key/value pairs of `ProvidedRoomId`=>`NewRoomId`
3939
Creates ephemeral instances of the RoomId's provided.
4040

41+
NOTE: Ephemeral rooms clean up (delete from memory) mobs, items, etc. when no players occupy the set of created rooms.
42+
4143
| Argument | Explanation |
4244
| --- | --- |
4345
| RoomIds | an array of integers containing RoomId's you want instanced |

_datafiles/guides/building/scripting/SCRIPTING_ITEMS.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,21 @@ In all other ways, this follows the same rules as the normal `onCommand()` funct
8787
| item | [ItemObject](FUNCTIONS_ITEMS.md) |
8888
| room | [RoomObject](FUNCTIONS_ROOMS.md) |
8989

90+
---
91+
92+
```
93+
function onPurchase(user ActorObject, item ItemObject, room RoomObject) {
94+
}
95+
```
96+
97+
`onPurchase()` is called when a player successfully purchases an item in a shop, after the item is
98+
99+
| Argument | Explanation |
100+
| --- | --- |
101+
| user | [ActorObject](FUNCTIONS_ACTORS.md) |
102+
| item | [ItemObject](FUNCTIONS_ITEMS.md) |
103+
| room | [RoomObject](FUNCTIONS_ROOMS.md) |
104+
105+
Returning `false` will prevent the user from being given the object. This can be useful if you want to initate a script from a purchase, but not actually grant the item to the user, such as purchasing extra lives, a ticket for travel, or renting a room.
106+
90107
---
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
3+
function onPurchase(user, item, room) {
4+
5+
var newRoomIds = CreateInstancesFromRoomIds( [432] );
6+
7+
if ( newRoomIds[432] ) {
8+
9+
SendUserMessage(user.UserId(), "You are directed to a room upstairs with a large bed. How inviting...");
10+
SendRoomMessage(room.RoomId(), user.GetCharacterName(true)+" says something to the Inn keeper and is escorted to another room.", user.UserId());
11+
12+
user.MoveRoom(newRoomIds[432]);
13+
return false;
14+
}
15+
16+
return false;
17+
}
18+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
itemid: 102
2+
value: 5
3+
hands: 0
4+
name: room rental
5+
namesimple: room rental
6+
description: Rent a room in the Inn and rest up.
7+
type: service
8+
subtype: generic
9+

_datafiles/world/default/mobs/frostfang/7-wench.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ groups:
77
combatcommands:
88
- 'callforhelp 7:guard:calls for the guards.'
99
idlecommands:
10-
- 'say You can <ansi fg="command">sleep</ansi> here for a bit here to refresh.'
11-
- 'say If you''re hungry check the <ansi fg="command">list</ansi> of food for sale.'
10+
- 'say If you''re hungry check the <ansi fg="command">list</ansi> of food and services for sale.'
1211
activitylevel: 10
1312
character:
1413
name: wench
@@ -19,6 +18,8 @@ character:
1918
spellbook:
2019
curepoison: 50
2120
shop:
21+
- itemid: 102
22+
quantitymax: 0
2223
- itemid: 30004
2324
quantitymax: 2
2425
- itemid: 30005

_datafiles/world/default/rooms/frostfang/432.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ crowbarAvailableRound = 0;
44
const crowbar = ["crowbar", "rod", "metal", "bar"];
55
const verbs = ["get", "take", "grab", "steal", "snatch"];
66

7+
8+
function onEnter(user, room) {
9+
user.GiveBuff(15, "sleep");
10+
return false; // return false to prevent the "auto look"
11+
}
12+
13+
714
function onCommand_look(rest, user, room) {
815

916
matches = UtilFindMatchIn(rest, crowbar);

_datafiles/world/default/rooms/frostfang/432.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ description: The dim glow of a crackling hearth in one corner bathes the wooden
1313
mapsymbol: I
1414
maplegend: Inn
1515
biome: city
16+
nouns:
17+
metal rod: a crowbar leans against the hearth. It must be used as a fire poker.
1618
exits:
17-
leave:
19+
downstairs:
1820
roomid: 61
1921
exitmessage: You gather your belongings and head back towards the main room of
2022
the Inn.

_datafiles/world/default/rooms/frostfang/5.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
roomid: 5
22
zone: Frostfang
33
title: Cobblestone Way
4-
description: Almost at the end of Cobblestone Way, the stones paventment underfoot
4+
description: Almost at the end of Cobblestone Way, the stones pavement underfoot
55
is slick with ice, reflecting the soft glow of lanterns that line the path. The
66
trees have receded, replaced by statues of figures posed in moments of triumph,
77
each one covered in a layer of frost. The music is now a symphony, with flutes and

_datafiles/world/default/rooms/frostfang/61.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

_datafiles/world/default/templates/admincommands/ingame/roominfo.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{{ $room := .room }}{{ $zone := .zone }}
2-
<ansi fg="yellow-bold">RoomId:</ansi> <ansi fg="red">{{ $room.RoomId }}</ansi>{{ if eq $room.ZoneConfig.RoomId $room.RoomId }} <ansi fg="white">(This is the zone root)</ansi>{{ else }} <ansi fg="white">(Zone root is {{ $zone.RoomId }})</ansi>{{ end }}
2+
<ansi fg="yellow-bold">RoomId:</ansi> <ansi fg="red">{{ $room.RoomId }}</ansi>{{ if eq $zone.RoomId $room.RoomId }} <ansi fg="white">(This is the zone root)</ansi>{{ else }} <ansi fg="white">(Zone root is {{ $zone.RoomId }})</ansi>{{ end }}
33
<ansi fg="yellow-bold">Filepath:</ansi> <ansi fg="129">{{ $room.Filepath }}</ansi>
44
<ansi fg="yellow-bold">Zone:</ansi> <ansi fg="room-zone">{{ $room.Zone }}</ansi>
55
<ansi fg="yellow-bold">MapSymbol:</ansi> <ansi fg="map-{{ lowercase $room.MapLegend }}">{{ $room.GetMapSymbol }}</ansi>

0 commit comments

Comments
 (0)