• Making an attack function for a Nextbot and calling it when they're within range of a player
    9 replies, posted
Hello. I decided that I'd start making a nextbot. It seems simple enough, I've gotten the nextbot to chase a player, but the thing I need help with is making it attack. Now, I know that nextbots don't have an attack function built-in, so I need to make one. I'm trying to make them do a simple punch attack, that does 10 damage to a player. I know about setting animations, but how would I set an attack range and damage? Oh yeah, I also know about ViewPunch, so making the player who is attacked flinch won't be a problem. Please remember that I'm new to nextbots, and that this isn't begging for someone to code a whole nextbot for me.
[QUOTE=A Fghtr Pilot;47621335]Hello. I decided that I'd start making a nextbot. It seems simple enough, I've gotten the nextbot to chase a player, but the thing I need help with is making it attack. Now, I know that nextbots don't have an attack function built-in, so I need to make one. I'm trying to make them do a simple punch attack, that does 10 damage to a player. I know about setting animations, but how would I set an attack range and damage? Oh yeah, I also know about ViewPunch, so making the player who is attacked flinch won't be a problem. Please remember that I'm new to nextbots, and that this isn't begging for someone to code a whole nextbot for me.[/QUOTE] Assuming you are using code from the example on the wiki, get the distance to the enemy, check if it is less than your arbitrary value, and apply damage directly to the player with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/TakeDamage]Entity:TakeDamage[/url]
[QUOTE=James xX;47621562]Assuming you are using code from the example on the wiki, get the distance to the enemy, check if it is less than your arbitrary value, and apply damage directly to the player with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/TakeDamage]Entity:TakeDamage[/url][/QUOTE] Thanks! [editline]28th April 2015[/editline] [QUOTE=James xX;47621562]Assuming you are using code from the example on the wiki, get the distance to the enemy, check if it is less than your arbitrary value, and apply damage directly to the player with [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/TakeDamage]Entity:TakeDamage[/url][/QUOTE] Where would I put a code that does this? Ent:HaveEnemy? Ent:ChaseEnemy?
I did ENT:Think and checking if the player is close enough to the bot
Hmm. I have this: [CODE]function ENT:PunchEnemy() if ( self:GetEnemy() and IsValid( self:GetEnemy() ) ) then if (self:GetRangeTo(self:GetEnemy()) < 10) then if self:GetEnemy():IsPlayer() then self:StartActivity( ACT_HL2MP_SIT_PISTOL ) self:GetEnemy():TakeDamage( 10 ) self:GetEnemy():ViewPunch(Angle( 30, 0, 0 )) end end end end[/CODE] but it doesn't work. Obviously, something is wrong. I'm not getting errors, however, and I called it to happen in ENT:RunBehavior. Hmm....
[QUOTE=A Fghtr Pilot;47621878]Hmm. I have this: [CODE]function ENT:PunchEnemy() if ( self:GetEnemy() and IsValid( self:GetEnemy() ) ) then if (self:GetRangeTo(self:GetEnemy()) < 10) then if self:GetEnemy():IsPlayer() then self:StartActivity( ACT_HL2MP_SIT_PISTOL ) self:GetEnemy():TakeDamage( 10 ) self:GetEnemy():ViewPunch(Angle( 30, 0, 0 )) end end end end[/CODE] but it doesn't work. Obviously, something is wrong. I'm not getting errors, however, and I called it to happen in ENT:RunBehavior. Hmm....[/QUOTE] Put prints in to see where your code is failing.
[QUOTE=James xX;47621924]Put prints in to see where your code is failing.[/QUOTE] Judging by what it shows, should it work? Putting it in RunBehavior might not have been the best way idea, though the code itself without being called probably works. Where else can I call it? Note: I was calling it in RunBehavior like so: self:PunchEnemy()
[QUOTE=A Fghtr Pilot;47621939]Judging by what it shows, should it work? Putting it in RunBehavior might not have been the best way idea, though the code itself without being called probably works. Where else can I call it? Note: I was calling it in RunBehavior like so: self:PunchEnemy()[/QUOTE] I don't quite understand your reply, you haven't posted what it shows. Personally, I would put the hook in Think, like Exho said.
[QUOTE=James xX;47621966]I don't quite understand your reply, you haven't posted what it shows. Personally, I would put the hook in Think, like Exho said.[/QUOTE] Hmm. Putting the code for punching in Think might work, yeah. Let me try that. [editline]28th April 2015[/editline] [QUOTE=James xX;47621966]I don't quite understand your reply, you haven't posted what it shows. Personally, I would put the hook in Think, like Exho said.[/QUOTE] Putting it in ENT:Think() works great! Only change I need to make is to use PlaySequenceAndWait, as StartActivity makes it so he can punch as fast as he wants(he can kill someone in like, a millisecond, heh)
Um, because ENT:Think() isn't the behavior function I can't use PlayerSequenceAndWait, what could I use as an alternative? He can punch as fast as he wants, as fast as he can...
Sorry, you need to Log In to post a reply to this thread.