NeuralStunner

NS Input Script (Snippet)

Dec 17th, 2011
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. // Define script numbers at the top, to make them quickly changable.
  2. #Define NS_Cl_Input_Script 961
  3. #Define NS_Sv_Input_Script 962
  4.  
  5.  
  6. // Player Input (Client-Side): Detects input and informs the Server when it changes.
  7.  
  8. Script NS_Cl_Input_Script Enter ClientSide
  9. {
  10. // Not needed or desired in TitleMaps.
  11. If (GameType() == GAME_TITLE_MAP) Terminate;
  12.  
  13. // Which Player?
  14. Int ThisPlayer = PlayerNumber();
  15. // Cancel if somehow called by a non-Player.
  16. If ((ThisPlayer < 0) || (ThisPlayer >= 32)) Terminate;
  17.  
  18.  
  19. // For storing buttons.
  20. Int ThemButtons, ThemOldButtons;
  21.  
  22. While (True)
  23. {
  24. // Here you should check whether the Player has left, and terminate.
  25.  
  26. // For key detection in weapons/items.
  27. ThemButtons = GetPlayerInput(PlayerNumber(), INPUT_BUTTONS);
  28. ThemOldButtons = GetPlayerInput(PlayerNumber(), INPUT_OLDBUTTONS);
  29.  
  30. // Attack
  31. If (ThemButtons & BT_ATTACK)
  32. {
  33. If (!(ThemOldButtons & BT_ATTACK)) ACS_ExecuteAlways (NS_Sv_Input_Script, 0, BT_ATTACK, 1);
  34. }
  35. Else
  36. {
  37. If (ThemOldButtons & BT_ATTACK) ACS_ExecuteAlways (NS_Sv_Input_Script, 0, BT_ATTACK, 0);
  38. }
  39.  
  40. // Check other Inputs here.
  41.  
  42.  
  43. // This is required, Terran.
  44. Delay (1);
  45. }
  46. }
  47.  
  48.  
  49. // Player Input (Server-Side): Called by NS_Cl_Input_Script.
  50.  
  51. Script NS_Sv_Input_Script (Int ThisButton, Int ThisValue)
  52. {
  53. // Cancel if somehow called by a non-Player.
  54. Int ThisPlayer = PlayerNumber();
  55. If ((ThisPlayer < 0) || (ThisPlayer >= 32)) Terminate;
  56.  
  57. Switch (ThisButton)
  58. {
  59. Case BT_ATTACK:
  60. If (ThisValue)
  61. {
  62. // Give a flag item or set a property.
  63. }
  64. Else
  65. {
  66. // Remove the flag item.
  67. }
  68. Break;
  69.  
  70. // Handle other controls here.
  71.  
  72. }
  73. }
  74.  
  75.  
  76. /*
  77. The first script is handled clientside, where a 1-tic loop will not be laggy. As soon as an input change is detected, it calls the second script, which is server-side.
  78.  
  79. Calls to the server script, and status changes associated with them, are only done when actually needed. This should, in theory, prevent lag.
  80. */
Advertisement
Add Comment
Please, Sign In to add comment