-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGrabToCap.cpp
65 lines (55 loc) · 2.04 KB
/
GrabToCap.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// GrabToCap.cpp
#include "bzfsAPI.h"
// Custom Utility functions
void resetPlayer(int playerID) {
bz_resetFlag(playerID);
bz_killPlayer(playerID, true, BZ_SERVER);
bz_incrementPlayerLosses(playerID, -1);
}
bz_eTeamType flagToTeamValue(const char* flagType) {
if (strcmp("R*", flagType) == 0) {
return eRedTeam;
} else if (strcmp("G*", flagType) == 0) {
return eGreenTeam;
} else if (strcmp("B*", flagType) == 0) {
return eBlueTeam;
} else if (strcmp("P*", flagType) == 0) {
return ePurpleTeam;
} else {
return eNoTeam;
}
}
class GrabToCap : public bz_Plugin
{
public:
virtual const char* Name () {return "GrabToCap";}
virtual void Init(const char* config);
virtual void Event(bz_EventData *eventData);
};
BZ_PLUGIN(GrabToCap)
void GrabToCap::Init( const char* /*commandLine*/ ) {
Register(bz_eFlagGrabbedEvent);
}
void GrabToCap::Event ( bz_EventData *eventData )
{
if (eventData->eventType != bz_eFlagGrabbedEvent)
return;
bz_FlagGrabbedEventData_V1* grabData = (bz_FlagGrabbedEventData_V1*)eventData;
int playerHoldingFlag = grabData->playerID;
bz_eTeamType flagTeam = flagToTeamValue(grabData->flagType);
// Proceeding, if we have a team flag.
if (flagTeam != eNoTeam) {
bz_eTeamType playerTeam = bz_getPlayerTeam(grabData->playerID);
// If we have an actual team, we may be ready to score.
if ((playerTeam == eRedTeam) || (playerTeam == eGreenTeam) || (playerTeam == eBlueTeam) || (playerTeam == ePurpleTeam)) {
// Checking if teams are not the same, if they are not, we trigger a score change at this point, as well as anything else specified.
if (flagTeam != playerTeam) {
// View custom functions for details of code.
bz_triggerFlagCapture(playerHoldingFlag, playerTeam, flagTeam);
resetPlayer(playerHoldingFlag);
//bz_incrementPlayerWins(playerHoldingFlag, bz_getTeamCount(flagTeam));
}
}
}
// End of event trigger
}