AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   Help Solving Attack Problem (https://forums.alliedmods.net/showthread.php?t=306276)

thebro 03-24-2018 00:29

Help Solving Attack Problem
 
I am currently trying to make a Bot swing its knife if it sees you (enemy players) from a distance, so far the code Detects if he is staring at you. But the Attack Part does not work. Any help?


Code:

#include <amxmodx>
#include <fun>
#include <hamsandwich>

public plugin_init()
{
        register_event("StatusValue", "event_status_value", "be", "1=2")
        RegisterHam(Ham_Weapon_PrimaryAttack, "weapon_knife", "AttackTest")
}

//Bot Fire (V1)
public event_status_value(id)
{
        new target = read_data(2)
        if (!target) // if player not aimed at target then we stop else continue
                return
       
        if (get_user_team(id) != get_user_team(target))
        {
                if ( is_user_bot(id) )
                {
                        AttackTest(id)
                        //engclient_cmd(id, "say", "Seen Player")
                }
        }
}

public AttackTest(id)
{
        //engclient_cmd(id, "say", "Attack Event Called")
        ExecuteHamB(Ham_Weapon_PrimaryAttack, id)
        return HAM_SUPERCEDE
}

This is what I have written so far, the code does make it to the AttackTest(id) area, but the bot still does not Attack with Knife. Before I also had engclient_cmd(id, "+attack") but that was not being executed. So I have no idea on what is going on.

Natsheh 03-24-2018 10:28

Re: Help Solving Attack Problem
 
AttackTest( Entity )

Entity , is the id of the weapon that player is holding.


PHP Code:

#include <amxmodx>
#include <fun>
#include <hamsandwich>
#include engine

public plugin_init()
{
    
register_event("StatusValue""event_status_value""be""1=2")
}

//Bot Fire (V1)
public event_status_value(id)
{
    new 
target read_data(2)
    if (!
target// if player not aimed at target then we stop else continue
        
return
    
    if (
get_user_team(id) != get_user_team(target))
    {
        if ( 
is_user_bot(id) ) 
        { 
                        new 
szWp[24]
                        
get_weaponname(get_user_weapon(id), szWp23);
                        new 
ent find_ent_by_owner(-1szWpid);

            if(
ent 0AttackTest(ent)
                        
        }
    }


AttackTest(ent)
{
    
ExecuteHamB(Ham_Weapon_PrimaryAttackent)



thebro 03-24-2018 14:18

Re: Help Solving Attack Problem
 
Compile fails for some reason.

Code:

Error: Number of arguments does not match definition on line 25
The Line referred is above the commented area regarding This Line Above Causes Compile Error

PHP Code:

#include <amxmodx>
#include <fun>
#include <hamsandwich>
#include <engine>

public plugin_init()
{
    
register_event("StatusValue""event_status_value""be""1=2")
    
RegisterHam(Ham_Weapon_PrimaryAttack"weapon_knife""AttackTest")
}

//Bot Fire (V1)
public event_status_value(id)
{
    new 
target read_data(2)
    if (!
target// if player not aimed at target then we stop else continue
        
return
    
    if (
get_user_team(id) != get_user_team(target))
    {
        if ( 
is_user_bot(id) ) 
        { 
            new 
szWp[24]
            
get_weaponname(get_user_weapon(id), szWp23);
            new 
ent find_ent_by_owner(-1szWp); 
                        
//This Line Above Causes Compile Error//

            
if(ent 0AttackTest(ent)
                        
        }
    }


public 
AttackTest(ent)
{
    
ExecuteHamB(Ham_Weapon_PrimaryAttackent)


Any idea what the issue may be? Thanks for your help by the way, I appreciate it!

EDIT: if I put "id" at the end of the conflicting line, it compiles, but it also Crashes the server once the bot looks at a player with No Error being logged!

Natsheh 03-25-2018 04:48

Re: Help Solving Attack Problem
 
Code edited

thebro 03-25-2018 22:41

Re: Help Solving Attack Problem
 
The Plugin just crashes the server with no Error being logged after the bot attempts to attack "swing knife" aka when he is looking at you. Any idea what the issue may be?

Natsheh 03-25-2018 22:49

Re: Help Solving Attack Problem
 
Quote:

Originally Posted by thebro (Post 2584689)
The Plugin just crashes the server with no Error being logged after the bot attempts to attack "swing knife" aka when he is looking at you. Any idea what the issue may be?

Remove the registerham hook

polimpo4 04-18-2018 21:55

Re: Help Solving Attack Problem
 
How We Can Use It To Display Variables And Not Const... And Yes It Works I Already Saw It... And Many Portuguese Servers Have It... I Can Do It With Hudmessage So Why I Cannot Do The Same With DHUDmessage?

I Mean when i hit a player i win one point and i cache it on one variable and i want to know if it is possible to show the value of that variable with dhudmessage ? If Yes *(As I Already Saw) How To Made It?


All times are GMT -4. The time now is 17:26.

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