commands.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. //-----------------------------------------------------------------------------
  2. // Copyright (c) 2012 GarageGames, LLC
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to
  6. // deal in the Software without restriction, including without limitation the
  7. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  8. // sell copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  20. // IN THE SOFTWARE.
  21. //-----------------------------------------------------------------------------
  22. //-----------------------------------------------------------------------------
  23. // Misc server commands avialable to clients
  24. //-----------------------------------------------------------------------------
  25. function serverCmdSuicide(%client)
  26. {
  27. if (isObject(%client.player))
  28. %client.player.kill("Suicide");
  29. }
  30. function serverCmdPlayCel(%client,%anim)
  31. {
  32. if (isObject(%client.player))
  33. %client.player.playCelAnimation(%anim);
  34. }
  35. function serverCmdTestAnimation(%client, %anim)
  36. {
  37. if (isObject(%client.player))
  38. %client.player.playTestAnimation(%anim);
  39. }
  40. function serverCmdPlayDeath(%client)
  41. {
  42. if (isObject(%client.player))
  43. %client.player.playDeathAnimation();
  44. }
  45. // ----------------------------------------------------------------------------
  46. // Throw/Toss
  47. // ----------------------------------------------------------------------------
  48. function serverCmdThrow(%client, %data)
  49. {
  50. %player = %client.player;
  51. if(!isObject(%player) || %player.getState() $= "Dead" || !$Game::Running)
  52. return;
  53. switch$ (%data)
  54. {
  55. case "Weapon":
  56. %item = (%player.getMountedImage($WeaponSlot) == 0) ? "" : %player.getMountedImage($WeaponSlot).item;
  57. if (%item !$="")
  58. %player.throw(%item);
  59. case "Ammo":
  60. %weapon = (%player.getMountedImage($WeaponSlot) == 0) ? "" : %player.getMountedImage($WeaponSlot);
  61. if (%weapon !$= "")
  62. {
  63. if(%weapon.ammo !$= "")
  64. %player.throw(%weapon.ammo);
  65. }
  66. default:
  67. if(%player.hasInventory(%data.getName()))
  68. %player.throw(%data);
  69. }
  70. }
  71. // ----------------------------------------------------------------------------
  72. // Force game end and cycle
  73. // Probably don't want this in a final game without some checks. Anyone could
  74. // restart a game.
  75. // ----------------------------------------------------------------------------
  76. function serverCmdFinishGame()
  77. {
  78. cycleGame();
  79. }
  80. // ----------------------------------------------------------------------------
  81. // Cycle weapons
  82. // ----------------------------------------------------------------------------
  83. function serverCmdCycleWeapon(%client, %direction)
  84. {
  85. %client.getControlObject().cycleWeapon(%direction);
  86. }
  87. // ----------------------------------------------------------------------------
  88. // Unmount current weapon
  89. // ----------------------------------------------------------------------------
  90. function serverCmdUnmountWeapon(%client)
  91. {
  92. %client.getControlObject().unmountImage($WeaponSlot);
  93. }
  94. // ----------------------------------------------------------------------------
  95. // Weapon reloading
  96. // ----------------------------------------------------------------------------
  97. function serverCmdReloadWeapon(%client)
  98. {
  99. %player = %client.getControlObject();
  100. %image = %player.getMountedImage($WeaponSlot);
  101. // Don't reload if the weapon's full.
  102. if (%player.getInventory(%image.ammo) == %image.ammo.maxInventory)
  103. return;
  104. if (%image > 0)
  105. %image.clearAmmoClip(%player, $WeaponSlot);
  106. }