try IncludeScript("advcc_downpour/advcc_soundscapes") catch(e) printl(e) try IncludeScript("advcc_downpour/advcc_fogcontrollers") catch(e) printl(e) IncludeScript("advcc_downpour/advcc_lookups") local ROOT = getroottable() foreach(k, v in ::NetProps.getclass()) if (k != "IsValid" && !(k in ROOT)) ROOT[k] <- ::NetProps[k].bindenv(::NetProps) // we spawn a color correction entity and attach it to the player for each soundscape in the map // once our soundscape changes, fade all other color corrections out and fade one in based on our current soundscape ::GetPlayerUserID <- function(player) { return GetPropIntArray(Entities.FindByClassname(null, "tf_player_manager"), "m_iUserID", player.entindex()) } //The original plan was to only have two color correction ents at a time and use a queueing system, this code is unfinished and doesn't work // ::AdvCC_Think <- function() // { // local targetname = GetPropString(self, "m_iName") // local player = self.GetOwner() // local scope = player.GetScriptScope() // local userid = GetPlayerUserID(player) // local soundscapeindex = GetPropInt(player, "m_Local.m_audio.soundscapeIndex") // local soundscapename = SoundScapeTable[soundscapeindex] // local maxweight = 1.0 // local faderate = 0.02 // //parenting doesn't work correctly for color_correction, update origin every think // self.SetOrigin(player.GetOrigin()) // //we've entered a soundscape with a CC modifier // if (soundscapeindex in AdvCC_Table) // { // if (typeof AdvCC_Table.soundscapename == "table") // { // if ("maxWeight" in AdvCC_Table.soundscapename) // maxweight = AdvCC_Table.soundscapename.maxWeight // if ("fadeRate" in AdvCC_Table.soundscapename) // faderate = AdvCC_Table.soundscapename.fadeRate // } // //primary // if (targetname == format("__cc1_%d", userid)) // { // local curweight = GetPropFloat(self, "m_flCurWeight") // //secondary has been set, start fading the primary out // if (curweight > 0.0 && GetPropString(secondary, "m_netlookupFilename") != "") // { // SetPropFloat(self, "m_flCurWeight", curweight - faderate) // } // } // //secondary // else if (targetname == format("__cc2_%d", userid)) // { // local curweight = GetPropFloat(self, "m_flCurWeight") // SetPropString(self, "m_netlookupFilename", AdvCC_Table[soundscapename]) // //secondary has been set, start fading in // if (GetPropString(self, "m_netlookupFilename") != "" && curweight < maxweight) // { // SetPropFloat(self, "m_flCurWeight", curweight + faderate) // } // //we've reached max weight, switch over to primary // else if (curweight >= maxweight) // { // SetPropString(primary, "m_netlookupFilename", GetPropString(self, "m_netlookupFilename")) // SetPropFloat(primary, "m_flCurWeight", curweight) // SetPropFloat(self, "m_flCurWeight", 0.0) // SetPropString(self, "m_netlookupFilename", "") // } // } // } // //no CC modifier, fade all color corrections out // else // { // local curweight = GetPropFloat(self, "m_flCurWeight") // if (curweight > 0.0) // { // SetPropFloat(primary, "m_flCurWeight", curweight - faderate) // SetPropFloat(secondary, "m_flCurWeight", curweight - faderate) // } // } // return -1 // } ::AdvCC_Events <- { function OnGameEvent_player_spawn(params) { local userid = params.userid local player = GetPlayerFromUserID(userid) player.ValidateScriptScope() local scope = player.GetScriptScope() scope.colorcorrections <- {} scope.userid <- userid local lookups = [] if ("SoundScapeTable" in ROOT) lookups.append(SoundScapeTable) if ("FogControllerTable" in ROOT) lookups.append(FogControllerTable) foreach (lookup in lookups) { foreach (index, name in lookup) { local oldcc = Entities.FindByName(null, format("__cc_%d_%d", index, userid)) if (oldcc != null) oldcc.Kill() if (!(name in AdvCC_Table)) continue local key = AdvCC_Table[format("%s", name)] local file = "" if (typeof key == "table") file = key.file else file = key local cc = SpawnEntityFromTable("color_correction", { origin = player.GetOrigin() // spawnflags = 2, //doesn't exist in tf2 minfalloff = 1, maxfalloff = 1, filename = file }) cc.SetOwner(player) SetPropFloat(cc, "m_flCurWeight", 0.0) SetPropString(cc, "m_iName", format("__cc_%d_%d", index, userid)) cc.ValidateScriptScope() cc.GetScriptScope().AdvCC_Think <- function() { local soundscapeindex = -1 local soundscapename = "" if ("SoundScapeTable" in ROOT) { soundscapeindex = GetPropInt(player, "m_Local.m_audio.soundscapeIndex") if (soundscapeindex != -1 && soundscapeindex in SoundScapeTable) soundscapename = SoundScapeTable[soundscapeindex] } local fogcontroller = null local fogcontrollername = "" if ("FogControllerTable" in ROOT) { fogcontroller = GetPropEntity(player, "m_Local.m_PlayerFog.m_hCtrl") if (fogcontroller) fogcontrollername = GetPropString(fogcontroller, "m_iName") } local player = null try player = self.GetOwner() catch(e) return local scope = player.GetScriptScope() // local userid = GetPlayerUserID(player) local userid = scope.userid local maxweight = 1.0 local fadeinrate = 0.008 local fadeoutrate = 0.008 //parenting doesn't work correctly for color_correction, update origin every think self.SetOrigin(player.GetOrigin()) //we've entered a soundscape with a CC modifier if ((soundscapename in AdvCC_Table && self == scope.colorcorrections[soundscapeindex]) || fogcontrollername in AdvCC_Table) { if (typeof key == "table") { if ("maxWeight" in key) maxweight = key.maxWeight if ("fadeInRate" in key) fadeinrate = key.fadeInRate if ("fadeOutRate" in key) fadeoutrate = key.fadeOutRate } local curweight = GetPropFloat(self, "m_flCurWeight") if (curweight < maxweight) { SetPropFloat(self, "m_flCurWeight", curweight + fadeinrate) } } //no CC modifier, fade this color correction out else { local curweight = GetPropFloat(self, "m_flCurWeight") if (curweight > 0.0) { SetPropFloat(self, "m_flCurWeight", curweight - fadeoutrate) } } if (GetPropFloat(self, "m_flCurWeight") < 0.0) SetPropFloat(self, "m_flCurWeight", 0.0) return -1 } AddThinkToEnt(cc, "AdvCC_Think") scope.colorcorrections[index] <- cc } } } function OnGameEvent_player_disconnect(params) { local userid = params.userid foreach (index, _ in SoundScapeTable) EntFire(format("__cc_%d_%d", index, userid), "Kill") } } __CollectGameEventCallbacks(AdvCC_Events)