Shaking Camera Script
From Mount&Blade Modding Wiki
Revision as of 11:10, 1 August 2013 by 180.215.223.105 (Talk)
Contents |
[edit] Description
This is a script written for both Warband, SP & MP. It makes the camera shake (change rotation along x/z direction randomly) every 0.01 second and generates an effect similar to explosions, earthquakes etc...
[edit] Knowledge/Tools Required
- Python ModuleSystem
- Understanding of adding triggers into Module_mission_templates
[edit] Script
[edit] Addition to Module_scripts
Place the below anywhere in module_scripts,
("shake_camera", [ (store_script_param_1,":n"), (store_script_param,":loc_shake_x",2), (store_script_param,":loc_shake_z",3), (assign, "$shake", ":n"), (assign, "$shake_x", ":loc_shake_x"), (assign, "$shake_z", ":loc_shake_z"), ]),
[edit] Addition to Module_mission_templates
Place the below trigger in the required mission_templates,
### Camera Shake ### # Part 1 - rotate the camera a random value from 0 to shake_x/z (0.01, 0, 0, [],[ # Changes angle every 0.01 second, value of 0.01 can be changed # for different effects (try_begin), (ge, "$shake", 1), (store_mul,":neg_shake_x",-1,"$shake_x"), (store_mul,":neg_shake_z",-1,"$shake_z"), (store_random_in_range,":drx",":neg_shake_x","$shake_x"), (store_random_in_range,":drz",":neg_shake_z","$shake_z"), (assign, "$cam_drx", ":drx"), (assign, "$cam_drz", ":drz"), (try_begin), (eq, "$shake", 1), (mission_cam_set_mode, 0), (try_end), (val_sub, "$shake", 1), (try_end), ]), # Part 2 - make camera follow changed rotation every frame (0, 0, 0, [],[ (try_begin), (gt, "$shake", 0), (mission_cam_set_mode, 1), (get_player_agent_no, ":p_agent"), (agent_get_look_position, pos0, ":p_agent"), (agent_get_horse,":horse",":p_agent"), (try_begin), (eq, ":horse", -1), (position_move_z,pos0,208,1), (else_try), (position_move_z,pos0,287,1), (try_end), (position_move_y,pos0,-130), (position_rotate_x, pos0, "$cam_drx"), (position_rotate_z, pos0, "$cam_drz"), (mission_cam_set_position, pos0), (try_end), ]),
[edit] Trigger the camera script
Add the following line where appropriate, i.e. after grenade explodes etc...
(call_script, "script_shake_camera", 100, 5, 12), # no. of shakes, max rotate x, max rotate z
[edit] Credits
By Sonkidd.
Open source; use and edit at will. Credits given where appropriate would be appreciated, but not necessary.