Registering Weapons - T-Rizzle12/Custom-Gmod-Bot GitHub Wiki
Intro
Welcome to the registering weapons page, you are probably here because you want to register a weapon so the bots know how to use them.
The ways to register a weapon
There are three ways to register a weapon
- Using the TBotRegisterWeapon console command
- Using the TRizzleBotRegisterWeaponMenu console command [Recommended]
- You create an addon and use the RegisterTBotWeapon function
Registering a weapon using TBotRegisterWeapon
To register a weapon using the TBotRegisterWeapon console command you need the weapon you are trying to register's class name. You can get this by right-clicking the weapon in the spawn menu and selecting the copy option. This should add the weapon's class name to your clipboard. Now there are two required arguments to the console command, after that, the addon will assume the default parameters.
The first parameter is the class name all you would have to do is type or paste in the class name.
The second parameter is the weapon type there are currently 7 available weapon types, Rifle, Melee, Pistol, Sniper, Shotgun, Explosive, and Grenade. Just type in the weapon type based on the type of weapon you are registering.
The third parameter is if the weapon has a scope, you should either enter 1 [Yes] or 0 [No].
The fourth parameter is if the weapon has a secondary attack, once again you should either enter 1 [Yes] or 0 [No].
The fifth parameter is the time before the bot can use the secondary attack again, by default this is 30 seconds, you can set this to any valid number.
The sixth parameter is the maximum stored ammo, if you set this to 0 the default is 6 clips of ammo, if you choose a number greater than 0 that will be the total amount of ammo carried.
The seventh parameter is if the bot should ignore the automatic range system, if you set this to 1 [Yes] then the bot will always press and hold its attack button when firing this weapon if it is automatic. If you set it to 0 [No] then the bot will fire in bursts if the enemy is far away.
The eighth and final parameter is if the bot should wait until the clip is fully loaded after reading from an empty clip before it can fire again. Set it to 1 [Yes] to have the bot when reloading from empty wait until the clip is full before firing again or set it to 0 [No] to fire as soon as there is one bullet in the weapon. The bot will always press and hold if an enemy is close.
You can now hit enter and the weapon will now be registered.
Registering a weapon using TRizzleBotRegisterWeaponMenu
Registering a weapon using the TRizzleBotRegisterWeaponMenu console command is easy. Once you enter the command a derma menu will open with every option available. The menu will automatically collect every available weapon's class name on the server and put them on a scroll bar list. Now all you have to do is fill out the rest of the menu and hit the Register/Update Weapon button when you are finished. Once you hit the button the weapon will be registered and is ready for bot use.
Registering a weapon using the RegisterTBotWeapon function
[NOTE]: This is only for addon creators or players who don't want to register the weapon every time they change maps. All you have to do is use the RegisterTBotWeapon function to register the weapon. The function only accepts one parameter and that is a table with the following arguments:
- ClassName = [string]
- WeaponType = [string] -- This must be either Rifle, Melee, Pistol, Sniper, Shotgun, Explosive, or Grenade.
- HasScope = [bool] -- This is optional
- HasSecondaryAttack = [bool] -- This is optional
- SecondaryAttackCooldown = [Number] -- This is optional
- MaxStoredAmmo = [Number] -- This is optional
- IgnoreAutomaticRange = [bool] -- This is optional
- ReloadsSingly = [bool] -- This is optional. The bot will assume true for shotguns and false for everything else.
Once your lua file loads your weapon should be registered. I recommend putting this a hook with the event name set as TRizzleBotInitialized. TRizzleBotInitialized is called once this addon is completely initialized and will guarantee that you can register the weapons.