From 34698fdd399d6f1529f539752b47dec98779b094 Mon Sep 17 00:00:00 2001 From: INeedBots Date: Sun, 20 Dec 2020 22:04:52 -0600 Subject: [PATCH] bot_wait_for_host --- main_shared/maps/mp/bots/_bot.gsc | 2 + main_shared/maps/mp/bots/_bot_utility.gsc | 58 +++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/main_shared/maps/mp/bots/_bot.gsc b/main_shared/maps/mp/bots/_bot.gsc index 7387fad..5e7a0a0 100644 --- a/main_shared/maps/mp/bots/_bot.gsc +++ b/main_shared/maps/mp/bots/_bot.gsc @@ -582,6 +582,8 @@ teamBots() addBots() { level endon("game_ended"); + + bot_wait_for_host(); for(;;) { diff --git a/main_shared/maps/mp/bots/_bot_utility.gsc b/main_shared/maps/mp/bots/_bot_utility.gsc index 26d5507..5532d61 100644 --- a/main_shared/maps/mp/bots/_bot_utility.gsc +++ b/main_shared/maps/mp/bots/_bot_utility.gsc @@ -661,6 +661,64 @@ waittill_notify_or_timeout(not, tim) wait tim; } +/* + Gets a player who is host +*/ +GetHostPlayer() +{ + for (i = 0; i < level.player.size; i++) + { + player = level.players[i]; + + if (!player is_host()) + continue; + + return player; + } + + return undefined; +} + +/* + Waits for a host player +*/ +bot_wait_for_host() +{ + host = undefined; + + for(i = 0; i < 100; i++) + { + host = GetHostPlayer(); + + if(isDefined(host)) + break; + + wait 0.05; + } + + if(!isDefined(host)) + return; + + for(i = 0; i < 100; i++) + { + if(IsDefined( host.pers[ "team" ] )) + break; + + wait 0.05; + } + + if(!IsDefined( host.pers[ "team" ] )) + return; + + for(i = 0; i < 100; i++) + { + if(host.pers[ "team" ] == "allies" || host.pers[ "team" ] == "axis") + break; + + wait 0.05; + } +} + /* Pezbot's line sphere intersection. http://paulbourke.net/geometry/circlesphere/raysphere.c