Skip to content

Commit ae41a26

Browse files
committed
auto_animate for attached
1 parent 8176bd9 commit ae41a26

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

scripts/dmodels_animating.dsc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ dmodels_catmullrom_proc:
171171
dmodels_attach_to:
172172
type: task
173173
debug: false
174-
definitions: root_entity|target
174+
definitions: root_entity|target|auto_animate
175175
script:
176176
- if !<[root_entity].is_truthy> || !<[root_entity].has_flag[dmodel_model_id]||false>:
177177
- debug error "[DModels] invalid attach_to root_entity <[root_entity]>"
@@ -180,6 +180,7 @@ dmodels_attach_to:
180180
- debug error "[DModels] invalid attach_to target <[target]>"
181181
- stop
182182
- flag <[root_entity]> dmodels_attached_to:<[target]>
183+
- flag <[root_entity]> dmodels_attach_auto_animate:<[auto_animate]||false>
183184
- flag server dmodels_attached.<[root_entity].uuid>:<[root_entity]>
184185

185186
dmodels_animator_world:
@@ -189,7 +190,20 @@ dmodels_animator_world:
189190
on tick server_flagged:dmodels_attached priority:-20:
190191
- foreach <server.flag[dmodels_attached]> as:root:
191192
- if <[root].is_spawned||false> && <[root].flag[dmodels_attached_to].is_spawned||false>:
192-
- teleport <[root]> <[root].flag[dmodels_attached_to].location>
193+
- define target <[root].flag[dmodels_attached_to]>
194+
- teleport <[root]> <[target].location>
195+
- if <[root].flag[dmodels_attach_auto_animate]> && !<[root].flag[dmodels_temp_alt_anim].is_truthy||false>:
196+
- define preferred idle
197+
- if <[target].is_sneaking||false>:
198+
- define preferred crouching_idle
199+
- if <[target].velocity.vector_length> > 0.1:
200+
- define preferred running
201+
- if <[target].velocity.vector_length> > 1.2:
202+
- define preferred sprinting
203+
- if <[target].velocity.y> > 0.1:
204+
- define preferred jump
205+
- if <[root].flag[dmodels_animation_id]||none> != <[preferred]> && <server.has_flag[dmodels_data.animations_<[root].flag[dmodel_model_id]>.<[preferred]>]||null>:
206+
- run dmodels_animate def.root_entity:<[root]> def.animation:<[preferred]>
193207
- if !<[root].has_flag[dmodels_animation_id]>:
194208
- run dmodels_reset_model_position def.root_entity:<[root]>
195209
on tick server_flagged:dmodels_anim_active priority:-10:

scripts/dmodels_citizens.dsc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ dmodels_npc_spawn:
3232
- stop
3333
- adjust <npc> hide_from_players
3434
- flag <npc> dmodels_root:<[root]>
35-
- run dmodels_attach_to def.root_entity:<[root]> def.target:<npc>
35+
- run dmodels_attach_to def.root_entity:<[root]> def.target:<npc> def.auto_animate:true
3636

3737
dmodels_npc_despawn:
3838
type: task

scripts/dmodels_main.dsc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
# Installation:
2020
# 1: Edit your "plugins/Denizen/config.yml", find "File:", and "Allow read" and "Allow write" inside, and set them both to "true", then use "/denizen reload config"
2121
# 2: Copy the "scripts/dmodels" folder to your "plugins/Denizen/scripts" and "/ex reload"
22+
# 2.5: NOTE: If you do not use the plugin Citizens, you can exclude the "dmodels_citizens" file.
2223
# 3: Note that you must know the basics of operating resource packs - the pack content will be generated for you, but you must know how to install a pack on your client and/or distribute it to players as appropriate
2324
# 4: Take a look at the config settings in the bottom of this file in case you want to change any of them.
2425
#
@@ -123,6 +124,7 @@
123124
# Input definitions:
124125
# root_entity: The root entity gotten from 'dmodels_spawn_model'.
125126
# target: The entity to be attached to.
127+
# auto_animate: (OPTIONAL) set to 'true' to indicate the model should automatically apply animations based on the entity it's attached to. See 'core animations' list below.
126128
# Flags:
127129
# Every entity spawned by DModels has the flag 'dmodel_root', that refers up to the root entity.
128130
# The root entity has the following flags:
@@ -131,8 +133,22 @@
131133
# 'dmodel_anim_part.<ID_HERE>': a mapping of outline IDs to the part entity spawned for them.
132134
# 'dmodels_animation_id': only if the model is animating automatically, contains the animation ID.
133135
# 'dmodels_anim_time': only if the model is animating automatically, contains the progress through the current animation as a number representing time.
136+
# 'dmodels_attached_to': the entity this model is attached to, if any.
137+
# 'dmodels_temp_alt_anim': if set to a truthy value, will tell the model to not play any auto-animations (so other scripts can indicate they need to override the default)
134138
# Additional flags are present on both the root and on parts, but are not considered API - use at your own risk.
135139
#
140+
# #########
141+
#
142+
# Core Animations:
143+
# Some systems within DModels look for certain core animations to exist, and will use them when relevant.
144+
# For example, the with the 'dmodels_attach_to' task, with the 'auto_animate' flag enabled (or the 'npcmodel' command which enables it by default), will apply animations to match the attached entity.
145+
# List:
146+
# 'idle': default/no activity idle animation.
147+
# 'crouching_idle': default/no activity idle animation, while crouching (sneaking).
148+
# 'running': the animation for moving at normal speed.
149+
# 'sprinting': the animation for moving very fast.
150+
# 'jump': the animation for jumping in place.
151+
#
136152
################################################
137153

138154
dmodels_config:

0 commit comments

Comments
 (0)