This wiki is archived and useful information is being migrated to the main bzflag.org website

Difference between revisions of "Bz eCaptureEvent"

From BZFlagWiki
Jump to: navigation, search
(Uses: hyphenated compound adjective)
(added sample code)
Line 43: Line 43:
 
==Uses==
 
==Uses==
 
This event is a notification-only event, none of the data returned can be changed.
 
This event is a notification-only event, none of the data returned can be changed.
 +
==Example Code==
 +
void sampleDocPlugin::Event(bz_EventData* eventData)
 +
{
 +
    switch (eventData->eventType)
 +
    {
 +
        case bz_eCaptureEvent: // A tank captures the flag
 +
        {
 +
            // Get the data about what just happened and store it in the 'capData' variable
 +
            bz_CTFCaptureEventData_V1* capData = (bz_CTFCaptureEventData_V1*)eventData;
 +
 +
            // Create a player record in order to access the player's callsign
 +
            bz_BasePlayerRecord* myPlayerRecord = bz_getPlayerByIndex(capData->playerCapping);
 +
 +
            bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s captured the flag!", myPlayerRecord->callsign.c_str()); // Announce who captured the flag
 +
 +
            bz_freePlayerRecord(myPlayerRecord); // Free the player record to avoid a memory leak
 +
        }
 +
    }
 +
}
  
 
[[Category:BZFS_API_Docs]]
 
[[Category:BZFS_API_Docs]]
 
[[Category:BZFS_API_Events]]
 
[[Category:BZFS_API_Events]]

Revision as of 05:00, 29 January 2013

BZFS API Documentation This page contains part of the BZFS API documentation for use by Plug-ins on the BZFS server.

BZFS Event. This page documents a BZFS event that is called by the game server to notify plug-ins of various actions and state changes in the game world.


Overview

The bz_eCaptureEvent is an API event that is called each time a team's flag has been captured.

Data

bz_eCaptureEvent returns the bz_CTFCaptureEventData_V1 data class.

name type value description
eventType bz_eEventType bz_eCaptureEvent
teamCapped bz_eTeamType The team whose flag was captured.
teamCapping bz_eTeamType The team who did the capturing.
playerCapping int The player who captured the flag.
pos float[3] The world position(X,Y,Z) where the flag has been captured
rot float The rotational orientation of the capturing player
time double The time on which the flag was captured

Uses

This event is a notification-only event, none of the data returned can be changed.

Example Code

void sampleDocPlugin::Event(bz_EventData* eventData)
{
   switch (eventData->eventType)
   {
       case bz_eCaptureEvent: // A tank captures the flag
       {
           // Get the data about what just happened and store it in the 'capData' variable
           bz_CTFCaptureEventData_V1* capData = (bz_CTFCaptureEventData_V1*)eventData;

           // Create a player record in order to access the player's callsign
           bz_BasePlayerRecord* myPlayerRecord = bz_getPlayerByIndex(capData->playerCapping);

           bz_sendTextMessagef(BZ_SERVER, BZ_ALLUSERS, "%s captured the flag!", myPlayerRecord->callsign.c_str()); // Announce who captured the flag

           bz_freePlayerRecord(myPlayerRecord); // Free the player record to avoid a memory leak
       }
   }
}