Multi Timers

Discussion in 'JS Plugin Releases (RMMV)' started by Shaz, Nov 14, 2015.

  1. Shaz

    Shaz Veteran Veteran

    Messages:
    37,707
    Likes Received:
    11,416
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Multi Timers
    2015.11.14
    by Shaz

    Introduction
    This plugin allows you to have multiple timers running at once, with no timer display, to execute any command after counting down

    How to use
    Add to your plugins folder (name is irrelevant but I use MultiTimers.js). There are no parameters to set.

    Plugin commands are:
    AddTimer key seconds command
    DeleteTimer key
    HasTimer key switchId
    TimeLeft key variableId

    key is any text/number string without spaces, that uniquely identifies the timer, and can be used later to cancel/delete it, see if it is running, and how much time is left. Using the same key in subsequent AddTimer plugin commands replaces the existing timer with the newest one.
    seconds is the number of seconds for the timer to count down.
    command is the command to run after countdown completes. This can be any command to run, but would normally be turning a switch on or off, setting a self switch, or changing a variable.
    switchId is the switch id to be turned on if there is a timer with the specified key.
    variableId is the variable id to be set to the number of seconds remaining on the timer. If there is no timer with the specified key, the variable will be set to 0.

    Keywords that can be used anywhere in the plugin command are:
    <thismap> - current map's id
    <thisevent> - current event's id
    \setSS - set a self switch - format is \setss([map, event, 'A'], true)
    \ss - the value of a self switch - format is \ss([map, event, 'A'])
    \setS - set a switch - format is \sets(switchId, true)
    \s - the value of a switch - format is \s(switchId)
    \setV - set a variable - format is \setv(variableId, value)
    \v - the value of a variable - format is \v(variableId)

    See plugin documentation for examples


    Plugin
    Download from pastebin

    Credit
    - Shaz

    Terms
    - free for use in commercial games

    Notes
    - if you need help setting or checking a timer, post below and I'll help you with the plugin command

    - let me know if you can think of other keywords that might be useful - I couldn't really come up with much
     
    Last edited by a moderator: Nov 15, 2015
    #1
    Black Pagan, Nilom, andrus and 13 others like this.
  2. djDarkX

    djDarkX Retro & Remastered Music Guru Veteran

    Messages:
    2,699
    Likes Received:
    1,887
    Location:
    Currently unsure...
    First Language:
    Music
    Primarily Uses:
    RMMV
    This has a plethora of uses!  Nice going, Shaz!  Might grab this later for a different project.
     
    #2
  3. sertianscompany

    sertianscompany Villager Member

    Messages:
    16
    Likes Received:
    5
    First Language:
    ESP EN
    Great, but is it possible to show more than one timer on the screen? thanks! ;)
     
    Last edited by a moderator: Dec 21, 2015
    #3
  4. Shaz

    Shaz Veteran Veteran

    Messages:
    37,707
    Likes Received:
    11,416
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    This plugin does not show timers on the screen at all. You will need a different plugin for that.
     
    #4
  5. Percival

    Percival Villager Member

    Messages:
    14
    Likes Received:
    0
    First Language:
    Italian
    How can i set a switch to turn off?
     
    #5
  6. Shaz

    Shaz Veteran Veteran

    Messages:
    37,707
    Likes Received:
    11,416
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    If your switch is switch 18, and you want it turned off after 3 minutes (180 seconds), the plugin command would be:

    Code:
    AddTimer Switch18Off 180 \sets(18, false)
    The Switch18Off can be any name you want it to be - it just identifies it uniquely so you can check it later if you have a need, but mostly to make sure something else doesn't overwrite it with a different timer.
     
    #6
  7. Rafael_Sol_Maker

    Rafael_Sol_Maker Almighty God Jabu Veteran

    Messages:
    122
    Likes Received:
    36
    Location:
    Brazil
    First Language:
    Portuguese
    Primarily Uses:
    RMMV
    Pretty dum useful. Good job, Shaz! These scripts are the best, because it give options and flexibility to games (nothing against fancy Battle Systems, ahem).

    I will test the compatibility with my Timer Expansion. If you don't care, maybe I will write an compatibility script for it, so we can have the best of both worlds (timers on and offscreen)

    Although I think I will need to write a script for a future project to put multiple timers on screen (not as HUD, but in-game, I should say).
     
    Last edited by a moderator: Jan 8, 2016
    #7
  8. Shaz

    Shaz Veteran Veteran

    Messages:
    37,707
    Likes Received:
    11,416
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    sure - take what you need :)
     
    #8
  9. Shake0615

    Shake0615 Reanimator Veteran

    Messages:
    118
    Likes Received:
    63
    Location:
    USA
    First Language:
    English
    Primarily Uses:
    RMMV
    Every time I use Delete Timer, no matter the circumstance, it crashes and says "Type Error undefined is not a function." I tried it in a blank project and it still had the same error. I basically do it like this:

    Code:
    Event 1:
    addTimer timer1 75 \sets(10, true)
    timeLeft timer1 7
    
    Event 2:
    deleteTimer timer1
    
    Crashes immediately.
     
    Last edited by a moderator: Jan 24, 2016
    #9
  10. Shaz

    Shaz Veteran Veteran

    Messages:
    37,707
    Likes Received:
    11,416
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Thanks for reporting this.  I've found and fixed the problem.  Please download again from pastebin for the updated version.
     
    #10
  11. Veralisa

    Veralisa Villager Member

    Messages:
    16
    Likes Received:
    8
    First Language:
    English
    Would this work for an open-world harvesting system? Say for example, I have hundreds of carrots spread over my maps that you can pick once every x days. I'd just have to use the 'self-switch off' plugin command to make them harvestable again? If yes, I have a couple of questions!


    1. Will having hundreds of respawnable events across the whole game cause lag? It seems like it might be heavy to manage.


    2. I was just wondering if the timer keeps counting down when the game isn't running! I was thinking a 24 irl hours respawn, so 86400 seconds? xD Is that 86400s worth of actual playtime, or just real life time? S:


    3. Do you have any plans to make the timers compatible with other time systems (e.g. I'm using Orange Time System) to make them work with game time instead?


    Thank you so much! I've been banging my head against the wall and wasting mannyyyy hours trying to event a crops-respawn system to no avail.
     
    #11
  12. MySwordSmitesAll

    MySwordSmitesAll Villager Member

    Messages:
    6
    Likes Received:
    0
    First Language:
    English
    Weird, my Windows Defender is going crazy when I try to download this script. It's never done that for other ones; has the link been compromised? It's detecting "Trojan: Win32/Spursint.A!cl".
     
    #12
  13. Shaz

    Shaz Veteran Veteran

    Messages:
    37,707
    Likes Received:
    11,416
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    @Veralisa I'm so sorry I haven't seen your post until now - I was away from the forums more frequently for a few months starting in February, so it was hard to stay up to date, and you didn't tag me.


    1. It might.  It checks on every frame to see if there are any timers that are due to be triggered.  If you have a few hundred of them, that might slow things down a bit.  The only way to tell is to actually give it a go and check.


    2. No, the timer works on game seconds, not real time.  So it only counts down while the game is being played.


    3. No, I write my scripts and plugins to suit my project, and I share them if I think others will find it useful.  I don't have time to go looking at all other systems to see if I need to change them to be compatible.  You are very welcome to ask for someone else to make a patch or modify the plugin to make them compatible - even if you want to pay someone to do this.  They would need to add a note that they'd done edits though, so it's clear it's not MY timer system as I designed it.  However, doesn't Hudell have some kind of similar timer system that would work with the Orange Time System?


    @MySwordSmitesAll You're downloading it wrong.  Javascript is executable code, so anytime you try to download a .js file, this is going to happen.  What you need to do is click the RAW button at that link, then copy the code, paste it into a blank text document (using notepad or something similarly basic - not MS Word), and save it as a javascript file (to ensure the extension stays as .js and doesn't get changed to .js.txt)
     
    Last edited by a moderator: Jul 20, 2016
    #13
    MySwordSmitesAll likes this.
  14. Jonforum

    Jonforum Veteran Veteran

    Messages:
    1,580
    Likes Received:
    1,360
    Location:
    Canada / Québec
    First Language:
    French
    Primarily Uses:
    RMMV


    Hi @Shaz


    Awsome your script, is what i need :)


    Di you have any idea or solution for me .


    Am trying to do this.


    ◆Command:AddTimer Test<thismap> 5 \setss([<thismap>, <thisevent>, 'A'], false)


    The \setss([<thismap>, <thisevent>, 'A'], false) Not seem work .


    Also try add this.$gameMap.mapId
    \setss([this.$gameMap.mapId, <thisevent>, 'A'], false)


    If you have trick for me ?


    Tank you
     
    #14
  15. Shaz

    Shaz Veteran Veteran

    Messages:
    37,707
    Likes Received:
    11,416
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    this doesn't mean anything.  <thismap> means something, because I've made it mean something.


    Can you please show a screenshot of your event?  Include the whole event window, and if it has multiple pages, show one screenshot for each page.
     
    #15
  16. Jonforum

    Jonforum Veteran Veteran

    Messages:
    1,580
    Likes Received:
    1,360
    Location:
    Canada / Québec
    First Language:
    French
    Primarily Uses:
    RMMV
    ok 


    I have this in my plugin


    I add 
        $gameSwitches.setValue(13, true);
    this appen eatch time player transfer map


    Scene_Map.prototype.create = function() {
    Scene_Base.prototype.create.call(this);
    this._transfer = $gamePlayer.isTransferring();
    var mapId = this._transfer ? $gamePlayer.newMapId() : $gameMap.mapId();
    $gameSwitches.setValue(13, true);
    DataManager.loadMapData(mapId);
    };


    The gameSwitch(13) will active one time this kind of event on eatch map.
    And This event generate random ressource ( rock, grass, .... ) on the map load.


    Rigthclik, open new windows for fullscreen


    page1.jpg


    This is the ◆Commande:GenerateMap


    command === 'GenerateMap') {

    for (g = 1; g <= MapNBMaxRock; g++) {
    // mapid, eventid, regionid, respawn after map transfer (le random generete des modele aléatoir, voir map 0004)
    //modele roche 1 a 6
    $gameMap.copyEventFromMapToRegion(4, 1 + Math.floor(Math.random() * 6), 2, true);
    console.log('G= ' + g);
    }




    After i want your time to maybe about 400 Second.
    So ressource will never generate again, when player will come to this map, befor your timer finish.
    When your time finish, if player enter in this map, il will generate random ressource again.
    i dont know if your are understant


    Sorry for poor english. :)
     
    #16
  17. Shaz

    Shaz Veteran Veteran

    Messages:
    37,707
    Likes Received:
    11,416
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    What's on tab 2 of that event?


    Please change the plugin call to reference <thismap> rather than this.$gameMap.mapId - it won't work unless you do that.


    Once we figure out what the problem is, there's another issue.  If the timer hasn't run out and the player comes back to this map, then the timer runs out while the player is ON the map, I think your event will run again, which means the map might regenerate while the player's on it.  Is that what's actually happening?  You said it doesn't work, but "doesn't work" could mean a lot of things - I just assumed you meant the self switch never turned off.


    And, of course, you'll have to change the 5 to 400 to make it run after 400 seconds.
     
    Last edited by a moderator: Aug 27, 2016
    #17
    Jonforum likes this.
  18. Jonforum

    Jonforum Veteran Veteran

    Messages:
    1,580
    Likes Received:
    1,360
    Location:
    Canada / Québec
    First Language:
    French
    Primarily Uses:
    RMMV
    Tanks you @Shaz


    i forget a parralele processe they close alway variable


    now i can see is working good with


    console.log($gameTimer._timers["GENROCK2"]);



    Nop because the game engine are JAP, and JAP read Left to right.
    So the priority page are right [Page2].


    But all work fine now is awesome tank you
     
    #18
  19. Shaz

    Shaz Veteran Veteran

    Messages:
    37,707
    Likes Received:
    11,416
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Uh - game engine being Japanese has nothing to do with it.  If both pages have conditions that are met, page 2 will have priority.  For ANY language version.
     
    #19
  20. Jonforum

    Jonforum Veteran Veteran

    Messages:
    1,580
    Likes Received:
    1,360
    Location:
    Canada / Québec
    First Language:
    French
    Primarily Uses:
    RMMV
    yep but is not like this in unity , a american game engine 
     
    #20

Share This Page