How do I change spawn locations when a team wins a certain amount of wins?

Grassen

L1: Registered
Feb 15, 2024
19
0
So recently i've started to play around with math_counter entity to add to a map. What came to mind was, let's say red team wins 3 rounds the map changes spawnpoints and if blue wins a round it removes a "counter" to the score, making it so red does not progress to the next area of the map. How would I go about recreating this?
(I've attached screenshots to see what I have so far)
 

Attachments

  • math1.png
    math1.png
    328.9 KB · Views: 7
  • math2.png
    math2.png
    335.2 KB · Views: 7
  • math3.png
    math3.png
    329.2 KB · Views: 9
  • math4.png
    math4.png
    323 KB · Views: 7
  • math5.png
    math5.png
    353.7 KB · Views: 8
  • math6.png
    math6.png
    334 KB · Views: 7

Box Of Paper

L3: Member
Jul 15, 2019
128
159
If you really want to use a math_counter you could turn it into a preserved entity by changing its classname (https://developer.valvesoftware.com/wiki/S_PreserveEnts) and then check the value at the start of every round to do what you need to do...

On a new round the original math_counter will be respawned while the preserved one still lingers; leading to two copies with the same targetname. You can workaround this with a logic_auto but there are problems there too and this time in the hammer editor itself.

For a working prefab you can check out the "Preserved Entities" section of the Box Of Features I made a while ago at https://tf2maps.net/downloads/prefabs-box-of-features.10818/.

But with VScript this is no longer needed.

I'll paste here the script and attach a demo .vmf to play around with.
C:
// Setting the "town_mood" value
::town_mood <- "town_mood" in getroottable() ? ::town_mood : 0

// Defining this entity's methods
function Increase() {
    if (::town_mood < 3) ::town_mood++
    ClientPrint(null, 3, "\x07FF3F3FRed\x07EEFFAA wins! Increasing the score to \x07FFFFFF"+::town_mood)
}

function Decrease() {
    if (::town_mood > 0) ::town_mood--
    ClientPrint(null, 3, "\x0799CCFFBlue\x07EEFFAA wins! Decreasing the score to \x07FFFFFF"+::town_mood)
}

// Checking this round's "town_mood"
switch (::town_mood) {

    case 3:
        for (local spawn; spawn = Entities.FindByName(spawn, "spawn_town_*");) spawn.AcceptInput("Disable", "", null, null)
        for (local spawn; spawn = Entities.FindByName(spawn, "spawn_otherside_*");) spawn.AcceptInput("Enable", "", null, null)
        self.AcceptInput("FireUser1", "", null, null)
        break

    default:
        for (local spawn; spawn = Entities.FindByName(spawn, "spawn_town_*");) spawn.AcceptInput("Enable", "", null, null)
        for (local spawn; spawn = Entities.FindByName(spawn, "spawn_otherside_*");) spawn.AcceptInput("Disable", "", null, null)
        self.AcceptInput("FireUser2", "", null, null)

}

// Debug print
ClientPrint(null, 3, "----- ---- --- -- -")
ClientPrint(null, 3, "\x07EEFFAACurrent town mood: \x07FFFFFF"+::town_mood)
ClientPrint(null, 3, "\x07EEFFAAWin as \x07FF3F3FRed\x07EEFFAA to increase the value or win as \x0799CCFFBlue\x07EEFFAA to decrease it!")
ClientPrint(null, 3, "----- ---- --- -- -")

Basically: we are using the VScript "Root table" (::town_mood is stored in it) which is preserved between rounds.

To use the VScript, go to C:\Program Files (x86)\Steam\steamapps\common\Team Fortress 2\tf\scripts\vscripts (or wherever you setup your TF2, create the folders if needed) and create a town_mood.nut file; then open it with any text editor and paste the above script.

Then in hammer you have to place a logic_script and set its Entity Scripts property to town_mood.nut; then set its name to something like town_mood.

That's it! You may now OnRoundWin town_mood RunScriptCode Increase() to update the town's mood!
I wasn't sure of what you were planning so I just went with a simple and generic solution.
Update the VScript as you wish, and if you need help, ask away!

You may hook your outputs to the FireUser1 and FireUser2 to just work within hammer or you may go crazy and just do everything with VScript.

Just make sure you remember to pack the script into your .bsp when you want to share the map! It's a tad annoying but I think it's worth it.
I personally use VIDE (https://www.tophattwaffle.com/packing-custom-content-using-vide-in-steampipe/) but I heard good things about CompilePal.

PS... why didn't I just hook the spawn enabling and disabling to the FireUsers? Simply because it doesn't work otherwise! VScript has this really nice quirk that it runs BEFORE player spawning but AFTER every entity has loaded, thus we can immediately disable the spawns we don't want.

town_mood_thumbnail.png
 

Attachments

  • town_mood_vscript.zip
    1.3 MB · Views: 4
Last edited:

Grassen

L1: Registered
Feb 15, 2024
19
0
This is really beautiful! I never thought that vscript can be used in such way. I'll be sure to ask further questions once i've played around with it. As for my plan for this map, its essentially a zombie infection map based off the town of Silent Hill. Everytime red wins the town becomes "enraged" when red wins 3 consecutive times, the area changes to favor zombies a bit more. Likewise, if zombies win before red reaches those 3 wins, it removes one point from the 3 leaving the 2. Also when red reaches 3 points it resets back to 0

Edit: i have zero idea with vscript as you may know just started with this. :')
 
Last edited: