Raised This Month: $ Target: $400
 0% 

get enemy distance


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
LukeyB
Member
Join Date: Dec 2011
Old 01-26-2012 , 17:00   get enemy distance
Reply With Quote #1

How do I make it so the attack2 action is only performed when the enemy is a certain distance away?

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <hamsandwich>
#include <fakemeta>
#include <fun>
new g_iMaxPlayers;
#define IsPlayer(%1) (1<=%1<=g_iMaxPlayers)
public plugin_init()
{
register_plugin("botattack""1.0""LB")
register_event"StatusValue" "eventStatusValue" "be" "1=2" );
}
public 
eventStatusValueiduc_handle )

  if(
is_user_bot(id) )
  {
    new 
iPlayeriEnemyweapon get_user_weapon(id)
    
get_user_aimingidiPlayeriEnemy);
    if (
IsPlayeriEnemy ) && weapon == CSW_GLOCK18)
    { 
      
set_pevidpev_buttonpev(idpev_button) | IN_ATTACK2)
    }
  }

LukeyB is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-26-2012 , 17:05   Re: get enemy distance
Reply With Quote #2

Do you want the attack to be automatic within a distance or only allow the attack within a distance?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 01-26-2012 , 17:06   Re: get enemy distance
Reply With Quote #3

http://www.amxmodx.org/funcwiki.php?go=func&id=397
__________________
Selling tons of my own private works.
Accepting paid work for clans and communities.
Don't hesitate to contact me.
bibu is offline
LukeyB
Member
Join Date: Dec 2011
Old 01-26-2012 , 17:22   Re: get enemy distance
Reply With Quote #4

I want it to happen once if the enemy is within the set distance, then again when they are out of range. The bot would set the glock to burst within a certain distance of enemy then set it back to semi auto when beyond that distance.
LukeyB is offline
LukeyB
Member
Join Date: Dec 2011
Old 01-26-2012 , 17:32   Re: get enemy distance
Reply With Quote #5

something like this maybe...but it doesn't work.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <hamsandwich>
#include <fakemeta>
#include <fun>
new g_iMaxPlayers;
#define IsPlayer(%1) (1<=%1<=g_iMaxPlayers)
public plugin_init()
{
register_plugin("botattack""1.0""LB")
register_event"StatusValue" "eventStatusValue" "be" "1=2" );
}
public 
eventStatusValueiduc_handle )

  if(
is_user_bot(id) )
  {
    new 
iPlayeriEnemyweapon get_user_weapon(id)
    
get_user_aimingidiPlayeriEnemy);
    if (
IsPlayeriEnemy ) && weapon == CSW_GLOCK18 && get_entity_distance idiEnemy ) < 200)
    { 
      
cs_set_weapon_burst(weapon1
    }
    if (
IsPlayeriEnemy ) && weapon == CSW_GLOCK18 && get_entity_distance idiEnemy ) > 200)
    { 
      
cs_set_weapon_burst(weapon0
    }
  }

LukeyB is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-26-2012 , 17:51   Re: get enemy distance
Reply With Quote #6

Try this:
Code:
#include <amxmodx> #include <engine> #include <cstrike> #include <hamsandwich> #define m_pActiveItem 373 public client_PreThink(id) {     // check if a bot and alive holding a glock18     if(is_user_bot(id) && is_user_alive(id) && get_user_weapon(id) == CSW_GLOCK18) {         // get aim info         new ent, body;         get_user_aiming(id, ent, body);                 // if aiming at another player within burst range         if(is_user_alive(ent) && entity_range(id, ent) < 200) {             // set to be burst fire             body = 1;         } else {             // set to be semi-automatic             body = 0;         }                 // get the glock18 entity         ent = get_pdata_cbase(id, m_pActiveItem);                 // if valid entity and entity's burst status is not the same as the new status         if(is_valid_ent(ent) && cs_get_weapon_burst(ent) != body) {             // set the entity's burst status             cs_set_weapon_burst(ent, body);         }     } }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 01-26-2012 , 18:16   Re: get enemy distance
Reply With Quote #7

