Veteran Member
Join Date: May 2011
Location: Oman
|
04-09-2022
, 10:04
Re: How to realize player bot check and trigger?
|
#2
|
Stop duplicating threads
Quote:
Originally Posted by Moody92
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(id, print_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(id, print_chat, "You are already at full health.") return PLUGIN_HANDLED } client_print(id, print_chat, "Health function called successfully") set_user_health(id, maxhealth) // 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(id, print_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(id, print_chat, "You are already at full armor.") return PLUGIN_HANDLED }
client_print(id, print_chat, "Armor gain") set_user_armor(id, maxarmor) client_cmd(id, "spk items/ammopickup1")
return PLUGIN_CONTINUE }
public bot_check() { new sBots[32], pNum, szName[33] get_players(sBots, pNum, "abdefghi") //only get bot players
for(new i=0; i < pNum; i++) { switch(random_num(1, 100)) //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], szName, charsmax(szName)) client_print(0, print_chat, "Bot %s has been fully healed and armored up!", szName) // Prints to everyone } } } } }
|
Last edited by Moody92; 04-09-2022 at 10:04.
|
|