AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Get cz bots to stop when shooting (https://forums.alliedmods.net/showthread.php?t=174092)

LukeyB 12-15-2011 10:39

Get cz bots to stop when shooting
 
I'm trying to get cz bots to stop when shooting to increase their accuracy, then continue to move as normal. I have got it to where they will stop when shooting but can't move again. Here is what I have so far.

PHP Code:

#include <amxmodx>
#include <fakemeta>
#include <fun>
// any of the buttons on the right will count as moving
#define IN_MOVING (IN_FORWARD|IN_BACK|IN_MOVELEFT|IN_MOVERIGHT| IN_JUMP)
// Tracks players Shots-Fired: [0]=WeaponID, [1]=Ammo
new g_iCurrWeapon[33][2]
public 
plugin_init()
{
register_event"CurWeapon""Event_ShotFired""b" )
}
public 
Event_ShotFiredid )
{
// Players current weapon data..
new wID read_data)
new 
wAmmo read_data)
if( 
g_iCurrWeapon[id][0] != wID // User Changed Weapons..
{
g_iCurrWeapon[id][0] = wID
g_iCurrWeapon
[id][1] = wAmmo
return PLUGIN_CONTINUE
}
if( 
g_iCurrWeapon[id][1] < wAmmo // User Reloaded..
{
g_iCurrWeapon[id][1] = wAmmo
return PLUGIN_CONTINUE
}
if( 
g_iCurrWeapon[id][1] == wAmmo // User did something else, but didn't shoot..
{
return 
PLUGIN_CONTINUE
}
// This far means user shot his/her gun..
// Save new weapon data..
g_iCurrWeapon[id][1] = wAmmo
g_iCurrWeapon
[id][0] = wID
// Do Stuff here..
// he is alive and using movement keys
if( is_user_alive(id) && is_user_bot(id) && (pev(idpev_button) & IN_MOVING) )
{
// make sure he is using a gun
if( wID != CSW_HEGRENADE && wID != CSW_FLASHBANG && wID != CSW_SMOKEGRENADE
&& wID != CSW_C4 && wID != CSW_KNIFE )
{
set_user_maxspeedid 0.1)
}
}
return 
PLUGIN_CONTINUE



Xellath 12-15-2011 14:59

Re: Get cz bots to stop when shooting
 
You could try hooking Ham_Weapon_PrimaryAttack in both Pre (and set maxspeed to 0.1) and in Post (reset the maxspeed).

LukeyB 12-15-2011 16:35

Re: Get cz bots to stop when shooting
 
Thanks. How would I go about doing this for all weapons?

Xellath 12-15-2011 17:40

Re: Get cz bots to stop when shooting
 
Code:
#include < amxmodx > #include < hamsandwich > #include < fun > const m_pPlayer = 41; public plugin_init( ) {     new WeaponName[ 32 ];     // no knifes, nades or c4     new NoPrimaryAttack = ( ( 1 << CSW_KNIFE ) | ( 1 << CSW_HEGRENADE ) | ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_SMOKEGRENADE ) | ( 1 << CSW_C4 ) );     for( new CSWConstant = CSW_P228; CSWConstant <= CSW_P90; CSWConstant++ )     {         if( ~NoPrimaryAttack & ( 1 << CSWConstant ) // check for invalid CSW_* constants         && get_weaponname( CSWConstant, WeaponName, charsmax( WeaponName ) ) ) // get weaponname         {             RegisterHam( Ham_Weapon_PrimaryAttack, WeaponName, "Ham_Weapon_PrimaryAttack_Pre", 0 ); // hook pre             RegisterHam( Ham_Weapon_PrimaryAttack, WeaponName, "Ham_Weapon_PrimaryAttack_Post", 1 ); // hook post         }     } } public Ham_Weapon_PrimaryAttack_Pre( Weapon ) {     new id = get_pdata_cbase( Weapon, m_pPlayer, 4 );         set_user_maxspeed( id, 0.1 ); // set low speed } public Ham_Weapon_PrimaryAttack_Post( Weapon ) {     new id = get_pdata_cbase( Weapon, m_pPlayer, 4 );         set_user_maxspeed( id ); // reset speed }

LukeyB 12-16-2011 10:14

Re: Get cz bots to stop when shooting
 
Thanks for your help, but I get a lot of errors when trying to compile this.

Devil259 12-16-2011 11:35

Re: Get cz bots to stop when shooting
 
#include < fun >

Xellath 12-16-2011 11:52

Re: Get cz bots to stop when shooting
 
Quote:

Originally Posted by Devil259 (Post 1614194)
#include < fun >

Forgot about that. Thanks. Edited.

LukeyB 12-16-2011 12:45

Re: Get cz bots to stop when shooting
 
I appreciate your help with this. Unfortunately the speed does not reset until weapon is changed, which is a problem for the bots. I would like for this not to affect players, only bots and when I add is_user_alive(id) && is_user_bot(id) && to the script, i get error 017: undefined symbol "id".

PHP Code:

#include < amxmodx >
#include < hamsandwich >
#include < fun >
const m_pPlayer 41;
public 
plugin_init( )
{
    new 
WeaponName32 ];
    
// no knifes, nades or c4
    
new NoPrimaryAttack = ( ( << CSW_KNIFE ) | ( << CSW_HEGRENADE ) | ( << CSW_FLASHBANG ) | ( << CSW_SMOKEGRENADE ) | ( << CSW_C4 ) ); 
    for( new 
CSWConstant CSW_P228CSWConstant <= CSW_P90CSWConstant++ ) 
    {
        if( 
is_user_alive(id) && is_user_bot(id) && ~NoPrimaryAttack & ( << CSWConstant // check for invalid CSW_* constants
        
&& get_weaponnameCSWConstantWeaponNamecharsmaxWeaponName ) ) ) // get weaponname
        
{
            
RegisterHamHam_Weapon_PrimaryAttackWeaponName"Ham_Weapon_PrimaryAttack_Pre"); // hook pre
            
RegisterHamHam_Weapon_PrimaryAttackWeaponName"Ham_Weapon_PrimaryAttack_Post"); // hook post
        
}
    }
}
public 
Ham_Weapon_PrimaryAttack_PreWeapon 
{
    new 
id get_pdata_cbaseWeaponm_pPlayer); 
    
    
set_user_maxspeedid0.1 ); // set low speed
}
public 
Ham_Weapon_PrimaryAttack_PostWeapon 
{
    new 
id get_pdata_cbaseWeaponm_pPlayer); 
    
    
set_user_maxspeedid ); // reset speed


