-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathberobot_restrictions_team_death.sp
167 lines (134 loc) · 4.4 KB
/
berobot_restrictions_team_death.sp
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <tf2>
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <sm_logger>
#include <morecolors>
#include <team_round_timer>
#include <berobot_constants>
#include <berobot>
#include <berobot_core_restrictions>
#include <tf2_stocks>
char LOG_TAGS[][] = {"VERBOSE", "INFO", "ERROR"};
enum(<<= 1)
{
SML_VERBOSE = 1,
SML_INFO,
SML_ERROR,
}
#include <berobot_core>
#pragma newdecls required
#pragma semicolon 1
public Plugin myinfo =
{
name = "berobot_restrictions_team_death",
author = "icebear",
description = "",
version = "0.1",
url = "https://github.com/higps/robogithub"
};
public void OnPluginStart()
{
SMLoggerInit(LOG_TAGS, sizeof(LOG_TAGS), SML_ERROR, SML_FILE);
SMLogTag(SML_INFO, "berobot_restrictions_team_death started at %i", GetTime());
if (!IsEnabled())
return;
Start();
}
public void MM_OnEnabledChanged(int enabled)
{
SMLogTag(SML_VERBOSE, "MM_OnEnabledChanged called at %i with value %i", GetTime(), enabled);
if (enabled == 0)
{
UnhookEvent("player_death", OnDeath, EventHookMode_PostNoCopy);
return;
}
Start();
}
void Start()
{
HookEvent("player_death", OnDeath, EventHookMode_PostNoCopy);
}
public void OnDeath(Event event, const char[] name, bool dontBroadcast)
{
if (!IsEnabled())
{
return;
}
SMLogTag(SML_VERBOSE, "OnDeath called at %i", GetTime());
int victimUserId = event.GetInt("userid", -1);
int victimClientId = GetClientOfUserId(victimUserId);
int attackerUserId = event.GetInt("attacker", -1);
int attackerClientId = GetClientOfUserId(attackerUserId);
int death_flags = GetEventInt(event, "death_flags");
if((death_flags & TF_DEATHFLAG_DEADRINGER) != TF_DEATHFLAG_DEADRINGER)
{
// PrintToChatAll("Not deadringer");
}else{
return;
} // Not a dead ringer death?
if (IsAnyRobot(attackerClientId) && IsValidClient(victimClientId))
{
// int iattackerUserId = event.GetInt("attacker");
// int iattackerClientId = GetClientOfUserId(attackerUserId);
DataPack info = new DataPack();
info.Reset();
info.WriteCell(victimClientId);
info.WriteCell(attackerClientId);
CreateTimer(6.5, Timer_DeathTip, info);
}
if (!IsValidClient(victimClientId))
{
SMLogTag(SML_VERBOSE, "OnDeath canceled, because victim %i is invalid", victimClientId);
return;
}
if (!IsValidClient(attackerClientId))
{
SMLogTag(SML_VERBOSE, "OnDeath canceled, because attacker %i is invalid", attackerClientId);
return;
}
if (attackerClientId == victimClientId)
{
SMLogTag(SML_VERBOSE, "OnDeath canceled, because victim %L killed themselfs", victimClientId);
return;
}
if (!IsAnyRobot(victimClientId))
{
SMLogTag(SML_VERBOSE, "OnDeath canceled, because victim %L was not a robot", victimClientId);
return;
}
char weapon_logname[MAX_NAME_LENGTH];
GetEventString(event, "weapon_logclassname", weapon_logname, sizeof(weapon_logname));
if (StrEqual(weapon_logname, "player", true) || StrEqual(weapon_logname, "trigger", true) || StrEqual(weapon_logname, "world", true))
{
// PrintToChatAll("Logname %s", weapon_logname);
SMLogTag(SML_VERBOSE, "OnDeath canceled, because victim logname was player");
return;
}
char robotName[NAMELENGTH];
GetRobot(victimClientId, robotName, NAMELENGTH);
Robot robot;
GetRobotDefinition(robotName, robot);
int rewardedRobotCoins = robot.robotCoinsOnDeath;
SMLogTag(SML_VERBOSE, "adding %i RobotCoins, because robot %L died", rewardedRobotCoins, victimClientId);
AddRobotCoinsFor(victimClientId, rewardedRobotCoins);
int rewardedTeamCoins = robot.teamCoinsOnDeath;
SMLogTag(SML_VERBOSE, "adding %i TeamCoins, because robot %L died", rewardedTeamCoins, victimClientId);
AddTeamCoinsFor(victimClientId, rewardedTeamCoins);
}
public Action Timer_DeathTip(Handle timer, DataPack info)
{
info.Reset();
int victimClientId = info.ReadCell();
int attackerClientId = info.ReadCell();
delete info;
if(IsClientInGame(victimClientId))
{
char robotName[NAMELENGTH];
GetRobot(attackerClientId, robotName, NAMELENGTH);
Robot robot;
GetRobotDefinition(robotName, robot);
PrintHintText(victimClientId,"Tip: %s", robot.deathtip);
}
return Plugin_Continue;
}