Skip to content

Commit

Permalink
Add support cheats command god,notarget,noclip
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lentq committed Oct 8, 2023
1 parent b7f6eb8 commit 7fcec97
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 3 deletions.
110 changes: 108 additions & 2 deletions rehlds/engine/host_cmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,111 @@ void Host_Status_Formatted_f(void)
Host_Status_Printf(conprint, log, "%i users\n", nClients);
}

// Sets client to godmode
void Host_God_f(void)
{
if (cmd_source == src_command)
{
Cmd_ForwardToServer();
return;
}

if (!sv_cheats.value)
return;

sv_player->v.flags = (int)sv_player->v.flags ^ FL_GODMODE;
if (!((int)sv_player->v.flags & FL_GODMODE))
SV_ClientPrintf("godmode OFF\n");
else
SV_ClientPrintf("godmode ON\n");
}

// Sets client to notarget mode
void Host_Notarget_f(void)
{
if (cmd_source == src_command)
{
Cmd_ForwardToServer();
return;
}

if (!sv_cheats.value)
return;

sv_player->v.flags = (int)sv_player->v.flags ^ FL_NOTARGET;
if (!((int)sv_player->v.flags & FL_NOTARGET))
SV_ClientPrintf("notarget OFF\n");
else
SV_ClientPrintf("notarget ON\n");
}

// Searches along the direction ray in steps of "step" to see if
// the entity position is passible
// Used for putting the player in valid space when toggling off noclip mode
int FindPassableSpace(edict_t *pEdict, vec_t *direction, float step)
{
int i;

for (i = 0; i < 100; i++)
{
VectorMA(pEdict->v.origin, step, direction, pEdict->v.origin);

if (!SV_TestEntityPosition(pEdict))
{
// Store old origin
VectorCopy(pEdict->v.origin, pEdict->v.oldorigin);
return TRUE;
}
}

return FALSE;
}

void Host_Noclip_f(void)
{
if (cmd_source == src_command)
{
Cmd_ForwardToServer();
return;
}

if (!sv_cheats.value)
return;

if (sv_player->v.movetype != MOVETYPE_NOCLIP)
{
sv_player->v.movetype = MOVETYPE_NOCLIP;
SV_ClientPrintf("noclip ON\n");
}
else
{
sv_player->v.movetype = MOVETYPE_WALK;

// Store old origin
VectorCopy(sv_player->v.origin, sv_player->v.oldorigin);

SV_ClientPrintf("noclip OFF\n");

if (SV_TestEntityPosition(sv_player))
{
vec3_t forward, right, up;
AngleVectors(sv_player->v.v_angle, forward, right, up);

if (!FindPassableSpace(sv_player, forward, 1.0)
&& !FindPassableSpace(sv_player, right, 1.0)
&& !FindPassableSpace(sv_player, right, -1.0) // left
&& !FindPassableSpace(sv_player, up, 1.0) // up
&& !FindPassableSpace(sv_player, up, -1.0) // down
&& !FindPassableSpace(sv_player, forward, -1.0)) // back
{
Con_DPrintf("Can't find the world\n");
}

VectorCopy(sv_player->v.oldorigin, sv_player->v.origin);
}
}
}

void Host_Ping_f(void)
{
int i;
Expand Down Expand Up @@ -3146,11 +3251,12 @@ void Host_InitCommands(void)
Cmd_AddCommand("setinfo", Host_SetInfo_f);
Cmd_AddCommand("fullinfo", Host_FullInfo_f);

#ifndef SWDS
Cmd_AddCommand("god", Host_God_f);
Cmd_AddCommand("notarget", Host_Notarget_f);
Cmd_AddCommand("fly", Host_Fly_f);
Cmd_AddCommand("noclip", Host_Noclip_f);

#ifndef SWDS
Cmd_AddCommand("fly", Host_Fly_f);
Cmd_AddCommand("viewmodel", Host_Viewmodel_f);
Cmd_AddCommand("viewframe", Host_Viewframe_f);
Cmd_AddCommand("viewnext", Host_Viewnext_f);
Expand Down
2 changes: 1 addition & 1 deletion rehlds/engine/sv_user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ edict_t *sv_player;
qboolean nofind;

#if defined(SWDS) && defined(REHLDS_FIXES)
const char *clcommands[] = { "status", "name", "kill", "pause", "spawn", "new", "sendres", "dropclient", "kick", "ping", "dlfile", "setinfo", "sendents", "fullupdate", "setpause", "unpause", NULL };
const char *clcommands[] = { "status", "name", "kill", "pause", "spawn", "new", "sendres", "dropclient", "kick", "ping", "dlfile", "setinfo", "sendents", "fullupdate", "setpause", "unpause", "noclip", "god", "notarget", NULL };
#else
const char *clcommands[23] = { "status", "god", "notarget", "fly", "name", "noclip", "kill", "pause", "spawn", "new", "sendres", "dropclient", "kick", "ping", "dlfile", "nextdl", "setinfo", "showinfo", "sendents", "fullupdate", "setpause", "unpause", NULL };
#endif
Expand Down

0 comments on commit 7fcec97

Please sign in to comment.