forked from MinoMino/minqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommands.c
117 lines (103 loc) · 3.63 KB
/
commands.c
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
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include "common.h"
#include "quake_common.h"
#ifndef NOPY
#include "pyminqlxtended.h"
#endif
void __cdecl SendServerCommand(void) {
SV_SendServerCommand(NULL, "%s\n", Cmd_Args());
}
void __cdecl CenterPrint(void) {
SV_SendServerCommand(NULL, "cp \"%s\"\n", Cmd_Args());
}
void __cdecl RegularPrint(void) {
SV_SendServerCommand(NULL, "print \"%s\n\"\n", Cmd_Args());
}
void __cdecl Slap(void) {
int dmg = 0;
int argc = Cmd_Argc();
if (argc < 2) {
Com_Printf("Usage: %s <client_id> [damage]\n", Cmd_Argv(0));
return;
}
int i = atoi(Cmd_Argv(1));
if (i < 0 || i > sv_maxclients->integer) {
Com_Printf("client_id must be a number between 0 and %d\n.", sv_maxclients->integer);
return;
} else if (argc > 2) {
dmg = atoi(Cmd_Argv(2));
}
if (g_entities[i].inuse && g_entities[i].health > 0) {
Com_Printf("Slapping...\n");
if (dmg) {
SV_SendServerCommand(NULL, "print \"%s^7 was slapped for %d damage!\n\"\n", svs->clients[i].name, dmg);
} else {
SV_SendServerCommand(NULL, "print \"%s^7 was slapped!\n\"\n", svs->clients[i].name);
}
g_entities[i].client->ps.velocity[0] += RandomFloatWithNegative() * 200.0f;
g_entities[i].client->ps.velocity[1] += RandomFloatWithNegative() * 200.0f;
g_entities[i].client->ps.velocity[2] += 300.0f;
g_entities[i].health -= dmg; // Will be 0 if argument wasn't passed.
if (g_entities[i].health > 0) {
G_AddEvent(&g_entities[i], EV_PAIN, 99); // 99 health = pain100_1.wav
} else {
G_AddEvent(&g_entities[i], EV_DEATH1, g_entities[i].s.number);
}
} else {
Com_Printf("The player is currently not active.\n");
}
}
void __cdecl Slay(void) {
int argc = Cmd_Argc();
if (argc < 2) {
Com_Printf("Usage: %s <client_id>\n", Cmd_Argv(0));
return;
}
int i = atoi(Cmd_Argv(1));
if (i < 0 || i > sv_maxclients->integer) {
Com_Printf("client_id must be a number between 0 and %d\n.", sv_maxclients->integer);
return;
} else if (g_entities[i].inuse && g_entities[i].health > 0) {
Com_Printf("Slaying player...\n");
SV_SendServerCommand(NULL, "print \"%s^7 was slain!\n\"\n", svs->clients[i].name);
DebugPrint("Slaying '%s'!\n", svs->clients[i].name);
g_entities[i].health = -40;
G_AddEvent(&g_entities[i], EV_GIB_PLAYER, g_entities[i].s.number);
} else {
Com_Printf("The player is currently not active.\n");
}
}
#ifndef NOPY
// Execute a pyminqlxtended command as if it were the owner executing it.
// Output will appear in the console.
void __cdecl PyRcon(void) {
RconDispatcher(Cmd_Args());
}
void __cdecl PyCommand(void) {
if (!custom_command_handler) {
return; // No registered handler.
}
PyGILState_STATE gstate = PyGILState_Ensure();
PyObject* result = PyObject_CallFunction(custom_command_handler, "s", Cmd_Args());
if (result == Py_False) {
Com_Printf("The command failed to be executed. pyminqlxtended found no handler.\n");
}
Py_XDECREF(result);
PyGILState_Release(gstate);
}
void __cdecl RestartPython(void) {
Com_Printf("Restarting Python...\n");
if (PyMinqlxtended_IsInitialized()) {
PyMinqlxtended_Finalize();
}
PyMinqlxtended_Initialize();
// minqlxtended initializes after the first new game starts, but since the game already
// start, we manually trigger the event to make it initialize properly.
NewGameDispatcher(0);
}
#endif