Skip to content

Commit

Permalink
[game:console] A console command 'dm_pickup' to pick up an item by 'id'.
Browse files Browse the repository at this point in the history
Example use from Lua:
  local game = 'require dmlab.system.game'
  game:console('dm_pickup ' .. id)
  • Loading branch information
charlesbeattie authored and tkoeppe committed May 22, 2018
1 parent 4ef7980 commit 228de34
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
1 change: 1 addition & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
1. Add support for absl::variant to lua::Push and lua::Read.
2. The demo `:game` has a new flag `--start_index` to start at an episode index
other than 0.
3. Add a console command `dm_pickup` to pick up an item identified by its `id`.

## release-2018-05-15 May 2018 release

Expand Down
27 changes: 17 additions & 10 deletions docs/developers/reference/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -639,16 +639,23 @@ materials to for the commands available.

Here are some examples:

Command | Effect
------------------ | ------------------------------------
set <cvar> <value> | Sets any internal <cvar> to <value>.
set cg_drawFPS 1 | Draws the FPS counter to the screen
set cg_fov 70 | Sets hoizontal field of view to 70.
weapon <number> | Selects <number> gadget.
weapon 1 | Selects first gadget.
weapon 2 | Selects second gadget.
weapnext | Selects next gadget.
weapprev | Selects previous gadget.
Command | Effect
-------------------- | -----------------------------------------
set <cvar> <value> | Sets any internal <cvar> to <value>.
set cg_drawFPS 1 | Draws the FPS counter to the screen
set cg_fov 70 | Sets hoizontal field of view to 70.
weapon <number> | Selects <number> gadget.
weapon 1 | Selects first gadget.
weapon 2 | Selects second gadget.
weapnext | Selects next gadget.
weapprev | Selects previous gadget.
setviewpos x y z yaw | Sets the player's x y z location and yaw.

Here are some custom commands:

Command | Effect
------------ | --------------------------------------------------
dm_pickup id | Lets the player pickup all items with the id 'id'.

### `finishMap`()

Expand Down
31 changes: 31 additions & 0 deletions engine/code/game/g_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1677,7 +1677,36 @@ void Cmd_SetViewpos_f( gentity_t *ent ) {
TeleportPlayer( ent, origin, angles );
}

void Cmd_Pickup_f( gentity_t *ent ) {
gentity_t *e;
int id, i;
char buffer[MAX_TOKEN_CHARS];

if ( !g_cheats.integer ) {
trap_SendServerCommand( ent-g_entities, "print \"Cheats are not enabled on this server.\n\"" );
return;
}
if ( trap_Argc() == 3 ) {
trap_Argv( 2, buffer, sizeof( buffer ) );
i = ClientNumberFromString( ent, buffer, qtrue, qtrue );
if (i == -1) {
trap_SendServerCommand( ent-g_entities, "print \"Invalid player name\n\"");
return;
}
ent = &g_entities[i];
} else if ( trap_Argc() != 2 ) {
trap_SendServerCommand( ent-g_entities, "print \"usage: pickup id <optional player name>\n\"" );
return;
}
trap_Argv( 1, buffer, sizeof( buffer ) );
id = atoi( buffer );
for (i = 0; i < level.num_entities; i++) {
e = &g_entities[i];
if (e->id && id == e->id) {
Touch_Item( e, ent, NULL );
}
}
}

/*
=================
Expand Down Expand Up @@ -1817,6 +1846,8 @@ void ClientCommand( int clientNum ) {
Cmd_SetViewpos_f( ent );
else if (Q_stricmp (cmd, "stats") == 0)
Cmd_Stats_f( ent );
else if (Q_stricmp (cmd, "dm_pickup") == 0)
Cmd_Pickup_f( ent );
else
trap_SendServerCommand( clientNum, va("print \"unknown cmd %s\n\"", cmd ) );
}

0 comments on commit 228de34

Please sign in to comment.