vehicleWheeled.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. // This file contains script methods unique to the WheeledVehicle class. All
  23. // other necessary methods are contained in "../server/scripts/vehicle.cs" in
  24. // which the "generic" Vehicle class methods that are shared by all vehicles,
  25. // (flying, hover, and wheeled) can be found.
  26. // Parenting is in place for WheeledVehicleData to VehicleData. This should
  27. // make it easier for people to simply drop in new (generic) vehicles. All that
  28. // the user needs to create is a set of datablocks for the new wheeled vehicle
  29. // to use. This means that no (or little) scripting should be necessary.
  30. function WheeledVehicleData::onAdd(%this, %obj)
  31. {
  32. Parent::onAdd(%this, %obj);
  33. // Setup the car with some tires & springs
  34. for (%i = %obj.getWheelCount() - 1; %i >= 0; %i--)
  35. {
  36. %obj.setWheelTire(%i, DefaultCarTire);
  37. %obj.setWheelSpring(%i, DefaultCarSpring);
  38. %obj.setWheelPowered(%i, false);
  39. }
  40. // Steer with the front tires
  41. %obj.setWheelSteering(0, 1);
  42. %obj.setWheelSteering(1, 1);
  43. // Only power the two rear wheels... assuming there are only 4 wheels.
  44. %obj.setWheelPowered(2, true);
  45. %obj.setWheelPowered(3, true);
  46. }
  47. function WheeledVehicleData::onCollision(%this, %obj, %col, %vec, %speed)
  48. {
  49. // Collision with other objects, including items
  50. }
  51. // Used to kick the players out of the car that your crosshair is over
  52. function serverCmdcarUnmountObj(%client, %obj)
  53. {
  54. %obj.unmount();
  55. %obj.setControlObject(%obj);
  56. %ejectpos = %obj.getPosition();
  57. %ejectpos = VectorAdd(%ejectpos, "0 0 5");
  58. %obj.setTransform(%ejectpos);
  59. %ejectvel = %obj.mVehicle.getVelocity();
  60. %ejectvel = VectorAdd(%ejectvel, "0 0 10");
  61. %ejectvel = VectorScale(%ejectvel, %obj.getDataBlock().mass);
  62. %obj.applyImpulse(%ejectpos, %ejectvel);
  63. }
  64. // Used to flip the car over if it manages to get stuck upside down
  65. function serverCmdflipCar(%client)
  66. {
  67. %car = %client.player.getControlObject();
  68. if (%car.getClassName() $= "WheeledVehicle")
  69. {
  70. %carPos = %car.getPosition();
  71. %carPos = VectorAdd(%carPos, "0 0 3");
  72. %car.setTransform(%carPos SPC "0 0 1 0");
  73. }
  74. }
  75. function serverCmdsetPlayerControl(%client)
  76. {
  77. %client.setControlObject(%client.player);
  78. }
  79. function serverCmddismountVehicle(%client)
  80. {
  81. %car = %client.player.getControlObject();
  82. %passenger = %car.getMountNodeObject(0);
  83. %passenger.getDataBlock().doDismount(%passenger, true);
  84. %client.setControlObject(%client.player);
  85. }