Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Code modifications are CC0-1.0
- //WorldWeapons.cxx
- - bz_ServerShotFiredEventData_V1 event;
- + bz_ServerShotFiredEventData_V2 event;
- event.guid = shotGUID;
- event.flagType = allowEvent.flagType;
- event.speed = shotSpeed;
- + event.shotID = firingInfo.shot.id;
- for (int i = 0; i < 3; i++)
- {
- event.pos[i] = origin[i];
- event.velocity[i] = firingInfo.shot.vel[i];
- }
- // bzfsAPI.h
- class BZF_API bz_ServerShotFiredEventData_V1 : public bz_EventData
- {
- public:
- bz_ServerShotFiredEventData_V1() : bz_EventData(bz_eServerShotFiredEvent)
- , guid(0)
- , speed(0)
- , team(eRogueTeam)
- {
- pos[0] = pos[1] = pos[2] = velocity[0] = velocity[1] = velocity[2] = 0.0f;
- }
- uint32_t guid;
- bz_ApiString flagType;
- float speed;
- float pos[3];
- float velocity[3];
- bz_eTeamType team;
- };
- // Below code added:
- class BZF_API bz_ServerShotFiredEventData_V2 : public bz_ServerShotFiredEventData_V1
- {
- public:
- bz_ServerShotFiredEventData_V2() : bz_ServerShotFiredEventData_V1(), shotID(-1)
- {
- }
- int shotID;
- };
- // Above code added:
- // Below is an error of trying to compile a plug-in:
- /*
- serverShotAPI.cpp: In member function ‘virtual void serverShotAPI::Event(bz_EventData*)’:
- serverShotAPI.cpp:91:9: error: ‘bz_ServerShotFiredEventData_V2’ was not declared in this scope; did you mean ‘bz_ServerShotFiredEventData_V1’?
- 91 | bz_ServerShotFiredEventData_V2* shotData = (bz_ServerShotFiredEventData_V2*)eventData;
- | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
- | bz_ServerShotFiredEventData_V1
- serverShotAPI.cpp:91:41: error: ‘shotData’ was not declared in this scope
- 91 | bz_ServerShotFiredEventData_V2* shotData = (bz_ServerShotFiredEventData_V2*)eventData;
- | ^~~~~~~~
- serverShotAPI.cpp:91:84: error: expected primary-expression before ‘)’ token
- 91 | bz_ServerShotFiredEventData_V2* shotData = (bz_ServerShotFiredEventData_V2*)eventData;
- */
- // The command used to compile it:
- // g++ -I /home/path-to-bzflag-mod/bzflag-2.4.26-api-mod/include/ -shared -fPIC -o serverShotAPI.so serverShotAPI.cpp
- // The plugin code itself:
- // serverShotAPI.cpp
- // License: CC0-1.0
- #include "bzfsAPI.h"
- class serverShotAPI : public bz_Plugin, bz_CustomSlashCommandHandler
- {
- public:
- const char* Name(){return "serverShotAPI";}
- void Init ( const char* commandLine );
- void Event(bz_EventData *eventData );
- void Cleanup ( void );
- bool SlashCommand ( int playerID, bz_ApiString command, bz_ApiString message, bz_APIStringList* params );
- };
- BZ_PLUGIN(serverShotAPI)
- void serverShotAPI::Init (const char* commandLine) {
- bz_registerCustomSlashCommand ( "shot", this );
- Register(bz_ePlayerDieEvent);
- Register(bz_eServerShotFiredEvent);
- }
- void serverShotAPI::Cleanup (void) {
- bz_removeCustomSlashCommand ( "shot" );
- Flush();
- }
- bool serverShotAPI::SlashCommand ( int playerID, bz_ApiString command, bz_ApiString message, bz_APIStringList* params ) {
- if (command == "shot"){
- float vector[3]={0.0, 0.0, 0.0};
- float origin[3]={0.0, 0.0, 0.0};
- uint32_t shotGUID = bz_fireServerShot("LF", origin, vector, bz_getPlayerTeam(playerID));
- bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "ShotOnDemand: ShotGUID is: %u", shotGUID);
- return true;
- }
- return false;
- }
- void serverShotAPI::Event(bz_EventData *eventData ){
- switch (eventData->eventType) {
- case bz_ePlayerDieEvent: {
- //int playerID=((bz_PlayerDieEventData_V2*)eventData)->playerID;
- bz_PlayerDieEventData_V2* deathData = (bz_PlayerDieEventData_V2*)eventData;
- bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "DieEvent: ShotID is: %d", deathData->shotID);
- }break;
- case bz_eServerShotFiredEvent: {
- bz_ServerShotFiredEventData_V2* shotData = (bz_ServerShotFiredEventData_V2*)eventData;
- bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "ShotEvent: ShotID is: %d, ShotGUID is: %u", shotData->shotID, shotData->guid);
- // Data
- // ---
- // (uint32_t) guid - The GUID of the shot that was fired
- // (bz_ApiString) flagType - The flag abbreviation of the shot type that was fired
- // (float) speed - The speed of the shot fired
- // (float[3]) pos - The position of where the shot was fired (x, y, z coordinates)
- // (float[3]) velocity - The vector of the shot's direction multiplied by the shot's speed
- // (bz_eTeamType) team - The team this shot belongs to
- // (double) eventTime - This value is the local server time of the event.
- }break;
- default:{
- }break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement