Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //=====================================================
- // Input, a script to capture key and mouse input
- //
- // This script will catch and store player input
- // from the keyboard and mouse in a struct array.
- // Keys and buttons are records as bool states,
- // while mouse clicks and movement are kept as
- // int and fixed values for the UI and World
- // respectively.
- //
- // To get the state of the X key, you would use:
- // Input[p].key.state[c_keyX]
- // To get the point of the cursor, you could:
- // Point(Input[p].mouse.x,Input[p].mouse.y)
- //
- // The user may configure the DETECT bool
- // constants to set which triggers will be
- // created on initialization of the script.
- //=====================================================
- include "TriggerLibs/natives"
- // CONFIGURABLE CONSTANTS
- static const bool DETECT_KEYDOWN = true;
- static const bool DETECT_KEYUP = true;
- static const bool DETECT_BUTTONDOWN = true;
- static const bool DETECT_BUTTONUP = true;
- static const bool DETECT_MOVEMENT = true;
- static const int INPUT_BUTTONS = 6;
- static const int INPUT_KEYS = 99;
- // STRUCTS
- struct Button { bool[INPUT_BUTTONS] state; };
- struct Key { bool[INPUT_KEYS] state; };
- struct Mouse
- {
- int uix;
- int uiy;
- fixed x;
- fixed y;
- fixed z;
- };
- struct InputData
- {
- Key key;
- Button button;
- Mouse mouse;
- };
- // GLOBALS
- InputData[c_maxPlayers] Input;
- // FUNCTIONS
- bool Input_KeyOn (bool testConds, bool runActions)
- {
- Input[EventPlayer()].key.state[EventKeyPressed()] = true;
- return true;
- }
- bool Input_KeyOff (bool testConds, bool runActions)
- {
- Input[EventPlayer()].key.state[EventKeyPressed()] = false;
- return true;
- }
- bool Input_ButtonOn (bool testConds, bool runActions)
- {
- int p = EventPlayer();
- Input[p].button.state[EventMouseClickedButton()] = true;
- Input[p].mouse.uix = EventMouseClickedPosXUI();
- Input[p].mouse.uiy = EventMouseClickedPosYUI();
- Input[p].mouse.x = EventMouseClickedPosXWorld();
- Input[p].mouse.y = EventMouseClickedPosYWorld();
- Input[p].mouse.z = EventMouseClickedPosZWorld();
- return true;
- }
- bool Input_ButtonOff (bool testConds, bool runActions)
- {
- int p = EventPlayer();
- Input[p].button.state[EventMouseClickedButton()] = false;
- Input[p].mouse.uix = EventMouseClickedPosXUI();
- Input[p].mouse.uiy = EventMouseClickedPosYUI();
- Input[p].mouse.x = EventMouseClickedPosXWorld();
- Input[p].mouse.y = EventMouseClickedPosYWorld();
- Input[p].mouse.z = EventMouseClickedPosZWorld();
- return true;
- }
- bool Input_Movement (bool testConds, bool runActions)
- {
- int p = EventPlayer();
- Input[p].mouse.uix = EventMouseMovedPosXUI();
- Input[p].mouse.uiy = EventMouseMovedPosYUI();
- Input[p].mouse.x = EventMouseMovedPosXWorld();
- Input[p].mouse.y = EventMouseMovedPosYWorld();
- Input[p].mouse.z = EventMouseMovedPosZWorld();
- return true;
- }
- void Input_Init ()
- {
- if (DETECT_KEYDOWN)
- {
- TriggerAddEventKeyPressed(TriggerCreate("Input_KeyOn"),c_playerAny,c_keyNone,true,0,0,0);
- }
- if (DETECT_KEYUP)
- {
- TriggerAddEventKeyPressed(TriggerCreate("Input_KeyOff"),c_playerAny,c_keyNone,false,0,0,0);
- }
- if (DETECT_BUTTONDOWN)
- {
- TriggerAddEventMouseClicked(TriggerCreate("Input_ButtonOn"),c_playerAny,c_mouseButtonNone,true);
- }
- if (DETECT_BUTTONUP)
- {
- TriggerAddEventMouseClicked(TriggerCreate("Input_ButtonOff"),c_playerAny,c_mouseButtonNone,false);
- }
- if (DETECT_MOVEMENT)
- {
- TriggerAddEventMouseMoved(TriggerCreate("Input_Movement"), c_playerAny);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement