local ROOT = getroottable() if("noflank" in ROOT) { noflank.CleanUp() delete ::noflank } ::findFirstPlayer <- function() { local MAX_CLIENTS = MaxClients().tointeger() for (local i = 1; i <= MAX_CLIENTS; i++) { local hPlayer = PlayerInstanceFromIndex(i) if(hPlayer && !hPlayer.IsFakeClient()) { return hPlayer } } } ::noflank <- { function OnGameEvent_recalculate_holidays(_) { if(GetRoundState() == 3) { CleanUp() // delete ::noflank } } // rcon script_execute no_flank; rcon script noflank.enable = true function OnGameEvent_player_say(params) { if (!enable) return local args = split(params.text.tolower(), " ") local sText = args[0] local hPlayer = GetPlayerFromUserID(params.userid) local redirect = false if ( args.len() > 1 ) { local top_index = args.len() - 1 if ( args[top_index].find("b:") == 0 ) { hPlayer = findPlayerByName(args[top_index].slice(2)) redirect = true args.remove(top_index) // printl("it works") } } if (sText == "mark") { mark(hPlayer) } } enable = false function CleanUp() { foreach ( func in MyAvoidFuncs ) { if ( func.IsValid() ) func.Destroy() } printl("cleaned") } mark1 = null mark2 = null function mark(me = findFirstPlayer()) { if ( mark1 && mark2 ) { if ( mark2.x >= 0 && mark2.y >= 0 && mark2.z >= 0) { } else printl("invalid mins and maxs") mark1 = null mark2 = null return } if ( !mark1 ) { mark1 = me.GetOrigin() // ClientPrint(null, 3, format("\x079EC34F%s %s\x01", "mark1", mark1.tostring())) ClientPrint(null, 3, format("\x079EC34F%s\x01", "marker 1 placed")) return } mark2 = me.GetOrigin() // ClientPrint(null, 3, format("\x079EC34F%s %s\x01", "mark2", mark2.tostring())) local origin = Vector() local maxs = Vector() if (mark1.x > mark2.x) { origin.x = mark2.x maxs.x = mark1.x } else { origin.x = mark1.x maxs.x = mark2.x } if (mark1.y > mark2.y) { origin.y = mark2.y maxs.y = mark1.y } else { origin.y = mark1.y maxs.y = mark2.y } if (mark1.z > mark2.z) { origin.z = mark2.z maxs.z = mark1.z } else { origin.z = mark1.z maxs.z = mark2.z } maxs -= origin origin.z -= 10 // add a bit extra maxs.z += 20 DebugDrawBox(origin, Vector(), maxs, 255, 255, 255, 150, 50) ClientPrint(null, 3, format("\x079EC34FVector(%f, %f, %f), Vector(%f, %f, %f)\x01", origin.x, origin.y, origin.z, maxs.x, maxs.y, maxs.z)) mark1 = null mark2 = null } } __CollectGameEventCallbacks(noflank) // BlockedAreas = [[Vector(1113.136963, 1984.065674, 22.009033), Vector(345.236572, 876.153076, 171.805664)], // [Vector(-669.346130, 1910.717896, -39.233543), Vector(344.006317, 701.738892, 301.432983)]] ::MyAvoidFuncs <- [] ::BlockedAreas <- [] ::CreateNavBlock <- function( BlockedAreas = ::BlockedAreas ) { local my_nav_avoid foreach (func_size in BlockedAreas) { local borrowed_model = findSuitableModel(func_size[1]) if ( !borrowed_model ) { printl("Unable to find any model") break } my_nav_avoid = SpawnEntityFromTable("func_nav_avoid", { // targetname = "bruh" origin = func_size[0] - borrowed_model.GetBoundingMins(), team = 3, start_disabled = false, tags = "common bomb_carrier", model = borrowed_model.GetModelName() }) my_nav_avoid.SetSize(borrowed_model.GetBoundingMins(), func_size[1] + borrowed_model.GetBoundingMins()) MyAvoidFuncs.append(my_nav_avoid) printl("creating a blocker: " + borrowed_model.GetModelName()) // DebugDrawBox(my_nav_avoid.GetOrigin(), my_nav_avoid.GetBoundingMins(), my_nav_avoid.GetBoundingMaxs(), 255, 255, 255, 255, 10) } } ::biggest_func_cost <- null function findSuitableModel(min_size) { local costEnt_size if ( biggest_func_cost != null ) { if ( biggest_func_cost.IsValid() ) { costEnt_size = biggest_func_cost.GetBoundingMaxs() - biggest_func_cost.GetBoundingMins() if (costEnt_size.x >= min_size.x && costEnt_size.y >= min_size.y && costEnt_size.z >= min_size.z ) { return biggest_func_cost } } else biggest_func_cost = null } local costEnt = null; local funcName = "func_nav_avoid" for ( local i = 0; i < 2; i++ ) { while ( costEnt = Entities.FindByClassname(costEnt, funcName) ) { costEnt_size = costEnt.GetBoundingMaxs() - costEnt.GetBoundingMins() if (costEnt_size.x >= min_size.x && costEnt_size.y >= min_size.y && costEnt_size.z >= min_size.z && costEnt.GetModelName()) { biggest_func_cost = costEnt DebugDrawBox(costEnt.GetOrigin(), costEnt.GetBoundingMins(), costEnt.GetBoundingMaxs(), 255, 255, 255, 140, 50) local boxsize = costEnt.GetBoundingMaxs() - costEnt.GetBoundingMins() printl(format("Box size: %f %f %f", boxsize.x, boxsize.y, boxsize.z)) return costEnt } else { if ( !biggest_func_cost ) { biggest_func_cost = costEnt } else { local biggest_func_cost_size = biggest_func_cost.GetBoundingMaxs() - biggest_func_cost.GetBoundingMins() local volume = biggest_func_cost_size.x * biggest_func_cost_size.y * biggest_func_cost_size.z if ( volume < costEnt_size.x * costEnt_size.y * costEnt_size.z ) biggest_func_cost = costEnt } } } funcName = "func_nav_prefer" } printl("----- Warning: Can't find a big enough model! -----") return biggest_func_cost }