Update:
My game script does this:
function botRollCall(game,id)
{
botRoll.push(id); // adds ID of any bots calling this function to the checkpoint roll call. Note is only called after spawn event
}
function playerWatch(game)
{
playerPos=map.object.getPosition(0);
brightness=game.event.callPlayer('lightLevel',null); // player script returns bone brightness
if (brightness>0.3) inTheLight=true;
else inTheLight=false;
for (i=0; i<botRoll.length; i++) {
distance=map.object.getDistance(botRoll[i],playerPos);
if (distance<15000) withinRange=true;
else withinRange=false;
inFOV=map.object.isFacingId(botRoll[i],0,120);
game.event.callObjectById(botRoll[i],'playerProximity',withinRange,inFOV,inTheLight);
}
game.event.chain(5,'playerWatch'); // loops chain every 5 ticks
}
My bots do this:
function spawn(obj)
{
obj.event.callGame('botRollCall',obj.setting.id); // sends ID of bot to the game script
}
function playerProximity(obj,inRange,inFOV,inTheLight)
{
if (inRange) {
if (inFOV) {
if (inTheLight) {
if (obj.sight.testPlayer()) enterCombat(obj); // only perform sight test if game script calls saying player is in range, in FOV and in light
}
}
}
}
So far so good actually! The only bit that isn't totally reliable is the map.object.isFacingId call - it sometimes says the player is in the FOV when it isn't within 120º, and I'm not sure how the slop is calculated. So I think I may have to make my own routine for verifying if the player is in the FOV
What I can then do is instead of triggering the combat routine as soon as the sight test passes, I can make a variable called something like 'spottedPlayer' which other functions rely on to decide if to carry on with what they were doing, or stop and enter combat. For example, if a bot is their way to get help or trigger an alarm, I wouldn't want the sight test to interrupt them