You can use get_user_aiming's distance parameter.
Code:
#include <amxmodx>
#include <engine>
#include <cstrike>
#include <hamsandwich>

#define m_pActiveItem 373

public client_PreThink(id) {
    // check if a bot and alive holding a glock18
    if(is_user_bot(id) && is_user_alive(id) && get_user_weapon(id) == CSW_GLOCK18) {
        // get aim info
        new ent, body;
        get_user_aiming(id, ent, body, 200);
        
        // if aiming at another player within burst range
        if(is_user_alive(ent)) {
            // set to be burst fire
            body = 1;
        } else {
            // set to be semi-automatic
            body = 0;
        }
        
        // get the glock18 entity
        ent = get_pdata_cbase(id, m_pActiveItem);
        
        // if valid entity and entity's burst status is not the same as the new status
        if(is_valid_ent(ent) && cs_get_weapon_burst(ent) != body) {
            // set the entity's burst status
            cs_set_weapon_burst(ent, body);
        }
    }
}
I would suggest you still do this in the StatusValue event though. You could read the id of the player that StatusValue is sending and remove get_user_aiming all together and just check the distance using entity_range.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
LukeyB
Member
Join Date: Dec 2011
Old 01-26-2012 , 18:16   Re: get enemy distance
Reply With Quote #8

Exolent[jNr] : Unfortunately, they never switch to burst with this.
Emp` : Can you give an example please? Having a hard time understanding.

Last edited by LukeyB; 01-26-2012 at 18:18.
LukeyB is offline
LukeyB
Member
Join Date: Dec 2011
Old 01-30-2012 , 00:31   Re: get enemy distance
Reply With Quote #9

Why is this not working? I am struggling here. Just want the bots to switch to burst when looking at an enemy within a certain distance...

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <hamsandwich>
#include <fakemeta>
#include <fun>
new g_iMaxPlayers;
#define IsPlayer(%1) (1<=%1<=g_iMaxPlayers)
#define m_pActiveItem 373
public plugin_init()
{
register_plugin("botattack""1.0""LB")
register_event"StatusValue" "eventStatusValue" "be" "1=2" )
}
public 
eventStatusValueid )
{
 if(
is_user_bot(id) )
 {
 static 
targetbody;
 new 
iWpnID get_pdata_cbase(idm_pActiveItem5), iWeapon get_user_weapon(id
 new 
Float:Distance get_user_aiming(idtargetbody)
 if(
is_user_alive(target) && iWeapon == CSW_GLOCK18 && Distance <= 200 && cs_get_weapon_burst(iWpnID) == 0)
 {
 
cs_set_weapon_burst(iWpnID1)
 }
 }

LukeyB is offline
LukeyB
Member
Join Date: Dec 2011
Old 01-31-2012 , 03:10   Re: get enemy distance
Reply With Quote #10

finally figured it out...

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <cstrike>
#include <engine>
#include <hamsandwich>
#include <fakemeta>
#include <fun>
#define m_pActiveItem 373
public plugin_init()
{
register_plugin("botattackburst""1.0""LB")
}
public 
client_PreThink(id)
{
 static 
targetbody;
 new 
Float:Distance get_user_aiming(idtargetbody), ent get_pdata_cbase(idm_pActiveItem5)
 if( 
is_user_alive(id) && is_user_bot(id) && get_user_weapon(id) == CSW_FAMAS && Distance 100)
 {
 
cs_set_weapon_burst(ent1);
 }
 if( 
is_user_alive(id) && is_user_bot(id) && get_user_weapon(id) == CSW_FAMAS && Distance 100)
 {
 
cs_set_weapon_burst(ent0);
 }
 if( 
is_user_alive(id) && is_user_bot(id) && get_user_weapon(id) == CSW_GLOCK18 && Distance 500)
 {
 
cs_set_weapon_burst(ent1);
 }
 if( 
is_user_alive(id) && is_user_bot(id) && get_user_weapon(id) == CSW_GLOCK18 && Distance 500)
 {
 
cs_set_weapon_burst(ent0);
 }

LukeyB is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 08:35.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode