• gmsv_bot - Bot Module
    77 replies, posted
  • Provides various functions for the creation and control of bots. [b]Changelog:[/b] [list] [*]Moved the controller functions into the bot controller metatable. [/list] [b]Download( source included ):[/b] [url=http://cdbarrett.com/downloads/botmodule2.zip]Link[/url] [b]Functions:[/b] [list] [*]bot.Create( [name] ) - [i]Creates a bot with the given name and returns a controller and the newly created bot entity.[/i] [*]BOTCONTROLLER:Run( [forward], [side], [up], [viewangles], [buttons], [impulse], [weapon select], [weapon subtype] ) - [i]Run the bot, move it around, etc.[/i] [*]BOTCONTROLLER:ExecCommand( [command] ) - [i]Runs the given command on the bot.[/i] [*]BOTCONTROLLER:RemoveAllItems( ) - [i]Remove all the bot's items.[/i] [*]BOTCONTROLLER:SetActiveWeapon( [weapon] ) - [i]Gives the bot a weapon.[/i] [*]BOTCONTROLLER:SetConVar( [var], [value] ) - [i]Sets a client convar on the bot.[/i] [*]BOTCONTROLLER:IsEFlagSet( [flag] ) - [i]Checks if an effect flag is set.[/i] [*]BOTCONTROLLER:PostClientMessagesSent( ) [/list] [b]Defines:[/b] [list] [*]EFL_BOT_FROZEN [/list] [b]Example:[/b] [lua] // Bot module. require( "bot" ); //require( "botx" ); // create our bot. local controller, entity = bot.Create( "MingeBag 2.0" ); //local buttons = botx.CreateButtonsHelper(); local viewangle = Angle( 0, 0, 0 ); local aim_at_player = true; // just make it walk forward. local function botThink( ) // no bot? if( !entity:IsValid() ) then return; end // aim at nearest player. if( aim_at_player ) then // closest dist. local closest, dist = nil, 8192; local list, pl = player.GetAll(); for _, pl in pairs( list ) do // closer? local length = ( pl:GetPos() - entity:GetPos() ):Length(); if( pl != entity && length < dist ) then dist = length; closest = pl; end end // found? if( closest ) then // aim. viewangle = ( closest:GetShootPos() - entity:GetShootPos() ):Normalize():Angle(); end // increment angle. else viewangle.y = viewangle.y + 50 * FrameTime(); if( viewangle.y > 360 ) then viewangle.y = 0; end end // set bot angle. entity:SetLocalAngles( viewangle ); // walk. controller:Run( 190, // forward ( walk ) 0, // side ( strafe ) 0, // up ( swim, I think ) viewangle, // view angles 0, // buttons 0, // impulse 0, // weapon select 0 // weapon sub type ); // controller:PostClientMessagesSent( ); end hook.Add( "Think", "BotThink", botThink ); [/lua]
  • Avatar of Megiddo
  • Nice, I see you used my lua module server plugin method. Glad I could help someone. :D
  • Avatar of Elspin
  • Jinto, you win all the internet. [b]Edit:[/b] [QUOTE=Jinto][lua] // Bot module. require( "bot" ); // create our bot. local controller, entity = bot.Create( "MingeBag 2.0" ); local viewangle = Angle( 0, 0, 0 ); local aim_at_player = true; // just make it walk forward. local function botThink( ) // no bot? if( !entity:IsValid() ) then return; end // aim at nearest player. if( aim_at_player ) then // closest dist. local closest, dist = nil, 8192; local list, pl = player.GetAll(); for _, pl in pairs( list ) do // closer? local length = ( pl:GetPos() - entity:GetPos() ):Length(); if( pl != entity && length < dist ) then dist = length; closest = pl; end end // found? if( closest ) then // aim. viewangle = ( closest:GetShootPos() - entity:GetShootPos() ):Normalize():Angle(); end // increment angle. else viewangle.y = viewangle.y + 50 * FrameTime(); if( viewangle.y > 360 ) then viewangle.y = 0; end end // set bot angle. entity:SetLocalAngles( viewangle ); // walk. bot.Run( controller, // the bot controller that was created with bot.Create 190, // forward ( walk ) 0, // side ( strafe ) 0, // up ( swim, I think ) viewangle, // view angles 0, // buttons 0, // impulse 0, // weapon select 0 // weapon sub type ); // bot.PostClientMessagesSent( controller ); end hook.Add( "Think", "BotThink", botThink ); [/lua][/QUOTE] I understood about 0% of that. God damn that's hard.
  • Avatar of FPtje
  • I understood -100% of that :D oh well... Bot=bot whee=whee Jinto made me happy :D
  • Avatar of Devenger
  • So we could potentially (laggily) create bot players and give them a basic AI via Lua inputs?
  • I moved the controller functions into the bot controller metatable. Should be easier to use now. Link is in the first post. [lua]bot.SetActiveWeapon( mybot, "weapon_pistol" );[/lua] Becomes. [lua]mybot:SetActiveWeapon( "weapon_pistol" );[/lua]
  • [QUOTE=The Mathias]This is pretty sweet. You can use player functions with them too, right?[/QUOTE] Yup.
  • Avatar of Suicidal_B
  • Niceness, but i can't get him to shoot? i've set weapon_physcannon and it stopped shooting on default, then i tried [lua]controller:ExecCommand( "+attack; -attack" );[/lua] right after controller:Run what did i do wrong?
  • [QUOTE=Suicidal_B]Niceness, but i can't get him to shoot? i've set weapon_physcannon and it stopped shooting on default, then i tried [lua]controller:ExecCommand( "+attack; -attack" );[/lua] right after controller:Run what did i do wrong?[/QUOTE] The buttons argument of BOTCONTROLLER:Run is a bitmask of all the keys you want them to have held this frame. [lua] // walk. controller:Run( 190, // forward ( walk ) 0, // side ( strafe ) 0, // up ( swim, I think ) viewangle, // view angles IN_JUMP + IN_DUCK, // buttons 0, // impulse 0, // weapon select 0 // weapon sub type ); [/lua]
  • Avatar of jA_cOp
  • Awesome, I'll give a try at an AI :D How do I disable the default bot behaviour? Also, what does this do [lua]bot.PostClientMessagesSent( controller )[/lua]
  • Avatar of Suicidal_B
  • [QUOTE=jA_cOp]Awesome, I'll give a try at an AI :D How do I disable the default bot behaviour? Also, what does this do [lua]bot.PostClientMessagesSent( controller )[/lua][/QUOTE] My d/l doesn't say controller in between, but yeah i also have that question (will try keys now, thanks) [I]Edit:[/I] Another thing, the bot often goes in some kind of slomo reverse, it still aims right but walks backward (sometimes forward too) really really slowly, with a slow animation, any fix for that?
  • [code]bot_zombie 1[/code] Disable the default gmod bot behaviour. As for the funky animation, I get that too, never found a workaround for it.
  • Avatar of Suicidal_B
  • Hmm, the angle it shoots in isn't the same as the angle its looking at, any thoughts? i'm just trying some basic stuff on gm_construct and it keeps shooting towards behind the spawn, no matter what angle. Then i gave it a physgun and it pointed to same place behind spawnpoint, so if you could be so nice, look into it [I]Edit:[/I] I do find this awesome though, despite my many questions
  • Avatar of CapsAdmin
  • Wow. [b]Edit:[/b] [QUOTE=Elspin]Jinto, you win all the internet. [b]Edit:[/b] I understood about 0% of that. God damn that's hard.[/QUOTE] Just read the comments and I'm pretty sure you'll understand it just fine (The green text.)
  • [QUOTE=smallfry]Can they use .nav files?[/QUOTE] If you programmed them to.
  • Avatar of morpheous
  • Thought I'd let you know... [url=http://www.gmodnews.com/node/23][img]http://www.gmodnews.com/img/syndicate/gmodnewsreviewed.png[/img][/url] Fantastic module; eagerly awaiting the first scripts using this.
  • Avatar of Suicidal_B
  • I'm working on a basic friendly bot (as in not meant to deathmatch) When it finds a prop near it runs to it and stops before hitting it, then tries to punt it away using the physcannon (yellow gravgun), though that keeps failing (i'm thinking its looking over the prop or something, the bot doesn't seem to aim up/down) Either way it's great fun, thanks loads
  • Avatar of jA_cOp
  • [lua]Bot.Controller:Run( 0, 0, 0, Bot.Entity.Master:GetPos() - Bot.Entity:GetPos():Angle() , IN_FORWARD, 0, 0, 0 )[/lua] That's run every frame - and is supposed to make it follow its creator. However, when I start the think hook that runs it gmod crashes. Any idea why?