IncludeScript("popextensions/botbehavior", getroottable()) ::scroob <- { function PrintWrapper() { ClientPrint(null, 2, "Script Spawned"); } OnGameEvent_player_spawn = function(params) { local player = GetPlayerFromUserID(params.userid); //ClientPrint(null,2,"Callback Tripped"); if (player.IsFakeClient()) { //ClientPrint(null,2,"Bot Acknowledge"); EntFireByHandle(player, "RunScriptCode", "scroob.BotTagCheck(activator)", -1.0, player, null) return } } BotTagCheck = function(activator) { //ClientPrint(null,2,"We ran successfully"); if (activator.HasBotTag("fetchflag_sniper")) { activator.GetScriptScope().PlayerThinkTable.fetchflag_sniper_Think <- function() { if (NetProps.GetPropInt(self, "m_lifeState") != 0) { NetProps.SetPropString(self, "m_iszScriptThinkFunction", ""); return -1; } local visibilityChecked = false; //ClientPrint(null,2,"Thinking"); local ent = null if(self.InCond(51) == false) { for (local p; p = Entities.FindByClassnameWithin(p, "player", self.GetOrigin(), 2500);) { if (p.GetTeam() != self.GetTeam() && NetProps.GetPropInt(p, "m_lifeState") == 0) { visibilityChecked = true; if (IsThreatVisible(p, self) == true) { //All of this to get a bot to right click once if(self.InCond(1) == false) { //ClientPrint(null,2,"Enemy is visible, scoping"); self.PressAltFireButton(0.1); } } else { if(self.InCond(1) == true) { //ClientPrint(null,2,"Enemy is not visible, unscoping"); self.PressAltFireButton(0.1); } } } } } if(visibilityChecked == false) { if(self.InCond(1) == true) { //ClientPrint(null,2,"Enemy is not visible, unscoping"); self.PressAltFireButton(0.1); } } //All three of these functions are taken from mw2_bot.nut function IsVisible(target, bot) { //ClientPrint(null,2,"Running visibility check"); local cur_eye_pos = bot.EyePosition(); local trace = { start = cur_eye_pos, end = target.EyePosition(), mask = 16513, // CONTENTS_SOLID|CONTENTS_OPAQUE|CONTENTS_MOVEABLE ignore = bot }; TraceLineEx(trace); return !trace.hit; } function IsInFieldOfView(target, bot) { //ClientPrint(null,2,"Running FOV check"); local cur_eye_pos = bot.EyePosition(); local tolerance = 0.5736; // cos(110/2) local cur_eye_ang = bot.EyeAngles(); local cur_eye_fwd = cur_eye_ang.Forward(); local delta = target.GetOrigin() - cur_eye_pos; delta.Norm(); if (cur_eye_fwd.Dot(target) >= tolerance) return true; delta = target.GetCenter() - cur_eye_pos; delta.Norm(); if (cur_eye_fwd.Dot(delta) >= tolerance) return true; delta = target.EyePosition() - cur_eye_pos; delta.Norm(); //ClientPrint(null,2,(cur_eye_fwd.Dot(delta) >= tolerance)); return (cur_eye_fwd.Dot(delta) >= tolerance); } function IsThreatVisible(target, bot) { //ClientPrint(null,2,"Running Threat Visibility check"); return IsInFieldOfView(target, bot) && IsVisible(target, bot); } return 0.1; } activator.GetScriptScope().PlayerThinkTable.fetchflag_sniper_Think <- fetchflag_sniper_Think; ClientPrint(null,2,"Added think function"); } if (activator.HasBotTag("reserve_combo")) { activator.GetScriptScope().PlayerThinkTable.reserve_combo_Think <- function() { if (NetProps.GetPropInt(self, "m_lifeState") != 0) { NetProps.SetPropString(self, "m_iszScriptThinkFunction", ""); return -1; } //Get your primary and secondary for attribute application and switching local primary = NetProps.GetPropEntityArray(self, "m_hMyWeapons", 0); local secondary = NetProps.GetPropEntityArray(self, "m_hMyWeapons", 1); local visibilityChecked = false; //ClientPrint(null,2,"Thinking"); local ent = null if(self.InCond(51) == false) { for (local p; p = Entities.FindByClassnameWithin(p, "player", self.GetOrigin(), 1000);) { if (p.GetTeam() != self.GetTeam() && NetProps.GetPropInt(p, "m_lifeState") == 0) { if(p.InCond(81) || p.InCond(98) || p.InCond(99) || p.InCond(125)) { visibilityChecked = true; if (IsVisible(p, self) == true) { if(self.GetActiveWeapon() == primary) { self.Weapon_Switch(secondary); self.AddCustomAttribute("disable weapon switch", 1, -1); } else { local enemyHead = p.GetAttachmentOrigin(p.LookupAttachment("head")) LookAt(enemyHead, 1, 1) } } else { if(self.GetActiveWeapon() == secondary) { self.Weapon_Switch(primary); self.AddCustomAttribute("disable weapon switch", 0, -1); } } } } } } if(visibilityChecked == false) { if(self.GetActiveWeapon() == secondary) { self.Weapon_Switch(primary); self.AddCustomAttribute("disable weapon switch", 0, -1); } } //This function is still from mw2_bot.nut, the original lua version //didn't have a LoS check, but this one does. function IsVisible(target, bot) { //ClientPrint(null,2,"Running visibility check"); local cur_eye_pos = bot.EyePosition(); local trace = { start = cur_eye_pos, end = target.EyePosition(), mask = 16513, // CONTENTS_SOLID|CONTENTS_OPAQUE|CONTENTS_MOVEABLE ignore = bot }; TraceLineEx(trace); return !trace.hit; } return 0.1; } activator.GetScriptScope().PlayerThinkTable.reserve_combo_Think <- reserve_combo_Think; ClientPrint(null,2,"Added think function"); } } } scroob.PrintWrapper() __CollectGameEventCallbacks(scroob);