Skip to content

Commit 8176bd9

Browse files
committed
Citizens bridge and 'npcmodel' command
1 parent a266c63 commit 8176bd9

File tree

3 files changed

+84
-2
lines changed

3 files changed

+84
-2
lines changed

scripts/dmodels_citizens.dsc

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
###########################
2+
# This file is part of dModels / Denizen Models.
3+
# Refer to the header of "dmodels_main.dsc" for more information.
4+
# ------
5+
# This file may be excluded from servers that do not use Citizens.
6+
###########################
7+
8+
9+
dmodels_npc_assignment:
10+
type: assignment
11+
actions:
12+
on assignment:
13+
- if <npc.is_spawned>:
14+
- run dmodels_npc_spawn
15+
on remove assignment:
16+
- run dmodels_npc_despawn
17+
on spawn:
18+
- run dmodels_npc_spawn
19+
on despawn:
20+
- run dmodels_npc_despawn
21+
22+
dmodels_npc_spawn:
23+
type: task
24+
debug: false
25+
script:
26+
- if !<npc.has_flag[dmodels_model]>:
27+
- stop
28+
- run dmodels_spawn_model def.model_name:<npc.flag[dmodels_model]> def.location:<npc.location> save:model
29+
- define root <entry[model].created_queue.determination.first||null>
30+
- if !<[root].is_truthy>:
31+
- debug error "[DModels] NPC <npc.id> tried to use model <npc.flag[dmodels_model]> but spawning failed."
32+
- stop
33+
- adjust <npc> hide_from_players
34+
- flag <npc> dmodels_root:<[root]>
35+
- run dmodels_attach_to def.root_entity:<[root]> def.target:<npc>
36+
37+
dmodels_npc_despawn:
38+
type: task
39+
debug: false
40+
script:
41+
- if !<npc.has_flag[dmodels_root]>:
42+
- stop
43+
- adjust <npc> show_to_players
44+
- run dmodels_delete def.root_entity:<npc.flag[dmodels_root]>
45+
- flag <npc> dmodels_root:!

scripts/dmodels_command.dsc

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ dmodels_command:
1414
type: command
1515
debug: false
1616
name: dmodels
17-
usage: /dmodels [load/loadall/spawn/remove/animate/stopanimate]
17+
usage: /dmodels [load/loadall/spawn/remove/animate/stopanimate/npcmodel]
1818
description: Manages Denizen Models.
1919
permission: dmodels.help
2020
tab completions:
@@ -116,6 +116,38 @@ dmodels_command:
116116
- stop
117117
- run dmodels_end_animation def.root_entity:<[target]>
118118
- narrate "<&[base]>Animation stopped."
119+
- case npcmodel:
120+
- if !<player.has_permission[dmodels.npcmodel]>:
121+
- narrate "<&[error]>You do not have permission for that."
122+
- stop
123+
- if !<player.selected_npc.exists>:
124+
- narrate "<&[error]>You do not have any NPC selected."
125+
- stop
126+
- adjust <queue> linked_npc:<player.selected_npc>
127+
- if !<context.args.get[2].exists>:
128+
- narrate "<&[warning]>/dmodels npcmodel [model] <&[error]>- sets an NPC to render as a given model (must be loaded). Use 'none' to remove the model."
129+
- stop
130+
- define model <context.args.get[2]>
131+
- if !<[model].to_lowercase.matches_character_set[<script[dmodels_cmd_data].data_key[valid_chars]>]>:
132+
- narrate "<&[error]>Given model name has an invalid format."
133+
- stop
134+
- if <[model]> == none:
135+
- flag <npc> dmodels_model:!
136+
- if <npc.scripts.parse[name].contains[dmodels_npc_assignment]||false>:
137+
- run dmodels_npc_despawn
138+
- assignment remove script:dmodels_npc_assignment
139+
- narrate "<&[base]>NPC <npc.id.custom_color[emphasis]> (<npc.name><&[base]>) will now render as a normal NPC."
140+
- stop
141+
- if !<server.has_flag[dmodels_data.model_<[model]>]>:
142+
- narrate "<&[error]>No such model exists, or that model has never been loaded."
143+
- stop
144+
- flag <npc> dmodels_model:<[model]>
145+
- if !<npc.scripts.parse[name].contains[dmodels_npc_assignment]||false>:
146+
- assignment add script:dmodels_npc_assignment
147+
- else:
148+
- run dmodels_npc_despawn
149+
- run dmodels_npc_spawn
150+
- narrate "<&[base]>NPC <npc.id.custom_color[emphasis]> (<npc.name><&[base]>) will now render as model <[model].custom_color[emphasis]>"
119151
# help
120152
- default:
121153
- if <player.has_permission[dmodels.load]||true>:
@@ -130,6 +162,8 @@ dmodels_command:
130162
- narrate "<&[warning]>/dmodels animate [animation] <&[error]>- causes the closest real-spawned model to start playing the given animation"
131163
- if <player.has_permission[dmodels.stopanimate]||true>:
132164
- narrate "<&[warning]>/dmodels stopanimate <&[error]>- causes the closest real-spawned model to stop animating"
165+
- if <player.has_permission[dmodels.npcmodel]||true>:
166+
- narrate "<&[warning]>/dmodels npcmodel [model] <&[error]>- sets an NPC to render as a given model (must be loaded). Use 'none' to remove the model."
133167
- narrate "<&[warning]>/dmodels help <&[error]>- this help output"
134168

135169
dmodels_get_target:
@@ -146,7 +180,7 @@ dmodels_tab_1:
146180
debug: false
147181
script:
148182
- define list <list>
149-
- foreach load|loadall|spawn|remove|animate|stopanimate|help as:key:
183+
- foreach load|loadall|spawn|remove|animate|stopanimate|npcmodel|help as:key:
150184
- if <player.has_permission[<[key]>]||true>:
151185
- define list:->:<[key]>
152186
- determine <[list]>
@@ -167,6 +201,8 @@ dmodels_tab_2:
167201
- determine <util.list_files[data/dmodels/<[path]>].parse[before_last[.bbmodel]]||<list>>
168202
- else if <[args].first> == spawn && <player.has_permission[dmodels.spawn]||true>:
169203
- determine <server.flag[dmodels_data].keys.filter[starts_with[model_]].parse[after[model_]]>
204+
- else if <[args].first> == npcmodel && <player.has_permission[dmodels.npcmodel]||true>:
205+
- determine <server.flag[dmodels_data].keys.filter[starts_with[model_]].parse[after[model_]].include[none]>
170206
- else if <[args].first> == animate && <player.has_permission[dmodels.animate]||true>:
171207
- define target <player.location.find_entities[dmodel_part_stand].within[10].filter[has_flag[dmodel_model_id]].first||null>
172208
- if !<[target].is_truthy>:

scripts/dmodels_main.dsc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
# /dmodels remove - "dmodels.remove" - Removes whichever real-spawned model is closest to your location
5050
# /dmodels animate [animation] - "dmodels.animate" - Causes your nearest real-spawned model to play the specified animation
5151
# /dmodels stopanimate - "dmodels.stopanimate" - Causes your nearest real-spawned model to stop animating
52+
# /dmodels npcmodel [model] - "dmodels.npcmodel" - sets an NPC to render as a given model (must be loaded). Use 'none' to remove the model.
5253
#
5354
# #########
5455
#

0 commit comments

Comments
 (0)