Skip to content

Commit a005dbc

Browse files
authored
Improving scripting, scripts, documentation, follow command, adding a special item (#379)
# Description This adds/changes some scripting functions, improves some scripts, and adds a magic flute, used to charm rats at night to follow the player. ## Changes - `follow` command now has a default time it lasts. Longer periods can be specified. - Implemented a magic flute which when played at night, causes rats to follow the player. - Added some new scripting functions and modified existing ones - Return Actor objects instead of userId/mob instance id - Updated/improved some scripts to use changes.
1 parent 71609e4 commit a005dbc

File tree

33 files changed

+402
-416
lines changed

33 files changed

+402
-416
lines changed

_datafiles/guides/building/scripting/FUNCTIONS_ACTORS.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ ActorObjects are the basic object that represents Users and NPCs
55
- [ActorObject](#actorobject)
66
- [ActorNames(actors \[\]ActorObject) string ](#actornamesactors-actorobject-string-)
77
- [GetUser(userId int) ActorObject ](#getuseruserid-int-actorobject-)
8-
- [GetMob(mobInstanceId int) ActorObject ](#getmobmobinstanceid-int-actorobject-)
8+
- [GetMob(mobInstanceId int \[,createIfMissing bool\]) ActorObject ](#getmobmobinstanceid-int-createifmissing-bool-actorobject-)
99
- [ActorObject.UserId() int](#actorobjectuserid-int)
1010
- [ActorObject.InstanceId() int](#actorobjectinstanceid-int)
1111
- [ActorObject.MobTypeId() int](#actorobjectmobtypeid-int)
@@ -104,12 +104,13 @@ Retrieves a ActorObject for a given userId.
104104
| --- | --- |
105105
| userId | The target user id to get. |
106106

107-
## [GetMob(mobInstanceId int) ActorObject ](/internal/scripting/actor_func.go)
107+
## [GetMob(mobInstanceId int [,createIfMissing bool]) ActorObject ](/internal/scripting/actor_func.go)
108108
Retrieves a ActorObject for a given mobInstanceId.
109109

110110
| Argument | Explanation |
111111
| --- | --- |
112112
| mobInstanceId | The target mobInstanceId to get. |
113+
| createIfMissing | If true and mob isn't found, the mob will be created and returned. |
113114

114115
## [ActorObject.UserId() int](/internal/scripting/actor_func.go)
115116
Returns the userId of the ActorObject.˚

_datafiles/guides/building/scripting/FUNCTIONS_ROOMS.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
- [RoomObject.GetItems() \[\]ItemObject](#roomobjectgetitems-itemobject)
1414
- [RoomObject.DestroyItem(itm ScriptItem) ](#roomobjectdestroyitemitm-scriptitem-)
1515
- [RoomObject.SpawnItem(itemId int, inStash bool) \[\]ItemObject](#roomobjectspawnitemitemid-int-instash-bool-itemobject)
16-
- [RoomObject.GetMobs() \[\]int](#roomobjectgetmobs-int)
17-
- [RoomObject.GetPlayers() \[\]int](#roomobjectgetplayers-int)
16+
- [RoomObject.GetMob(mobId int) Actor](#roomobjectgetmobmobid-int-actor)
17+
- [RoomObject.GetMobs(\[mobId int\]) \[\]Actor](#roomobjectgetmobsmobid-int-actor)
18+
- [RoomObject.GetPlayers() \[\]Actor](#roomobjectgetplayers-actor)
19+
- [RoomObject.GetAllActors() \[\]Actor](#roomobjectgetallactors-actor)
1820
- [RoomObject.GetContainers() \[\]string](#roomobjectgetcontainers-string)
1921
- [RoomObject.GetExits() \[\]object](#roomobjectgetexits-object)
2022
- [GetMap(mapRoomId int, mapZoom, mapHeight int, mapWidth int, mapName string, showSecrets bool \[,mapMarker string, mapMarker string\]) string](#getmapmaproomid-int-mapzoom-mapheight-int-mapwidth-int-mapname-string-showsecrets-bool-mapmarker-string-mapmarker-string-string)
@@ -113,11 +115,26 @@ Spawns an item in the room.
113115
| itemId | ItemId to spawn. |
114116
| inStash | If true, spawns stashed instead of visible. |
115117

116-
## [RoomObject.GetMobs() []int](/internal/scripting/room_func.go)
117-
Returns an array of `mobInstanceIds` in the room.
118118

119-
## [RoomObject.GetPlayers() []int](/internal/scripting/room_func.go)
120-
Returns an array of `userIds` in the room.
119+
## [RoomObject.GetMob(mobId int) Actor](/internal/scripting/room_func.go)
120+
Returns the first mob that matches the provided MobId type (Note: NOT MOB INSTANCE ID!)
121+
122+
| Argument | Explanation |
123+
| --- | --- |
124+
| mobId | MobId to match. |
125+
126+
## [RoomObject.GetMobs([mobId int]) []Actor](/internal/scripting/room_func.go)
127+
Returns an array of mob `Actor`s in the room.
128+
129+
| Argument | Explanation |
130+
| --- | --- |
131+
| mobId (optional) | Only get mobs of the provided MobId type. (Note: NOT MOB INSTANCE ID!) |
132+
133+
## [RoomObject.GetPlayers() []Actor](/internal/scripting/room_func.go)
134+
Returns an array of player `Actor`s in the room.
135+
136+
## [RoomObject.GetAllActors() []Actor](/internal/scripting/room_func.go)
137+
Returns an array of all `Actor`s in the room.
121138

122139
## [RoomObject.GetContainers() []string](/internal/scripting/room_func.go)
123140
Gets a list of container names in the room.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
2+
const MUSIC_DESCRIPTIONS = [
3+
"a silvery trill dances on the breeze. ♪♪ ♫",
4+
"a cascade of notes unravels into open air. ♫ ♪♪",
5+
"a soft melody fills the air. ♪♫ ♪",
6+
];
7+
8+
const RAT_MOB_IDS = [1, 12];
9+
10+
function onCommand_play(user, item, room) {
11+
12+
var randomPhrase = MUSIC_DESCRIPTIONS[UtilDiceRoll(1, MUSIC_DESCRIPTIONS.length)-1];
13+
14+
if ( UtilIsDay() ) {
15+
SendUserMessage(user.UserId(), "You attempt to play the flute, but only succeed in producing a shrill noise");
16+
SendRoomMessage(room.RoomId(), user.GetCharacterName(true)+" attempts to play their <ansi fg=\"item\">"+item.Name(true)+"</ansi> and a horrible, shrill sound fills the air.", user.UserId());
17+
18+
return true;
19+
}
20+
21+
SendUserMessage(user.UserId(), "You surprisingly find yourself able to play the flute effortlessly, and "+randomPhrase);
22+
SendRoomMessage(room.RoomId(), user.GetCharacterName(true)+" plays their <ansi fg=\"item\">"+item.Name(true)+"</ansi> and "+randomPhrase, user.UserId());
23+
24+
// NOTE: This is not charming the mob. This is a special pacify and force follow.
25+
// The rats will not follow the behavior of charmed mobs.
26+
for( var i in RAT_MOB_IDS ) {
27+
var ratMobs = room.GetMobs(RAT_MOB_IDS[i]);
28+
for ( var j in ratMobs ) {
29+
ratMobs[j].Command(`break`); // Break off any combat
30+
ratMobs[j].Command(`follow ` + user.ShorthandId() + ` sunrise`); // follow whoever played the flute until sunrise
31+
ratMobs[j].ChangeAlignment(user.GetAlignment()); // Set alignment to the flute player
32+
}
33+
}
34+
35+
36+
return true;
37+
}
38+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
itemid: 101
2+
value: 10000
3+
hands: 0
4+
name: arcane flute
5+
namesimple: arcane flute
6+
description: A flute with faintly glowing markings all along it. Maybe you can <ansi fg="command">play</ansi> it.
7+
type: object
8+
subtype: generic

_datafiles/world/default/mobs/frostfang/10-ivar_froststeel.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ hostile: false
55
groups:
66
- frostfang-npc
77
idlecommands:
8-
- 'say type `list` to see my wares'
8+
- 'say type <ansi fg="command">list</ansi> to see my wares'
99
- 'say If you''re looking to sell something, I may be interested... as long as it''s not too special or unique'
1010
- emote is counting his coins
1111
- emote watches you carefully

_datafiles/world/default/mobs/frostfang/11-brynja_snowdeal.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ hostile: false
55
groups:
66
- frostfang-npc
77
idlecommands:
8-
- 'say type `list` to see my wares'
8+
- 'say type <ansi fg="command">list</ansi> to see my wares'
99
- 'say If you''re looking to sell something, I may be interested... as long as it''s not too special or unique'
1010
- emote shuffles some papers
1111
- emote is counting her coins

_datafiles/world/default/mobs/frostfang/5-armorer.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ hostile: false
55
groups:
66
- frostfang-npc
77
idlecommands:
8-
- 'say type `list` to see my wares'
8+
- 'say type <ansi fg="command">list</ansi> to see my wares'
99
- 'say If you''re looking to sell something, I may be interested... as long as it''s not too special or unique'
1010
- emote shuffles some papers
1111
- emote is counting his coins

_datafiles/world/default/mobs/frostfang/50-moilyn_the_wizard.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ hostile: false
55
groups:
66
- frostfang-npc
77
idlecommands:
8-
- 'say type `list` to see what magical objects I have for sale'
8+
- 'say type <ansi fg="command">list</ansi> to see what magical objects I have for sale'
99
activitylevel: 10
1010
character:
1111
name: moilyn the wizard

_datafiles/world/default/mobs/mystarion/46-herbalist.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ groups:
77
- mystarion-npc
88
activitylevel: 40
99
idlecommands:
10-
- say type `list` to see my wares
11-
- say If you're looking to sell something, I may be interested... as long as it's
12-
not too special or unique
10+
- say type <ansi fg="command">list</ansi> to see my wares
11+
- say If you're looking to sell something, I may be interested... as long as it's not too special or unique
1312
- emote is watching you
1413
combatcommands:
1514
- 'say How dare you attack the citizens of Mystarion! We do not forget!'

_datafiles/world/default/mobs/mystarion/47-brewer.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ groups:
77
- mystarion-npc
88
activitylevel: 40
99
idlecommands:
10-
- say type `list` to see my wares
11-
- say If you're looking to sell something, I may be interested... as long as it's
12-
not too special or unique
10+
- say type <ansi fg="command">list</ansi> to see my wares
11+
- say If you're looking to sell something, I may be interested... as long as it's not too special or unique
1312
- emote is watching you
1413
combatcommands:
1514
- 'say How dare you attack the citizens of Mystarion! We do not forget!'

0 commit comments

Comments
 (0)