Hello. I’ve started a project that revolves around making the current bots in Gmod go from the dumb little crapheads they are to deathmatch-oriented AI that people can have fun with. My next step after getting a targeting system down(which I’ve successfully done :D) is getting them to keep moving upon them being shot. Normally, they’d just stand where they are and never move until they’re killed and they respawn. How would I, in a .lua file in GarrysMod/garrysmod/lua/autorun, overright this?
Use the StartCommand hook to modify the buttons that the bot is pressing.
Can you give me an example? I’ve never heard of StartCommand(I looked at the wiki page, though)
This should (untested right now) make all bots run forward:
[lua]local function ControlBots(ply, cmd)
–Ignore real players
if not ply:IsBot() then return end
--Get the current keys pressed (probably none since they are a bot) local KeysPressed = cmd:GetButtons() --Add your keys into the mix KeysPressed = bit.bor( KeysPressed, IN_FORWARD) --Apply the keys to the movecommand cmd:SetButtons(KeysPressed)
You would need your own (AI) logic for making each bot have its own individual set of actions.
Wouldn’t editing GM:PlayerHurt()(for bots) also work?
[editline]3rd May 2015[/editline]
Would this override every action they do, instead replacing it? If so, this probably isn’t the best method. Also, if it works correctly, wouldn’t the best way to do this be like:
local function GM:PlayerHurt(ply) If not ply:IsBot() then return end ControlBots() end
Umm… I’d need help with making an individual bot do this… Not every single one…
I can’t say how it would interact with the normal bot behaviour, when I used I wanted to override their default behaviour.
I don’t mean to advertise but if you want to see it in action look for ‘Hell (infinite death match vs bots)’ in the Sandbox servers.
Wait. For making the code work only on individual bots, not every bot on the server, wouldn’t adding
if ply:IsBot() then
to your ControlBots() function work? ply can be used locally iirc.