Skip to content

Weapons Module

George Petrou edited this page Aug 4, 2018 · 4 revisions

About this module

This module handles functions, hooks, and convars related to weapons, their spawning, import scripts, and other general weapon data. It also has to do with overriding or "redirecting" certain entities so that they spawn another entity. This is done to for example convert all weapon_zm_revolver entities to weapon_ttt_deagle entities. More on this is explained in the Entity Redirects section below.

Import Scripts

Old weapon import scripts are completely supported, you can even still use the old tool that Badking made for this. I may eventually create my own tool that supports more custom entities but for the time being its perfectly fine to use Badking's old one.

Entity Redirects

The entity and weapon redirect system handles the replacement certain map entities by other entities. You can see currently redirected entities in sh_entity_redirects.lua, specifically with the TTT.Weapons.RedirectedEntities and TTT.Weapons.RedirectedWeapons tables. You can add a new redirect by following the same form as the other entities/weapons. Below is a simple template:

TTT.Weapons.RedirectedWeapons["myWeaponClass"] = {
	Base = "weaponClassToInheritFrom",
	AnyOtherKey = "anyOtherValue"
}
TTT.Weapons.RedirectedEntities["myEntityClass"] = {
	Base = "entityClassToInheritFrom",
	AnyOtherKey = "anyOtherValue"
}

You can see that you can also add any other variables to the weapon/entity class. For example: print(weapons.Get("myEntityClass").AnyOtherKey) would output "anyOtherValue". All original TTT weapons and entities are given the IsOriginalTTTEntity variable set to true. Every single redirected entity is given the IsConvertedEntity variable set to true.

Enumerations

Weapon Kinds:

  • WEAPON_INVALID = 0
  • WEAPON_UNARMED = 1
  • WEAPON_MELEE = 2
  • WEAPON_CARRY = 3
  • WEAPON_PRIMARY = 4
  • WEAPON_SECONDARY = 5
  • WEAPON_GRENADE = 6
  • WEAPON_EQUIP1 = 7
  • WEAPON_EQUIP2 = 8
  • WEAPON_SPECIALEQUIP = 9

Each weapon must be given a Kind set to one of these enums in order to determine what slot the weapon takes up.

Crowbar Door Open Types:

  • OPEN_NO = 0
  • OPEN_ROT = 1
  • OPEN_DOOR = 2
  • OPEN_BUT = 3
  • OPEN_NOTOGGLE = 4

These enumerations are used to determine an entity's openability by the crowbar. OPEN_NO means the crowbar cannot open the entity.

Ammo Types

I simplified all ammo names down to the below list. You can see their definitions in sh_weapons.lua.

  • ar
  • pistol_heavy
  • pistol_light
  • sniper
  • shotgun_buckshot
  • none

Console Variables

ConVar Default Value Flags/Realm Description
ttt_weapon_spawn_count 0 Server, Archived How many extra weapons to spawn on unarmed CSS/TF2 maps missing import scripts. 0 for max player count + 3.
ttt_weapon_use_import_scripts 1 Server, Archived Should we use weapon import scripts.

Hooks

TODO: Add should redirect hooks here

TTT.Weapons.CanDropWeapon - Server

  • Desc: Can the given player drop their current weapon.
  • Arg One: Player, who wants to drop a weapon.
  • Arg Two: Weapon, weapon they want to drop.
  • Returns: Boolean, can they drop the weapon.

TTT.Weapons.DroppedWeapon - Server

  • Desc: Called when the player dropped their weapon..
  • Arg One: Player, who dropped their weapon.
  • Arg Two: Weapon, that they just dropped.

TTT.Weapons.CanDropActiveAmmo - Server

  • Desc: Can the given player drop their current weapon's ammo.
  • Arg One: Player, who wants to drop their active weapon's ammo.
  • Arg Two: Weapon, that they will be dropping ammo from.
  • Arg Three: String, ammo entity class that would be created.
  • Returns: Boolean, can they drop the ammo.

TTT.Weapons.PlayerDroppedActiveAmmo - Server

  • Desc: Called when the player dropped their ammo..
  • Arg One: Player, who dropped their ammo.
  • Arg Two: Weapon, where the ammo they dropped came from.
  • Arg Three: Entity, the ammo box produced when dropping the ammo.

