Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "convar.h"
  9. #include "tier0/dbg.h"
  10. #include "player.h"
  11. #include "world.h"
  12. // memdbgon must be the last include file in a .cpp file!!!
  13. #include "tier0/memdbgon.h"
  14. void Test_CreateEntity( const CCommand &args )
  15. {
  16. CBasePlayer *pPlayer = UTIL_GetCommandClient();
  17. // Require a player entity or that the command was entered from the dedicated server console
  18. if ( !pPlayer && UTIL_GetCommandClientIndex() > 0 )
  19. {
  20. return;
  21. }
  22. if ( args.ArgC() < 2 )
  23. {
  24. Error( "Test_CreateEntity: requires entity classname argument." );
  25. }
  26. const char *pClassName = args[ 1 ];
  27. // Don't allow regular users to create point_servercommand entities for the same reason as blocking ent_fire
  28. if ( pPlayer && !Q_stricmp( pClassName, "point_servercommand" ) )
  29. {
  30. if ( engine->IsDedicatedServer() )
  31. {
  32. // We allow people with disabled autokick to do it, because they already have rcon.
  33. if ( pPlayer->IsAutoKickDisabled() == false )
  34. return;
  35. }
  36. else if ( gpGlobals->maxClients > 1 )
  37. {
  38. // On listen servers with more than 1 player, only allow the host to create point_servercommand.
  39. CBasePlayer *pHostPlayer = UTIL_GetListenServerHost();
  40. if ( pPlayer != pHostPlayer )
  41. return;
  42. }
  43. }
  44. if ( !CreateEntityByName( pClassName ) )
  45. {
  46. Error( "Test_CreateEntity( %s ) failed.", pClassName );
  47. }
  48. }
  49. void Test_RandomPlayerPosition()
  50. {
  51. CBasePlayer *pPlayer = UTIL_GetLocalPlayer();
  52. CWorld *pWorld = GetWorldEntity();
  53. if ( !pPlayer )
  54. {
  55. Error( "Test_RandomPlayerPosition: no local player entity." );
  56. }
  57. else if ( !pWorld )
  58. {
  59. Error( "Test_RandomPlayerPosition: no world entity." );
  60. }
  61. Vector vMin, vMax;
  62. pWorld->GetWorldBounds( vMin, vMax );
  63. Vector vecOrigin;
  64. vecOrigin.x = RandomFloat( vMin.x, vMax.x );
  65. vecOrigin.y = RandomFloat( vMin.y, vMax.y );
  66. vecOrigin.z = RandomFloat( vMin.z, vMax.z );
  67. pPlayer->ForceOrigin( vecOrigin );
  68. }
  69. ConCommand cc_Test_CreateEntity( "Test_CreateEntity", Test_CreateEntity, 0, FCVAR_CHEAT );
  70. ConCommand cc_Test_RandomPlayerPosition( "Test_RandomPlayerPosition", Test_RandomPlayerPosition, 0, FCVAR_CHEAT );