{"slug":"animations/scenarios","category":"animations","title":"Scenarios","kind":"markdown","intro":"","body":"# SCENARIOS\n\n**Scenario** is a specially prepared container to run conditional animations. It is not animation itself, but only specifies which animation, when, where, with which prop model and under what conditions should be run. \n\n**ConditionalAnim** specifies which animation to run, if certain conditions are met. It is not animation itself, but only specifies which animation to trigger from [ingameanims.](https://github.com/femga/rdr3_discoveries/blob/master/animations/ingameanims/ingameanims_list.lua)\n\n**ConditionalAnim transition** specifies which animation to trigger to smoothly change one ConditionalAnim to another.\n\nUsually a scenario has several conditional anims. If the native function (TASK_START_SCENARIO_IN_PLACE_HASH, TASK_USE_SCENARIO_POINT, etc) does not directly specify which conditional anim to run, then a random one is launched (if the conditions are met). If the native function specifies conditional anim that does not meet the requirments, then a random acceptable one is played. If no conditional anim satisfies the requirments, then ped ignores scenario or can be stuck. \n\n\n\n### Simple structure of scenario\n\n\n- Scenario:\n  - Scenario Conditions\n  - ScenarioInfo Flags\n  - ConditionalAnim A\n    - ConditionalAnim Conditions \n    - ConditionalAnim Flags \n    - PropData\n    - Enter anim\n    - Base anim\n    - Exit anim\n    - Active looks anim\n    - Reactions anim\n    - Reactions enter anims\n    - Reactions exit anims\n  - ConditionalAnim B\n    - ConditionalAnim Conditions \n    - ConditionalAnim Flags \n    - PropData\n    - Enter anim\n    - Base anim\n    - Exit anim\n    - Active looks anim\n    - Reactions anim\n    - Reactions enter anims\n    - Reactions exit anims\n   - ConditionalAnim Transition A to B\n     - ConditionalAnimTransition Conditions \n     - ConditionalAnimTransition Flags\n     - TransitionFromConditionalAnim List\n     - TransitionToConditionalAnim List\n     - Transition Clips\n   - ConditionalAnim Transition B to A\n     - ConditionalAnimTransition Conditions \n     - ConditionalAnimTransition Flags\n     - TransitionFromConditionalAnim List\n     - TransitionToConditionalAnim List\n     - Transition Clips\n\n\n## Anim variations\n\nConditional anim contains various types of clips.\n\n***Enter*** anim contains clips for animation start.\n\n***Base*** anim contains clips for main part of animation.\n\n***Exit*** anim contains clips for animation ending.\n\n***Active looks*** anims  contains clips for moments when the NPC's attention is attracted by player walking by.\n\n***Reaction enter*** anims  contains clips for moments when ped begin to react to an interesting or threatening events.\n\n***Reaction exit*** anims  contains clips for moments when ped ends to react to an interesting or threatening events and return to base conditional anim.\n\n\n## Requirements\n\n\nEvery scenario and conditional anims have special requirements to run: ***conditions*** and some ***flags***. For scenario requirements you need to check the game files with OPENIV:\n\n - _common_0/data/ai/scenarios/_ \n\nFor conditional anims requirements:\n\n - _common_0/data/ai/scenarios/conditionalanims/_ \n\n\n\n## Requirements: conditions\n\n\n***Conditions*** are special game states that must be met in order to activate a scenario or conditional anims. It can be requirements to ped model, ped gender, current ingame time, activated ped commands, etc. \n\n```\n[file /common_0/data/ai/scenarios/conditionalanims/amb_rest_ca.meta]:\nFor example, scenario WORLD_HUMAN_DRUNK_PASSED_OUT_FLOOR have conditional anim WORLD_HUMAN_DRUNK_PASSED_OUT_FLOOR_MALE_A, \nthat have special condition CAIConditionIsMale to run. As a result, female peds cannot use this conditional anim.\n```\n\n\n\nIt may also be required that the special condition ***does not*** exist. In this case, the condition is enclosed in special tags _CAIConditionNot_. \n\n```\n[file /common_0/data/ai/scenarios/conditionalanims/amb_rest_ca.meta]:\nFor example, scenario PROP_HUMAN_SEAT_CHAIR_SAD have conditional anim PROP_HUMAN_SEAT_CHAIR_SAD_FEMALE_A, \nthat have special requirement to NOT have condition CAIConditionIsMale . As a result, male peds cannot use this \nconditional anim.\n```\n\nScenarios and conditional anims can have multiple conditions at once or requirements to not have multiple conditions. \n\n```\n[file /common_0/data/ai/scenarios/conditionalanims/amb_rest_ca.meta]:\nFor example, scenario WORLD_HUMAN_BOTTLE_PICKUP_BOX_TABLE_BEER have conditional anim \nWORLD_HUMAN_BOTTLE_PICKUP_TABLE_BOX_MALE_B, that have special condition CAIConditionIsMale and requirements to NOT have \nconditions CAIConditionIsPlayer and CAIConditionIsMetaPedType MPT_TEEN. As a result, all player peds, all female peds \n(not only player peds) and male teen peds cant use this conditional anim.\n```\n\n\nScenarios and conditional anims can have multiple conditions enclosed in special tags _CAIConditionOr_ . In this case, only some conditions are sufficient. \n\n\n\n## Requirements: conditions: Ped Command Hash\n\n\n**Ped Command Hash** is special command, that can be activated to change conditional anim variations or trigger transitions between conditional anims. Check ped command hashes for transitions [here](https://github.com/femga/rdr3_discoveries/blob/master/animations/scenarios/ped_commands_for_transitions_between_anims.lua) and ped command hashes for selecting anim variations [here.](https://github.com/femga/rdr3_discoveries/blob/master/animations/scenarios/ped_commands_for_selecting_anim_variations.lua)\n\n```lua\n\nCitizen.CreateThread(function()\n\twhile true do\n \t\tCitizen.Wait(0)\n \t\tif Citizen.InvokeNative(0x91AEF906BCA88877,0, 0x17BEC168) then   -- pressed E\n\t\t\t-- TASK_START_SCENARIO_IN_PLACE_HASH with conditional anim WORLD_PLAYER_MOONSHINE_CUSTOMER_SOBER_MALE_A. Works for male player peds:\n\t\t\tCitizen.InvokeNative(0x524B54361229154F, PlayerPedId(), GetHashKey(\"WORLD_PLAYER_MOONSHINE_CUSTOMER\"), 0, 1, GetHashKey(\"WORLD_PLAYER_MOONSHINE_CUSTOMER_SOBER_MALE_A\"), -1.0, 0)\n\t\tend\n\t\tif Citizen.InvokeNative(0x91AEF906BCA88877,0, 0x956C2A0E) then   -- pressed R\n\t\t\tlocal ped_command_hash=GetHashKey(\"ORDER_DRINK\")\n\t\t\tlocal ped_command_hash_activation_duration=5.0   -- 5 seconds\n\t\t\t-- _ACTIVATE_PED_COMMAND_HASH (as result, ped plays animation for ORDER_DRINK while ped command hash is active)\n\t\t\tCitizen.InvokeNative(0xD65FDC686A031C83, PlayerPedId(), ped_command_hash, ped_command_hash_activation_duration) \n\t\t\t -- _FORCE_SCENARIO_TRANSITION:\n\t\t\tCitizen.InvokeNative(0x6D07B371E9439019, PlayerPedId() ) \n\t\tend\n\tend\nend)\n\n\n```\n\n\n## Requirements: flags\n\n\nSome scenario or conditional anims flags can prevent scenario using. \n\n```\n[file /common_0/data/ai/scenarios/animals_mammal.meta]:\nFor example, scenario WORLD_ANIMAL_HORSE_SLEEPING have flag \"ScenarioExitNearPlayer\" and can be played if player is \nfar enough.\n```\n","tables":[],"sourceUrl":"https://github.com/femga/rdr3_discoveries/tree/477aaaccadb7f0c042286611d9939009636cff12/animations/scenarios","rows":[]}