-
Notifications
You must be signed in to change notification settings - Fork 2
How do I make my own bot?
Hello! This page will teach you how to create your own bot!
This is NOT a LUA tutorial.
Open the addon, and then open lua.
Open GMBots, and you should see abunch of lua files for each gamemode.
Clone base.lua, and rename it to the gamemode's file name (Same name as if you were typing "gamemode [name]" in console.)
Open the file you just cloned.
This file has a example bot, but it isn't too great.
- The "GMBotsStart" function is the "brains" of your bot.
- The "GMBotsBotAdded" hook gets called when a bot is added.
- The "BOTNames" table says what names the bots will use.
Each BOT Name will have a prefix. Due to a bug, Bot Quota WILL NOT have the chosen BOT Names until they get kicked, and rejoin.
See the Functions page for functions you can use!
Here, we will make our own "PvP" bot, for an example.
Scroll down to GMBotsStart, and delete everything INSIDE the function.
Now, add in that function
if ply and ply:IsValid() and cmd then
end
NOTE: You actually don't need to do this, but it helps either way.
Now, inside that "if" statement, add
if ply.Enemy and ply.Enemy:IsValid() and ply.Enemy:IsPlayer() and ply.Enemy:Alive() then
else
ply.Enemy = nil
ply.Enemy = ply:LookForPlayers()
end
This will make the bot search for players, until it finds somebody.
If you like, you can also add Player:BotWander, check the Functions page for details.
Now, under if ply.Enemy then
add
ply:BotAttack(cmd,ply.Enemy)
This will make the bot attack the enemy, this function WILL NOT switch weapons for you.
To make a bot switch weapons, use cmd:SelectWeapon or Player:SelectWeapon.
Your bot should now work!
You can modify this bot to your liking! GMBots will auto-load it on the correct gamemode!