Welcome to PlagueFest.com! Log in or Sign up to interact with the Plague Fest community.
  1. Welcome Guest! to interact with the community and gain access to all the site's features.

Tutorial Round to round persistent variables (and outputs in general).

Discussion in Resources & Tutorials started by enviolinador, Apr 25, 2013

  1. May 31, 2012
    Posts
    As most of you know, the whole levels thing has gone pretty far within ZE to the point where it is starting to feel obnoxious. One of the most common problems with level systems (that most people usually talk about anyway) is the fact that they always require a few entities (although they aren't that many and most of the people just like to exagerate problems). I have been focusing on some particular parts of the engine (because I feel that they can be exploited to achieve coolio-ish things) and I have, from this, understood the strengths of AddOutput.

    As I assume that you know what AddOutput does (https://developer.valvesoftware.com/wiki/AddOutput if not), you'll know that we've been mostly used it to change entity properties... How fancy!

    That is, however, the least important use of it (it is called AddOutput after all, not ChangeProperty). AddOutput can add new outputs to existing entities. So what? So you can have a trigger that does 'nothing' at round start and dynamically change the way it works.

    AddOutput follows a not-too-complex syntax for this, which is as follows:

    OnMyEvent -> MyEntity -> AddOutput -> OnMyNewEvent AnotherEntity:SomeInput:Parameter:Delay:Times -> 0.00

    This would add a new output to MyEntity, triggered OnMyNewEvent, that would fire SomeInput on AnotherEntity with Parameter after a Delay; it could be done Times.

    What does this have to do with anything? Well, if you didn't know, there are some entities in Source that are round persistent (to name a few we have the players, func_brushes, trigger_soundescapes, point_viewcontrols, etc; you can read more @ Valve's dev wiki). Those entities will retain the outputs you add to them, making them a perfect way to store levels using little to few entities (and even more considering all entities have a set of inputs/outputs, the OnUser1-4, FireUser1-4 thingies, that can be used for said on-the-fly modifications). With this, you could progressively save an output adding one to a counter for each level won (or subtracting one, if you wish, for the admin room), and have an 'infinite' (not quite, math_counters contain an integer value I believe, and there's a maximum of 2048 logical entities) amount of numbery numbers for your whatever-mathematical endeavours.

    Finally, and just to be a bit more absurd with it, you don't even need any of those fancy persistent entities mencioned before, since there's an entity that always exists. To make a reference to it, the classname must be used (as a reminder, you can use classnames within the entity I/O system to 'address' all the entities of a given class). This means, we have to address one lonely long forgotten entity friend, worldspawn.

    Want to get it working? Ok, do this:

    1. Make dummy entities
    -- 1.a Add a trigger (check the clients flag, please)
    -- 1.b Add a math_counter and some logic to detect its value
    2. Add to said trigger the following output:
    - OnStartTouch -> worldspawn -> AddOutput -> OnUser1 Counter:Add:1:0:-1
    3. Test that it adds, and that it remains from round to round

    And that's it. Enjoy.
    • Like Like x 1
    • Mapping King Mapping King x 1
      enviolinador, Apr 25, 2013 Last edited by enviolinador, Apr 25, 2013
    • Oct 4, 2012
      Posts
      Oh god, this. I think I finally understand it now.
    • May 15, 2011
      Posts
      To get rid of those damn smilies use [plain][/plain].

      Example: [plain]:Parameter:Delay[/plain]

      Those smilies are really annoying.
    • May 31, 2012
      Posts
      Thank you for this, they are really annoying to me too.