TTT.Weapons.ShouldUseImportScript - Server

  • Desc: Should the server use weapon import scripts for this map.
  • Arg One: String, map name of the current map.
  • Returns: Boolean, false to disable import scripts.

Functions

TTT.Weapons.RedirectEntities - Shared

  • Desc: Redirects all entities on the map to their specified counterparts.

TTT.Weapons.RedirectWeapons - Shared

  • Desc: Redirects all weapons on the map to their specified counterparts.

TTT.Weapons.RedirectMapEntities - Shared

  • Desc: Redirects all entities and weapons on the map.

TTT.Weapons.HasWeaponInSlot - Shared

  • Desc: Sees if the player has a weapon in the given slot.
  • Arg One: Player, who were checking weapons for.
  • Arg Two: WEAPON_ enum, slot we are checking for.
  • Returns: Boolean, do they have a weapon in that slot.

TTT.Weapons.HasWeaponAmmoForType - Shared

  • Desc: Sees if the player has a weapon that takes a given type of ammo.
  • Arg One: Player, who were checking weapons for.
  • Arg Two: String, ammo type.
  • Returns: Boolean, do they have a weapon that accepts the given ammo type.

TTT.Weapons.GetWeaponInSlot - Shared

  • Desc: Gets what weapon a player has in a given slot.
  • Arg One: Player, we are checking the weapons of.
  • Arg Two: WEAPON_ enum, slot we are looking for.
  • Returns: Weapon or Boolean. Weapon if a weapon was found in the slot, false if not.

TTT.Weapons.GetMapSpawnableWeapons - Shared

  • Desc: Gets all weapons that can spawn around the map.
  • Returns: Table, list of all map spawnable weapons.

TTT.Weapons.GetMapSpawnableAmmo - Shared

  • Desc: Gets all ammo types that can spawn around the map.
  • Returns: Table, list of all map spawnable ammo.

TTT.Weapons.GetAmmoEntityForWeapon - Shared

  • Desc: Gets what kind of ammo entity, not ammo type, the given weapon accepts.
  • Arg One: String, weapon class.
  • Returns: String or nil. String of the ammo entity class this weapon accepts, nil if it uses the "none" ammo.

TTT.Weapons.RequestDropCurrentWeapon - Client

  • Desc: Asks the server if we can drop our current weapon and drops it if we can.

TTT.Weapons.RequestDropCurrentAmmo - Client

  • Desc: Asks the server if we can drop our current weapon's ammo and drops it if we can.

TTT.Weapons.CanDropWeapon - Server

  • Desc: Sees if the player can drop one of their weapons.
  • Arg One: Player, who wants to drop one of their weapons.
  • Arg Two: Weapon, that they want to drop.
  • Returns: Boolean, can they drop that weapon.

TTT.Weapons.DropWeapon - Server

  • Desc: Drops the player's weapon.
  • Arg One: Player, who wants to drop a weapon.
  • Arg Two: Weapon, that they want to drop.
  • Arg Three: Boolean, are they dropping this weapon because they died.

TTT.Weapons.CanDropActiveAmmo - Server

  • Desc: Sees if the player can drop ammo for their active weapon.
  • Arg One: Player, who wants to drop ammo.
  • Returns: Boolean, can they drop ammo for their active weapon.

TTT.Weapons.DropActiveAmmo - Server

  • Desc: Drops ammo from the player's active weapon's clip.
  • Arg One: Player, to drop ammo from.
  • Returns: Entity or nil. Entity of the created ammo box, nil if one wasn't able to be made.

TTT.Weapons.GetOpennableEntityType - Shared

  • Desc: Gets the type of OPEN_ enum for the given opennable entity.
  • Arg One: Entity, to see its crowbar open type.
  • Returns: OPEN_ enum, what type of crowbar open entity is this. OPEN_NO for unopenable.

TTT.Weapons.CanOpenType - Shared

  • Desc: Sees if we can open the given OPEN type.
  • Arg One: OPEN_ enum, to see if we can open.
  • Returns: Boolean, can we open entities with this OPEN type.

TTT.Weapons.OpenEntity - Shared

  • Desc: Attempts to open the given entity type.
  • Arg One: Entity, to try to open.
  • Returns: OPEN_ enum, of that door. Will be OPEN_NO if it couldn't be opened.

Home

Modules

Clone this wiki locally