-
Notifications
You must be signed in to change notification settings - Fork 0
/
retroreflector.cpp
90 lines (78 loc) · 3.34 KB
/
retroreflector.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
* retroreflector
* Copyright (C) 2020 Benjamin Jackson
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "bzfsAPI.h"
class retroreflector : public bz_Plugin
{
public:
virtual const char* Name();
virtual void Init(const char* config);
virtual void Cleanup();
virtual void Event(bz_EventData* eventData);
};
BZ_PLUGIN(retroreflector)
const char* retroreflector::Name()
{
return "retroreflector 1.0.2";
}
void retroreflector::Init(const char* config)
{
Register(bz_eFlagGrabbedEvent);
Register(bz_ePlayerDieEvent);
bz_RegisterCustomFlag("RR", "Retrorreflector", "Reflects laser back to shooter", 0, eGoodFlag);
}
void retroreflector::Cleanup()
{
Flush();
}
void retroreflector::Event(bz_EventData* eventData)
{
switch (eventData->eventType)
{
case bz_ePlayerDieEvent:
{
// This event is called each time a tank is killed.
bz_PlayerDieEventData_V2* diedata = (bz_PlayerDieEventData_V2*)eventData;
bz_BasePlayerRecord* killer = bz_getPlayerByIndex(diedata->killerID);
if (killer)
{
std::string RR = bz_getFlagName(diedata->flagHeldWhenKilled);
if ("RR" == RR && diedata->flagKilledWith == "L" && killer->spawned && (diedata->killerTeam != diedata->team || diedata->killerTeam == eRogueTeam))
{
bz_sendTextMessagef(BZ_SERVER, diedata->killerID, "You killed yourself by shooting %s while they held retroreflector", bz_getPlayerCallsign(diedata->playerID));
bz_killPlayer(diedata->killerID, false, diedata->playerID, "RR");
bz_incrementPlayerLosses(diedata->playerID, -1);
}
}
bz_freePlayerRecord(killer);
// Data
// ----
// (int) playerID - ID of the player who was killed.
// (bz_eTeamType) team - The team the killed player was on.
// (int) killerID - The owner of the shot that killed the player, or BZ_SERVER for server side kills
// (bz_eTeamType) killerTeam - The team the owner of the shot was on.
// (bz_ApiString) flagKilledWith - The flag name the owner of the shot had when the shot was fired.
// (int) flagHeldWhenKilled - The ID of the flag the victim was holding when they died.
// (int) shotID - The shot ID that killed the player, if the player was not killed by a shot, the id will be -1.
// (bz_PlayerUpdateState) state - The state record for the killed player at the time of the event
// (double) eventTime - Time of the event on the server.
}
break;
default:
break;
}
}