Advertisement
Guest User

I don't quite get why this doesn't work

a guest
Dec 25th, 2023
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.65 KB | None | 0 0
  1. // Code modifications are CC0-1.0
  2.  
  3. //WorldWeapons.cxx
  4. -   bz_ServerShotFiredEventData_V1 event;
  5. +   bz_ServerShotFiredEventData_V2 event;
  6.     event.guid = shotGUID;
  7.     event.flagType = allowEvent.flagType;
  8.     event.speed = shotSpeed;
  9. +   event.shotID = firingInfo.shot.id;
  10.     for (int i = 0; i < 3; i++)
  11.     {
  12.         event.pos[i] = origin[i];
  13.         event.velocity[i] = firingInfo.shot.vel[i];
  14.     }
  15.  
  16. // bzfsAPI.h
  17. class BZF_API bz_ServerShotFiredEventData_V1 : public bz_EventData
  18. {
  19. public:
  20.     bz_ServerShotFiredEventData_V1() : bz_EventData(bz_eServerShotFiredEvent)
  21.         , guid(0)
  22.         , speed(0)
  23.         , team(eRogueTeam)
  24.     {
  25.         pos[0] = pos[1] = pos[2] = velocity[0] = velocity[1] = velocity[2] = 0.0f;
  26.     }
  27.  
  28.     uint32_t guid;
  29.     bz_ApiString flagType;
  30.     float speed;
  31.     float pos[3];
  32.     float velocity[3];
  33.     bz_eTeamType team;
  34. };
  35.  
  36. // Below code added:
  37. class BZF_API bz_ServerShotFiredEventData_V2 : public bz_ServerShotFiredEventData_V1
  38. {
  39. public:
  40.     bz_ServerShotFiredEventData_V2() : bz_ServerShotFiredEventData_V1(), shotID(-1)
  41.     {
  42.     }
  43.  
  44.     int shotID;
  45. };
  46. // Above code added:
  47.  
  48.  
  49. // Below is an error of trying to compile a plug-in:
  50. /*
  51. serverShotAPI.cpp: In member function ‘virtual void serverShotAPI::Event(bz_EventData*)’:
  52. serverShotAPI.cpp:91:9: error: ‘bz_ServerShotFiredEventData_V2’ was not declared in this scope; did you mean ‘bz_ServerShotFiredEventData_V1’?
  53.    91 |         bz_ServerShotFiredEventData_V2* shotData = (bz_ServerShotFiredEventData_V2*)eventData;
  54.       |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  55.       |         bz_ServerShotFiredEventData_V1
  56. serverShotAPI.cpp:91:41: error: ‘shotData’ was not declared in this scope
  57.    91 |         bz_ServerShotFiredEventData_V2* shotData = (bz_ServerShotFiredEventData_V2*)eventData;
  58.       |                                         ^~~~~~~~
  59. serverShotAPI.cpp:91:84: error: expected primary-expression before ‘)’ token
  60.    91 |         bz_ServerShotFiredEventData_V2* shotData = (bz_ServerShotFiredEventData_V2*)eventData;
  61. */
  62.  
  63. // The command used to compile it:
  64. // g++ -I /home/path-to-bzflag-mod/bzflag-2.4.26-api-mod/include/ -shared -fPIC -o serverShotAPI.so serverShotAPI.cpp
  65.  
  66. // The plugin code itself:
  67. // serverShotAPI.cpp
  68. // License: CC0-1.0
  69.  
  70. #include "bzfsAPI.h"
  71.  
  72. class serverShotAPI : public bz_Plugin, bz_CustomSlashCommandHandler
  73. {
  74. public:
  75.   const char* Name(){return "serverShotAPI";}
  76.   void Init ( const char* commandLine );
  77.   void Event(bz_EventData *eventData );
  78.   void Cleanup ( void );
  79.   bool SlashCommand ( int playerID, bz_ApiString command, bz_ApiString message, bz_APIStringList* params );
  80.  
  81. };
  82.  
  83. BZ_PLUGIN(serverShotAPI)
  84.  
  85. void serverShotAPI::Init (const char* commandLine) {
  86.   bz_registerCustomSlashCommand ( "shot", this );
  87.   Register(bz_ePlayerDieEvent);
  88.   Register(bz_eServerShotFiredEvent);
  89. }
  90.  
  91. void serverShotAPI::Cleanup (void) {
  92.   bz_removeCustomSlashCommand ( "shot" );
  93.   Flush();
  94. }
  95.  
  96. bool serverShotAPI::SlashCommand ( int playerID, bz_ApiString command, bz_ApiString message, bz_APIStringList* params ) {
  97.   if (command == "shot"){
  98.     float vector[3]={0.0, 0.0, 0.0};
  99.     float origin[3]={0.0, 0.0, 0.0};
  100.     uint32_t shotGUID = bz_fireServerShot("LF", origin, vector, bz_getPlayerTeam(playerID));
  101.     bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "ShotOnDemand: ShotGUID is: %u", shotGUID);
  102.     return true;
  103.   }
  104.   return false;
  105. }
  106.  
  107. void serverShotAPI::Event(bz_EventData *eventData ){
  108.   switch (eventData->eventType) {
  109.       case bz_ePlayerDieEvent: {
  110.       //int playerID=((bz_PlayerDieEventData_V2*)eventData)->playerID;
  111.       bz_PlayerDieEventData_V2* deathData = (bz_PlayerDieEventData_V2*)eventData;
  112.       bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "DieEvent: ShotID is: %d", deathData->shotID);
  113.     }break;
  114.      
  115.       case bz_eServerShotFiredEvent: {
  116.         bz_ServerShotFiredEventData_V2* shotData = (bz_ServerShotFiredEventData_V2*)eventData;
  117.         bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "ShotEvent: ShotID is: %d, ShotGUID is: %u", shotData->shotID, shotData->guid);
  118.        
  119. // Data
  120. // ---
  121. // (uint32_t)     guid - The GUID of the shot that was fired
  122. // (bz_ApiString) flagType - The flag abbreviation of the shot type that was fired
  123. // (float)        speed - The speed of the shot fired
  124. // (float[3])     pos - The position of where the shot was fired (x, y, z coordinates)
  125. // (float[3])     velocity - The vector of the shot's direction multiplied by the shot's speed
  126. // (bz_eTeamType) team - The team this shot belongs to
  127. // (double)       eventTime - This value is the local server time of the event.
  128.        
  129.     }break;
  130.      
  131.     default:{
  132.     }break;
  133.   }
  134. }
  135.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement