Skip to content

Commit 228de34

Browse files
charlesbeattietkoeppe
authored andcommitted
[game:console] A console command 'dm_pickup' to pick up an item by 'id'.
Example use from Lua: local game = 'require dmlab.system.game' game:console('dm_pickup ' .. id)
1 parent 4ef7980 commit 228de34

File tree

3 files changed

+49
-10
lines changed

3 files changed

+49
-10
lines changed

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
1. Add support for absl::variant to lua::Push and lua::Read.
2424
2. The demo `:game` has a new flag `--start_index` to start at an episode index
2525
other than 0.
26+
3. Add a console command `dm_pickup` to pick up an item identified by its `id`.
2627

2728
## release-2018-05-15 May 2018 release
2829

docs/developers/reference/lua_api.md

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -639,16 +639,23 @@ materials to for the commands available.
639639

640640
Here are some examples:
641641

642-
Command | Effect
643-
------------------ | ------------------------------------
644-
set <cvar> <value> | Sets any internal <cvar> to <value>.
645-
set cg_drawFPS 1 | Draws the FPS counter to the screen
646-
set cg_fov 70 | Sets hoizontal field of view to 70.
647-
weapon <number> | Selects <number> gadget.
648-
weapon 1 | Selects first gadget.
649-
weapon 2 | Selects second gadget.
650-
weapnext | Selects next gadget.
651-
weapprev | Selects previous gadget.
642+
Command | Effect
643+
-------------------- | -----------------------------------------
644+
set <cvar> <value> | Sets any internal <cvar> to <value>.
645+
set cg_drawFPS 1 | Draws the FPS counter to the screen
646+
set cg_fov 70 | Sets hoizontal field of view to 70.
647+
weapon <number> | Selects <number> gadget.
648+
weapon 1 | Selects first gadget.
649+
weapon 2 | Selects second gadget.
650+
weapnext | Selects next gadget.
651+
weapprev | Selects previous gadget.
652+
setviewpos x y z yaw | Sets the player's x y z location and yaw.
653+
654+
Here are some custom commands:
655+
656+
Command | Effect
657+
------------ | --------------------------------------------------
658+
dm_pickup id | Lets the player pickup all items with the id 'id'.
652659

653660
### `finishMap`()
654661

engine/code/game/g_cmds.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,7 +1677,36 @@ void Cmd_SetViewpos_f( gentity_t *ent ) {
16771677
TeleportPlayer( ent, origin, angles );
16781678
}
16791679

1680+
void Cmd_Pickup_f( gentity_t *ent ) {
1681+
gentity_t *e;
1682+
int id, i;
1683+
char buffer[MAX_TOKEN_CHARS];
16801684

1685+
if ( !g_cheats.integer ) {
1686+
trap_SendServerCommand( ent-g_entities, "print \"Cheats are not enabled on this server.\n\"" );
1687+
return;
1688+
}
1689+
if ( trap_Argc() == 3 ) {
1690+
trap_Argv( 2, buffer, sizeof( buffer ) );
1691+
i = ClientNumberFromString( ent, buffer, qtrue, qtrue );
1692+
if (i == -1) {
1693+
trap_SendServerCommand( ent-g_entities, "print \"Invalid player name\n\"");
1694+
return;
1695+
}
1696+
ent = &g_entities[i];
1697+
} else if ( trap_Argc() != 2 ) {
1698+
trap_SendServerCommand( ent-g_entities, "print \"usage: pickup id <optional player name>\n\"" );
1699+
return;
1700+
}
1701+
trap_Argv( 1, buffer, sizeof( buffer ) );
1702+
id = atoi( buffer );
1703+
for (i = 0; i < level.num_entities; i++) {
1704+
e = &g_entities[i];
1705+
if (e->id && id == e->id) {
1706+
Touch_Item( e, ent, NULL );
1707+
}
1708+
}
1709+
}
16811710

16821711
/*
16831712
=================
@@ -1817,6 +1846,8 @@ void ClientCommand( int clientNum ) {
18171846
Cmd_SetViewpos_f( ent );
18181847
else if (Q_stricmp (cmd, "stats") == 0)
18191848
Cmd_Stats_f( ent );
1849+
else if (Q_stricmp (cmd, "dm_pickup") == 0)
1850+
Cmd_Pickup_f( ent );
18201851
else
18211852
trap_SendServerCommand( clientNum, va("print \"unknown cmd %s\n\"", cmd ) );
18221853
}

0 commit comments

Comments
 (0)