Raised This Month: $51 Target: $400
 12% 

How to realize player bot check and trigger?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NEUCOUNTRA
Junior Member
Join Date: Jul 2021
Location: Ukraine, CITY8
Old 04-09-2022 , 04:17   How to realize player bot check and trigger?
Reply With Quote #1

Yesterday I tried to crete bot check for my plugin, the goal - after check do function. If it is bot and he has low health and armor he will type: "/health" and "/armor". I can't trigger that function, how can I realize it?

PHP Code:
#include <amxmodx>
#include <fun>

new maxhealth 100;

public 
plugin_init()
{
    
register_plugin("health""CNC""0.1")
    
register_clcmd("say /health""give_health")
    
register_clcmd("health""give_health")
    
register_clcmd("say /armor""give_armor")
}

public 
give_health(id)
{
    if(
is_user_alive(id))
    {
        
client_print(idprint_chat"Health function called successfully")
        
set_user_health(idget_user_health(id) + 100)
        
client_cmd(id"spk items/medshot4")
    }
    else
    {
        
client_print(idprint_chat"You are dead!")
    }
}

public 
give_armor(id)
{
    if(
is_user_alive(id))
    {
        
client_print(idprint_chat"Armor gain")
        
set_user_armor(idget_user_armor(id) + 100)
        
client_cmd(id"spk items/ammopickup1")
    }
    else
    {
        
client_print(idprint_chat"You are dead!")
    }
}

public 
client_putinserver(id)
{
    
set_task(0"set_task_check"id)
}

public 
set_task_check(id)
{    
    if(
is_user_alive(id))
    {
        if(
is_user_bot(id))
        {
            
console_print(id"bot")
        }
        
        if(
is_user_bot(id) && get_user_health(id) < maxhealth)
        {
            
give_health(id)
            
client_print(idprint_chat"Bot healed")
        }
        
        if(
is_user_bot(id) && get_user_armor(id) == 0)
        {
            
give_armor(id);
            
client_print(idprint_chat"Bot armored")
        }
    }

set_task is not working.
NEUCOUNTRA is offline
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
Old 04-09-2022 , 10:04   Re: How to realize player bot check and trigger?
Reply With Quote #2

Stop duplicating threads

Quote:
Originally Posted by Moody92 View Post
I do not think running a prethink is a good idea, you will be spamming the server. I copy pasta'd some of your code, but the way I put it is starting a task every round that loops thru every bot and if they get lucky (chance is 1 in 100), then they get geared up. Not sure if this is the best idea either.

Not tested.

PHP Code:
#include <amxmodx>
#include <fun>

// IMHO USAGE_CHANCE should be pretty small
#define USAGE_CHANCE 5

new maxhealth 100;
new 
maxarmor 100;
new 
Float:frequency 5.0 // 5 seconds frequency, you can change this

public plugin_init()
{
    
register_plugin("health""CNC""0.1")
    
register_clcmd("say /health""give_health")
    
register_clcmd("health""give_health")
    
register_clcmd("say /armor""give_armor")
    
    
register_logevent("logevent_round_start"2"1=Round_Start"
    
register_logevent("logevent_round_end"2"1=Round_End"
}

public 
logevent_round_start(){
    
set_task(frequency"bot_check"440033___1)
}

public 
logevent_round_end(){
    
remove_task(440033)
    
}
public 
give_health(id)
{
    new 
pHealth
    pHealth 
get_user_health(id//Obtain current user health
    
    //Check if user is alive
    
if(!is_user_alive(id))
    {
        
client_print(idprint_chat"You are dead!")
        return 
PLUGIN_HANDLED
    
}
    
    
//Check if user already has max hp, if yes then ignore the rest
    
if (pHealth == maxhealth)
    {
        
client_print(idprint_chat"You are already at full health.")
        return 
PLUGIN_HANDLED
    
}
    
    
client_print(idprint_chat"Health function called successfully")
    
set_user_health(idmaxhealth// Set to 100 -- get_user_health(id) + 100 this will set user health to above 100 if their health is 40 it will add 100 to that
    
client_cmd(id"spk items/medshot4")

    return 
PLUGIN_CONTINUE
}

public 
give_armor(id)
{
    new 
pArmor
    pArmor 
get_user_armor(id//Obtain current user health
    
    //Check if user is alive
    
if(!is_user_alive(id))
    {
        
client_print(idprint_chat"You are dead!")
        return 
PLUGIN_HANDLED
    
}
    
    
//Check if user already has max armor, if yes then ignore the rest
    
if (pArmor == maxarmor)
    {
        
client_print(idprint_chat"You are already at full armor.")
        return 
PLUGIN_HANDLED
    
}

    
client_print(idprint_chat"Armor gain")
    
set_user_armor(idmaxarmor)
    
client_cmd(id"spk items/ammopickup1")

    return 
PLUGIN_CONTINUE
}

public 
bot_check()
{
    new 
sBots[32], pNumszName[33]
    
get_players(sBotspNum"abdefghi"//only get bot players
    

    
for(new i=0pNumi++)
    {
        switch(
random_num(1100)) //You can change this, a random number will be picked from 1 to 100 and if it is the same number as USAGE_CHANCE then it will give armor and bot - this is run for each bot
        
{
            case 
USAGE_CHANCE:
            {
                if(
is_user_connected(sBots[i]))
                {
                    
give_health(sBots[i])
                    
give_armor(sBots[i])
                    
get_user_name(sBots[i], szNamecharsmax(szName)) 
                    
client_print(0print_chat"Bot %s has been fully healed and armored up!"szName// Prints to everyone
                
}
            }
        
        }
    }
    


Last edited by Moody92; 04-09-2022 at 10:04.
Moody92 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 12:25.


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