From 113c8108bcd8866d6a2d23f01fd8554d2ffb6df1 Mon Sep 17 00:00:00 2001 From: INeedBots Date: Sun, 20 Dec 2020 22:05:13 -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 b390e29..74a4c0b 100644 --- a/main_shared/maps/mp/bots/_bot.gsc +++ b/main_shared/maps/mp/bots/_bot.gsc @@ -574,6 +574,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 a9eb1e7..2191b66 100644 --- a/main_shared/maps/mp/bots/_bot_utility.gsc +++ b/main_shared/maps/mp/bots/_bot_utility.gsc @@ -688,6 +688,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