Thanks again for your help!

Devil259 12-16-2011 12:51

Re: Get cz bots to stop when shooting
 
You can't use id in plugin_init( )
Code:
#include < amxmodx > #include < hamsandwich > #include < fun > const m_pPlayer = 41; public plugin_init( ) {     new WeaponName[ 32 ];     // no knifes, nades or c4     new NoPrimaryAttack = ( ( 1 << CSW_KNIFE ) | ( 1 << CSW_HEGRENADE ) | ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_SMOKEGRENADE ) | ( 1 << CSW_C4 ) );     for( new CSWConstant = CSW_P228; CSWConstant <= CSW_P90; CSWConstant++ )     {         if( ~NoPrimaryAttack & ( 1 << CSWConstant ) // check for invalid CSW_* constants         && get_weaponname( CSWConstant, WeaponName, charsmax( WeaponName ) ) ) // get weaponname         {             RegisterHam( Ham_Weapon_PrimaryAttack, WeaponName, "Ham_Weapon_PrimaryAttack_Pre", 0 ); // hook pre             RegisterHam( Ham_Weapon_PrimaryAttack, WeaponName, "Ham_Weapon_PrimaryAttack_Post", 1 ); // hook post         }     } } public Ham_Weapon_PrimaryAttack_Pre( Weapon ) {     new id = get_pdata_cbase( Weapon, m_pPlayer, 4 );         if( is_user_bot( id ) )         set_user_maxspeed( id, 0.1 ); // set low speed } public Ham_Weapon_PrimaryAttack_Post( Weapon ) {     new id = get_pdata_cbase( Weapon, m_pPlayer, 4 );         if( is_user_bot( id ) )         set_user_maxspeed( id ); // reset speed }

If it doesn't work, try to use pev_velocity.

LukeyB 12-16-2011 13:18

Re: Get cz bots to stop when shooting
 
Gotcha. I am learning slowly, but surely.

This does stop the bot when shooting, but the bot speed in not reset after shooting so they get stuck in place.

Was reading about pev_velocity and am confused on how to add this instead of set_user_maxspeed.

Thanks again for all of your help.


All times are GMT -4. The time now is 12:05.

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