-
Notifications
You must be signed in to change notification settings - Fork 0
/
euphoria.sp
140 lines (116 loc) · 3.54 KB
/
euphoria.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
#include <sourcemod>
#define PLUGIN_VERSION "0.0.1"
static String:KVPath[PLATFORM_MAX_PATH];
new Handle:ClientTimer[32];
static Minutes[32];
static Kills[32];
static Deaths[32];
public Plugin:myinfo =
{
name = "Euphoria-TF2",
author = "Mcduder",
description = "This is a script that allows the Euphoria Gaming Network to get/send info and stats, etc.",
version = PLUGIN_VERSION,
url = "euphoriagaming.net"
}
public OnPluginStart()
{
PrintToServer("Euporia Tf2 Plugin started");
//CreateDirectory("addons/sourcemod/data/playerinfo.txt", 3);
BuildPath(Path_SM, KVPath, sizeof(KVPath), "data/playerinfo.txt");
RegConsoleCmd("sm_stats", Command_getInfo, "");
HookEvent("player_death", player_death);
}
public OnPluginEnd()
{
UnhookEvent("player_death", player_death);
}
public OnClientPutInServer(client)
{
AlterPlayerInfo(client, 1);
ClientTimer[client] = CreateTimer(60.0, TimerAddMinutes, client, TIMER_REPEAT);
}
public OnClientDisconnect(client)
{
CloseHandle(ClientTimer[client]);
if(client > 0)
AlterPlayerInfo(client, 0);
}
public Action:Command_getInfo(client, args)
{
new String:Name[32];
GetClientName(client, Name, sizeof(Name));
PrintToChatAll("%s has %d Minutes.", Name, Minutes[client]);
return Plugin_Handled;
}
public player_death(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
if(client == 0 || attacker == 0)
{
return Plugin_Continue;
}
new String:name[32], String:aname[32];
GetClientName(client, name, 32);
GetClientName(attacker, aname, 32);
if(client == attacker)
{
PrintToChatAll("%s Humiliated Theirself", name);
Deaths[client]++;
return Plugin_Continue;
} else {
PrintToChatAll("%s killed %s", aname, name);
Kills[attacker]++;
Deaths[client]++;
return Plugin_Continue;
}
}
public Action:TimerAddMinutes(Handle:timer, any:client)
{
if(IsClientConnected(client) && IsClientInGame(client))
{
Minutes[client]++;
}
}
public AlterPlayerInfo(client, connection)
{
new Handle:DB = CreateKeyValues("PlayersInfo");
FileToKeyValues(DB, KVPath);
new String:SID[32];
GetClientAuthString(client, SID, sizeof(SID));
if(connection == 1)
{
//we are connecting
if(KvJumpToKey(DB, SID, true))
{
new String:name[MAX_NAME_LENGTH], String:temp_name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
KvGetString(DB, "name", temp_name, sizeof(temp_name), "NULL");
Minutes[client] = KvGetNum(DB, "Minutes", 0);
Deaths[client] = KvSetNum(DB, "Deaths", 0);
Kills[client] = KvSetNum(DB, "Kills", 0);
new connections = KvGetNum(DB, "connections");
if(StrEqual(temp_name, "NULL") && connections == 0)
{
PrintToChatAll("%s is new to the server.", name);
} else {
PrintToChatAll("%s last connected as %s. Has %d connections.", name, temp_name, connections);
}
KvSetNum(DB, "connections", ++connections);
KvSetString(DB, "name", name);
}
} else if(connection == 0)
{
//we are disconnecting
if(KvJumpToKey(DB, SID, true))
{
KvSetNum(DB, "Minutes", Minutes[client]);
KvSetNum(DB, "Deaths", Deaths[client]);
KvSetNum(DB, "Kills", Kills[client]);
}
}
KvRewind(DB);
KeyValuesToFile(DB, KVPath);
CloseHandle(DB);
}