This wiki was in read-only mode for many years, but can now be edited again. A lot of information will need to be updated.
BZFS API examples: Difference between revisions
Jump to navigation
Jump to search
created base template |
m added simple playerscorechange example |
||
| Line 2: | Line 2: | ||
=Examples List= | =Examples List= | ||
'''bz_ePlayerScoreChanged''' | |||
==Example | ==bz_ePlayerScoreChanged== | ||
'''Note:''' Using any of the player score modifying/changing functions without any conditionals will lead to infinite loops. | |||
Starter code from official docs: [https://www.bzflag.org/documentation/developer/bzfs_api/events/bz_eplayerscorechanged/ www.bzflag.org/documentation/developer/bzfs_api/events/bz_eplayerscorechanged/] | |||
bz_PlayerScoreChangeEventData_V1* dataObject = (bz_PlayerScoreChangeEventData_V1*)eventData; | |||
// Data | |||
// --- | |||
// (int) playerID - Player that has had a change of score. | |||
// (bz_eScoreElement) element - The type of score that is being changed. | |||
// (int) thisValue - The new amount of element score the playerID has. | |||
// (int) lastValue - The old amount of element score the playerID had. | |||
// (double) eventTime - Time local server time for the event. | |||
Here's an example of how we can use the player score changed event to modify player scores and keep them tied to specific game play accomplishments. | |||
// Example of keeping a score tied. | |||
if (dataObject->element == bz_eWins) { | |||
if (WinsFrom[dataObject->playerID] != dataObject->thisValue) { // We lookup from our WinsFrom array, | |||
//...to see if the players wins matches our score system, if not, we adjust it. | |||
bz_setPlayerWins(dataObject->playerID, WinsFrom[dataObject->playerID]);// This keeps our score in sync, but it doesn't keep us in a loop. | |||
} | |||
} | |||
Revision as of 19:38, 2 November 2025
Various examples of the BZFS API. This may be used a quick reference or guide for getting started and contains various tips or tricks for using it.
Examples List
bz_ePlayerScoreChanged
bz_ePlayerScoreChanged
Note: Using any of the player score modifying/changing functions without any conditionals will lead to infinite loops.
Starter code from official docs: www.bzflag.org/documentation/developer/bzfs_api/events/bz_eplayerscorechanged/
bz_PlayerScoreChangeEventData_V1* dataObject = (bz_PlayerScoreChangeEventData_V1*)eventData; // Data // --- // (int) playerID - Player that has had a change of score. // (bz_eScoreElement) element - The type of score that is being changed. // (int) thisValue - The new amount of element score the playerID has. // (int) lastValue - The old amount of element score the playerID had. // (double) eventTime - Time local server time for the event.
Here's an example of how we can use the player score changed event to modify player scores and keep them tied to specific game play accomplishments.
// Example of keeping a score tied.
if (dataObject->element == bz_eWins) {
if (WinsFrom[dataObject->playerID] != dataObject->thisValue) { // We lookup from our WinsFrom array,
//...to see if the players wins matches our score system, if not, we adjust it.
bz_setPlayerWins(dataObject->playerID, WinsFrom[dataObject->playerID]);// This keeps our score in sync, but it doesn't keep us in a loop.
}
}