Skip to content

Commit

Permalink
Re-format existing files, correcting method names as I go
Browse files Browse the repository at this point in the history
  • Loading branch information
tjone270 committed Jun 28, 2024
1 parent 645af7c commit 77e5d39
Show file tree
Hide file tree
Showing 16 changed files with 2,575 additions and 2,516 deletions.
66 changes: 34 additions & 32 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
#define _GNU_SOURCE
#endif

#include <stdlib.h>
#include <stdio.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>

#include "quake_common.h"
#include "common.h"
#include "quake_common.h"

#ifndef NOPY
#include "pyminqlxtended.h"
Expand All @@ -26,7 +26,7 @@ void __cdecl RegularPrint(void) {
}

void __cdecl Slap(void) {
int dmg = 0;
int dmg = 0;
int argc = Cmd_Argc();
if (argc < 2) {
Com_Printf("Usage: %s <client_id> [damage]\n", Cmd_Argv(0));
Expand All @@ -36,27 +36,29 @@ void __cdecl Slap(void) {
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)
} 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)
if (dmg) {
SV_SendServerCommand(NULL, "print \"%s^7 was slapped for %d damage!\n\"\n", svs->clients[i].name, dmg);
else
} 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)
if (g_entities[i].health > 0) {
G_AddEvent(&g_entities[i], EV_PAIN, 99); // 99 health = pain100_1.wav
else
} else {
G_AddEvent(&g_entities[i], EV_DEATH1, g_entities[i].s.number);
}
else
}
} else {
Com_Printf("The player is currently not active.\n");
}
}

void __cdecl Slay(void) {
Expand All @@ -69,16 +71,15 @@ void __cdecl Slay(void) {
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) {
} 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
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
Expand All @@ -89,25 +90,26 @@ void __cdecl PyRcon(void) {
}

void __cdecl PyCommand(void) {
if (!custom_command_handler) {
return; // No registered handler.
}
PyGILState_STATE gstate = PyGILState_Ensure();
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");
}
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);
Py_XDECREF(result);
PyGILState_Release(gstate);
}

void __cdecl RestartPython(void) {
Com_Printf("Restarting Python...\n");
if (PyMinqlx_IsInitialized())
PyMinqlx_Finalize();
PyMinqlx_Initialize();
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);
Expand Down
Loading

0 comments on commit 77e5d39

Please sign in to comment.