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

is_user_bot check problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NEUCOUNTRA
Junior Member
Join Date: Jul 2021
Location: Ukraine, CITY8
Old 04-08-2022 , 07:39   is_user_bot check problem
Reply With Quote #1

I made plugin that gives possibility to heal and armor by executing a command. I wanted to import this function to bot, but don't get any respond and health/armor doesn't change. The goal - heal if health lower then maxhealth variable (maxhealth = 100) and armor if it equals 0. How it can be solved?

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(id, print_chat, "Health function called successfully")
        set_user_health(id, get_user_health(id) + 100)
        client_cmd(id, "spk items/medshot4")
    }
    else
    {
        client_print(id, print_chat, "You are dead!")
    }
}

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

public bot_check(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(id, print_chat, "Bot healed")
    }
    
    if(is_user_bot(id) && get_user_armor(id) == 0)
    {
        give_armor(id);
        client_print(id, print_chat, "Bot armored")
    }
}
NEUCOUNTRA is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 04-08-2022 , 08:15   Re: is_user_bot check problem
Reply With Quote #2

try: do a check if player is bot or not. if it is use engine and
PHP Code:
 entity_set_intiEntEV_FL_healthvalue 
lexzor is offline
NEUCOUNTRA
Junior Member
Join Date: Jul 2021
Location: Ukraine, CITY8
Old 04-08-2022 , 08:23   Re: is_user_bot check problem
Reply With Quote #3

Quote:
Originally Posted by lexzor View Post
try: do a check if player is bot or not. if it is use engine and
PHP Code:
 entity_set_intiEntEV_FL_healthvalue 
I have already checked or I don't understand something?

Code:
if(is_user_bot(id) && get_user_health(id) < maxhealth)
    {
        give_health(id);
        client_print(id, print_chat, "Bot healed")
    }
Where I should place that?

Code:
entity_set_int( iEnt, EV_FL_health, value )
Sorry, I'm new in pawn :<

Last edited by NEUCOUNTRA; 04-08-2022 at 08:23.
NEUCOUNTRA is offline
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
Old 04-08-2022 , 09:28   Re: is_user_bot check problem
Reply With Quote #4

Quote:
Originally Posted by NEUCOUNTRA View Post
I have already checked or I don't understand something?

Code:
if(is_user_bot(id) && get_user_health(id) < maxhealth)
    {
        give_health(id);
        client_print(id, print_chat, "Bot healed")
    }
Where I should place that?

Code:
entity_set_int( iEnt, EV_FL_health, value )
Sorry, I'm new in pawn :<
Your bot function is not being called anywhere. You need to trigger it somehow, just like the commands you have for the non-bot users.

PHP Code:
public bot_check(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")
    } 
EDIT: You probably also need to modify the function, usually bots are unable to call a function by themselves so you probably need to loop through the bots / or find the id of the bot somehow if a player is healing them.

Last edited by Moody92; 04-08-2022 at 09:36.
Moody92 is offline
NEUCOUNTRA
Junior Member
Join Date: Jul 2021
Location: Ukraine, CITY8
Old 04-09-2022 , 04:08   Re: is_user_bot check problem
Reply With Quote #5

Quote:
Originally Posted by Moody92 View Post
Your bot function is not being called anywhere. You need to trigger it somehow, just like the commands you have for the non-bot users.

PHP Code:
public bot_check(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")
    } 
EDIT: You probably also need to modify the function, usually bots are unable to call a function by themselves so you probably need to loop through the bots / or find the id of the bot somehow if a player is healing them.

How it might look, yesterday I tried to create a check, if player is bot and then I called function, but it didn't work. How I can realise a trigger?

Also I tried to use set_task on client_putinserver(), it didn't work too.
NEUCOUNTRA is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 04-09-2022 , 06:02   Re: is_user_bot check problem
Reply With Quote #6

The worst way I can suggest is to use preThink.
Make something like random command execution.
Code below will check if player is a bot. If it is a bot then generate random number from 1 to 100 and if number is in range of USAGE_CHANCE then execute your function
PHP Code:
// IMHO USAGE_CHANCE should be pretty small
#define USAGE_CHANCE 1..5

new bool:g_bBot[MAX_PLAYERS+1]

// when client connects to server
public client_putinserver(id)
{
    
// cache bots to probably decrease CPU usage
    
g_bBot[id] = bool:is_user_bot(id)
}

public 
client_PreThink(id)
{
    if(
g_bBot[id])
    {
        switch(
random_num(1100))
        {
            case 
USAGE_CHANCE:
            {
                
// run heal function
                
give_health(id)
            }
        }
    }

__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 04-09-2022 at 06:09.
kww is offline
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
Old 04-09-2022 , 07:19   Re: is_user_bot check problem
Reply With Quote #7

Quote:
Originally Posted by kww View Post
The worst way I can suggest is to use preThink.
Make something like random command execution.
Code below will check if player is a bot. If it is a bot then generate random number from 1 to 100 and if number is in range of USAGE_CHANCE then execute your function
PHP Code:
// IMHO USAGE_CHANCE should be pretty small
#define USAGE_CHANCE 1..5

new bool:g_bBot[MAX_PLAYERS+1]

// when client connects to server
public client_putinserver(id)
{
    
// cache bots to probably decrease CPU usage
    
g_bBot[id] = bool:is_user_bot(id)
}

public 
client_PreThink(id)
{
    if(
g_bBot[id])
    {
        switch(
random_num(1100))
        {
            case 
USAGE_CHANCE:
            {
                
// run heal function
                
give_health(id)
            }
        }
    }

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__"b")
}

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-10-2022 at 04:07.
Moody92 is offline
DJEarthQuake
Veteran Member
Join Date: Jan 2014
Location: Astral planes
Old 04-09-2022 , 12:25   Re: is_user_bot check problem
Reply With Quote #8

Think can be rough especially when multiple plugins are using it. A task with CVAR to adjust the timing.
__________________

Last edited by DJEarthQuake; 04-09-2022 at 12:28.
DJEarthQuake is offline
Old 04-09-2022, 17:38
kww
This message has been deleted by kww. Reason: no more need
Moody92
Veteran Member
Join Date: May 2011
Location: Oman
Old 04-10-2022 , 04:07   Re: is_user_bot check problem
Reply With Quote #9

Quote:
Originally Posted by kww View Post
As i wrote.


PHP Code:
// then it should be used on this manner
set_task(frequencybot_check440033, .flags[] = "b"
Corrected in first post, thanks.
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 15:00.


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