📄 cmd.java
字号:
// check cvars if (Cvar.Command()) return; // send it as a server command if we are connected Cmd.ForwardToServer(); } /** * Cmd_Give_f * * Give items to a client. */ public static void Give_f(edict_t ent) { String name; gitem_t it; int index; int i; boolean give_all; edict_t it_ent; if (GameBase.deathmatch.value != 0 && GameBase.sv_cheats.value == 0) { SV_GAME.PF_cprintfhigh(ent, "You must run the server with '+set cheats 1' to enable this command.\n"); return; } name = Cmd.Args(); if (0 == Lib.Q_stricmp(name, "all")) give_all = true; else give_all = false; if (give_all || 0 == Lib.Q_stricmp(Cmd.Argv(1), "health")) { if (Cmd.Argc() == 3) ent.health = Lib.atoi(Cmd.Argv(2)); else ent.health = ent.max_health; if (!give_all) return; } if (give_all || 0 == Lib.Q_stricmp(name, "weapons")) { for (i = 1; i < GameBase.game.num_items; i++) { it = GameItemList.itemlist[i]; if (null == it.pickup) continue; if (0 == (it.flags & Defines.IT_WEAPON)) continue; ent.client.pers.inventory[i] += 1; } if (!give_all) return; } if (give_all || 0 == Lib.Q_stricmp(name, "ammo")) { for (i = 1; i < GameBase.game.num_items; i++) { it = GameItemList.itemlist[i]; if (null == it.pickup) continue; if (0 == (it.flags & Defines.IT_AMMO)) continue; GameItems.Add_Ammo(ent, it, 1000); } if (!give_all) return; } if (give_all || Lib.Q_stricmp(name, "armor") == 0) { gitem_armor_t info; it = GameItems.FindItem("Jacket Armor"); ent.client.pers.inventory[GameItems.ITEM_INDEX(it)] = 0; it = GameItems.FindItem("Combat Armor"); ent.client.pers.inventory[GameItems.ITEM_INDEX(it)] = 0; it = GameItems.FindItem("Body Armor"); info = (gitem_armor_t) it.info; ent.client.pers.inventory[GameItems.ITEM_INDEX(it)] = info.max_count; if (!give_all) return; } if (give_all || Lib.Q_stricmp(name, "Power Shield") == 0) { it = GameItems.FindItem("Power Shield"); it_ent = GameUtil.G_Spawn(); it_ent.classname = it.classname; GameItems.SpawnItem(it_ent, it); GameItems.Touch_Item(it_ent, ent, GameBase.dummyplane, null); if (it_ent.inuse) GameUtil.G_FreeEdict(it_ent); if (!give_all) return; } if (give_all) { for (i = 1; i < GameBase.game.num_items; i++) { it = GameItemList.itemlist[i]; if (it.pickup != null) continue; if ((it.flags & (Defines.IT_ARMOR | Defines.IT_WEAPON | Defines.IT_AMMO)) != 0) continue; ent.client.pers.inventory[i] = 1; } return; } it = GameItems.FindItem(name); if (it == null) { name = Cmd.Argv(1); it = GameItems.FindItem(name); if (it == null) { SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "unknown item\n"); return; } } if (it.pickup == null) { SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "non-pickup item\n"); return; } index = GameItems.ITEM_INDEX(it); if ((it.flags & Defines.IT_AMMO) != 0) { if (Cmd.Argc() == 3) ent.client.pers.inventory[index] = Lib.atoi(Cmd.Argv(2)); else ent.client.pers.inventory[index] += it.quantity; } else { it_ent = GameUtil.G_Spawn(); it_ent.classname = it.classname; GameItems.SpawnItem(it_ent, it); GameItems.Touch_Item(it_ent, ent, GameBase.dummyplane, null); if (it_ent.inuse) GameUtil.G_FreeEdict(it_ent); } } /** * Cmd_God_f * * Sets client to godmode * * argv(0) god */ public static void God_f(edict_t ent) { String msg; if (GameBase.deathmatch.value != 0 && GameBase.sv_cheats.value == 0) { SV_GAME.PF_cprintfhigh(ent, "You must run the server with '+set cheats 1' to enable this command.\n"); return; } ent.flags ^= Defines.FL_GODMODE; if (0 == (ent.flags & Defines.FL_GODMODE)) msg = "godmode OFF\n"; else msg = "godmode ON\n"; SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, msg); } /** * Cmd_Notarget_f * * Sets client to notarget * * argv(0) notarget. */ public static void Notarget_f(edict_t ent) { String msg; if (GameBase.deathmatch.value != 0 && GameBase.sv_cheats.value == 0) { SV_GAME.PF_cprintfhigh(ent, "You must run the server with '+set cheats 1' to enable this command.\n"); return; } ent.flags ^= Defines.FL_NOTARGET; if (0 == (ent.flags & Defines.FL_NOTARGET)) msg = "notarget OFF\n"; else msg = "notarget ON\n"; SV_GAME.PF_cprintfhigh(ent, msg); } /** * Cmd_Noclip_f * * argv(0) noclip. */ public static void Noclip_f(edict_t ent) { String msg; if (GameBase.deathmatch.value != 0 && GameBase.sv_cheats.value == 0) { SV_GAME.PF_cprintfhigh(ent, "You must run the server with '+set cheats 1' to enable this command.\n"); return; } if (ent.movetype == Defines.MOVETYPE_NOCLIP) { ent.movetype = Defines.MOVETYPE_WALK; msg = "noclip OFF\n"; } else { ent.movetype = Defines.MOVETYPE_NOCLIP; msg = "noclip ON\n"; } SV_GAME.PF_cprintfhigh(ent, msg); } /** * Cmd_Use_f * * Use an inventory item. */ public static void Use_f(edict_t ent) { int index; gitem_t it; String s; s = Cmd.Args(); it = GameItems.FindItem(s); Com.dprintln("using:" + s); if (it == null) { SV_GAME.PF_cprintfhigh(ent, "unknown item: " + s + "\n"); return; } if (it.use == null) { SV_GAME.PF_cprintfhigh(ent, "Item is not usable.\n"); return; } index = GameItems.ITEM_INDEX(it); if (0 == ent.client.pers.inventory[index]) { SV_GAME.PF_cprintfhigh(ent, "Out of item: " + s + "\n"); return; } it.use.use(ent, it); } /** * Cmd_Drop_f * * Drop an inventory item. */ public static void Drop_f(edict_t ent) { int index; gitem_t it; String s; s = Cmd.Args(); it = GameItems.FindItem(s); if (it == null) { SV_GAME.PF_cprintfhigh(ent, "unknown item: " + s + "\n"); return; } if (it.drop == null) { SV_GAME.PF_cprintf(ent, Defines.PRINT_HIGH, "Item is not dropable.\n"); return; } index = GameItems.ITEM_INDEX(it); if (0 == ent.client.pers.inventory[index]) { SV_GAME.PF_cprintfhigh(ent, "Out of item: " + s + "\n"); return; } it.drop.drop(ent, it); } /** * Cmd_Inven_f. */ public static void Inven_f(edict_t ent) { int i; gclient_t cl; cl = ent.client; cl.showscores = false; cl.showhelp = false; if (cl.showinventory) { cl.showinventory = false; return; } cl.showinventory = true; GameBase.gi.WriteByte(Defines.svc_inventory); for (i = 0; i < Defines.MAX_ITEMS; i++) { GameBase.gi.WriteShort(cl.pers.inventory[i]); } GameBase.gi.unicast(ent, true); } /** * Cmd_InvUse_f. */ public static void InvUse_f(edict_t ent) { gitem_t it; Cmd.ValidateSelectedItem(ent); if (ent.client.pers.selected_item == -1) { SV_GAME.PF_cprintfhigh(ent, "No item to use.\n"); return; } it = GameItemList.itemlist[ent.client.pers.selected_item]; if (it.use == null) { SV_GAME.PF_cprintfhigh(ent, "Item is not usable.\n"); return; } it.use.use(ent, it); } /** * Cmd_WeapPrev_f. */ public static void WeapPrev_f(edict_t ent) { gclient_t cl; int i, index; gitem_t it; int selected_weapon; cl = ent.client; if (cl.pers.weapon == null) return; selected_weapon = GameItems.ITEM_INDEX(cl.pers.weapon); // scan for the next valid one for (i = 1; i <= Defines.MAX_ITEMS; i++) { index = (selected_weapon + i) % Defines.MAX_ITEMS; if (0 == cl.pers.inventory[index]) continue; it = GameItemList.itemlist[index]; if (it.use == null) continue; if (0 == (it.flags & Defines.IT_WEAPON)) continue; it.use.use(ent, it); if (cl.pers.weapon == it) return; // successful } } /** * Cmd_WeapNext_f. */ public static void WeapNext_f(edict_t ent) { gclient_t cl; int i, index; gitem_t it; int selected_weapon; cl = ent.client; if (null == cl.pers.weapon) return; selected_weapon = GameItems.ITEM_INDEX(cl.pers.weapon); // scan for the next valid one for (i = 1; i <= Defines.MAX_ITEMS; i++) { index = (selected_weapon + Defines.MAX_ITEMS - i) % Defines.MAX_ITEMS; //bugfix rst if (index == 0) index++; if (0 == cl.pers.inventory[index]) continue; it = GameItemList.itemlist[index]; if (null == it.use) continue; if (0 == (it.flags & Defines.IT_WEAPON)) continue; it.use.use(ent, it); if (cl.pers.weapon == it) return; // successful } } /** * Cmd_WeapLast_f. */ public static void WeapLast_f(edict_t ent) { gclient_t cl; int index; gitem_t it; cl = ent.client; if (null == cl.pers.weapon || null == cl.pers.lastweapon) return; index = GameItems.ITEM_INDEX(cl.pers.lastweapon); if (0 == cl.pers.inventory[index]) return; it = GameItemList.itemlist[index]; if (null == it.use) return; if (0 == (it.flags & Defines.IT_WEAPON)) return; it.use.use(ent, it); } /** * Cmd_InvDrop_f */ public static void InvDrop_f(edict_t ent) { gitem_t it; Cmd.ValidateSelectedItem(ent); if (ent.client.pers.selected_item == -1) { SV_GAME.PF_cprintfhigh(ent, "No item to drop.\n"); return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -