Scripting activity to use custom Avatars
- Last UpdatedDec 06, 2023
- 2 minute read
After completing the custom avatar pre-requirements, the next step is to configure the project so that you can properly use the custom avatar feature.
Scripting
Add scripting that covers the following items for each avatar involved in the project:
-
Include MWX files: Include all needed models.
-
Patching Human node: Define the skin meshes and avatar animations.
-
Visibility state for Avatar submeshes: This setting must be within a command; it cannot be part of human patching.
Example code
This is sample of code in the form of a template.
<deftemplate name="AVATARCUSTOM" >
<ifndef name="%avatarType%_loaded">
<define name="%avatarType%_loaded" type="sbool" value="true" />
<Mwx name="mwx_avatar_%avatarType%" file="user\avatars\avatar_%avatarType%.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_walk" file="user\avatars\avatar_anim_%avatarType%_walk.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_run" file="user\avatars\avatar_anim_%avatarType%_run.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_idle" file="user\avatars\avatar_anim_%avatarType%_idle.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_crouch" file="user\avatars\avatar_anim_%avatarType%_crouch.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_stairs_climb" file="user\avatars\avatar_anim_%avatarType%_stairs_climb.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_stairs_up" file="user\avatars\avatar_anim_%avatarType%_stairs_up.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_stairs_down" file="user\avatars\avatar_anim_%avatarType%_stairs_down.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_wave" file="user\avatars\avatar_anim_%avatarType%_wave.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_point" file="user\avatars\avatar_anim_%avatarType%_point.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_come_here" file="user\avatars\avatar_anim_%avatarType%_come_here.MWX"/>
<Mwx name="mwx_avatar_anim_%avatarType%_conversation" file="user\avatars\avatar_anim_%avatarType%_conversation.MWX"/>
<patch name="%avatarName%_human" skinMesh="%avatarType%" castShadows="true" animations="{anim_wait=anim_%avatarType%_idle}{anim_walk=anim_%avatarType%_walk}{anim_run=anim_%avatarType%_run}{anim_crouch=anim_%avatarType%_crouch}{anim_climb=anim_%avatarType%_stairs_climb}{anim_stairsup=anim_%avatarType%_stairs_up}{anim_stairsdown=anim_%avatarType%_stairs_down}{wave=anim_%avatarType%_wave}{point=anim_%avatarType%_point}{come_here=anim_%avatarType%_come_here}{conversation=anim_%avatarType%_conversation}"/>
<patch name="%avatarName%" visible="true"/>
<route from="reset_human_submeshes.execute" to="custom_reset_human_submeshes.execute"/>
<Command name="custom_reset_human_submeshes">
<setfield name="%avatarName%_human.submesh_Arms_visible" value="false" />
<setfield name="%avatarName%_human.submesh_Body_visible" value="false" />
<setfield name="%avatarName%_human.submesh_ChemicalSuit_visible" value="false" />
<setfield name="%avatarName%_human.submesh_Eyelashes_visible" value="true" />
<setfield name="%avatarName%_human.submesh_EyeMask_visible" value="false" />
<setfield name="%avatarName%_human.submesh_Eyes_visible" value="true" />
<setfield name="%avatarName%_human.submesh_FaceShield_visible" value="false" />
<setfield name="%avatarName%_human.submesh_FaceShieldGlass_visible" value="false" />
<setfield name="%avatarName%_human.submesh_GasMask_visible" value="false" />
<setfield name="%avatarName%_human.submesh_Gloves_visible" value="false" />
<setfield name="%avatarName%_human.submesh_H2SDetector_visible" value="false" />
<setfield name="%avatarName%_human.submesh_Hair_visible" value="true" />
<setfield name="%avatarName%_human.submesh_Hands_visible" value="true" />
<setfield name="%avatarName%_human.submesh_Hat_visible" value="false" />
<setfield name="%avatarName%_human.submesh_Head_visible" value="true" />
<setfield name="%avatarName%_human.submesh_HearingProtection_visible" value="false" />
<setfield name="%avatarName%_human.submesh_InfraredThermometer_visible" value="false" />
<setfield name="%avatarName%_human.submesh_InfraredThermometerUsed_visible" value="false" />
<setfield name="%avatarName%_human.submesh_Mask_visible" value="false" />
<setfield name="%avatarName%_human.submesh_Pant_visible" value="true" />
<setfield name="%avatarName%_human.submesh_Radio_visible" value="false" />
<setfield name="%avatarName%_human.submesh_RubberApron_visible" value="false" />
<setfield name="%avatarName%_human.submesh_RubberBoots_visible" value="false" />
<setfield name="%avatarName%_human.submesh_RubberGloves_visible" value="false" />
<setfield name="%avatarName%_human.submesh_SafetyGlasses_visible" value="false" />
<setfield name="%avatarName%_human.submesh_Shirt_visible" value="true" />
<setfield name="%avatarName%_human.submesh_Shoes_visible" value="true" />
<setfield name="%avatarName%_human.submesh_VaporRespirator_visible" value="false" />
</Command>
</ifndef>
</deftemplate>
<usetemplate name="AVATARCUSTOM" avatarName="player0" avatarType="def4_indiM" />