Panorama Utils

edited September 2015 in Projects

I haven't found anything like this so maybe have this as a thread to post Panorama snippets/utils?

JavaScript example: timed loops (edit: if there was anyone actually using this there was an update that fixed a bug making only one loop able to run at a time)

//Runs a function periodically
//start - how much of an additional delay to have (on top of the tick refresh) (set this to -1 to run the function immediately
//time - how long to run for. set this to -1 to run infinitely
//tick - how many seconds to elapse between ticks (assumes time / tick is an integer) (set this to negative to run a set amount of ticks, e.g. -30 will run 30 ticks in whatever time period given)
//func - func to run (return true to cancel)
//UPDATE June 29 2015 - fixed some enclosure issues, added a safecheck for time overflow
$.Every = function(start, time, tick, func){
    var startTime = Game.Time();
    var tickRate = tick;
    if(tick < 1){
        if(start < 0) tick--;
        tickRate = time / -tick;
    }

    var tickCount =  time/ tickRate;

    if(time < 0){
        tickCount = 9999999;
    }
    var numRan = 0;
    $.Schedule(start, (function(start,numRan,tickRate,tickCount){
        return function(){
            if(start < 0){
                start = 0;
                if(func()){
                    return;
                }; 
            }  
            var tickNew = function(){
                numRan++;
                delay = (startTime+tickRate*numRan)-Game.Time();
                if((startTime+tickRate*numRan)-Game.Time() < 0){
                    $.Msg('[ERROR] Function ' + func + ' taking too long to loop!')
                    delay = 0;
                }
                $.Schedule(delay, function(){
                    if(func()){
                        return;
                    };
                    tickCount--;
                    if(tickCount > 0) tickNew();
                });
            };
            tickNew();
        }
    })(start,numRan,tickRate,tickCount));
};
//usage example:

$.Every(0, 10, -30, function(){
    $.Msg('HI ' + Game.Time());
});

//30 times in the next 10 seconds, print the game time

MAKE CUSTOM GAMES GREAT AGAIN

Finished-
kv checker - https://arhowk.github.io
panorama video series - https://moddota.com/forums/discussion/2021/inclusive-panorama-tutorial-quest-box

My pet project This Cursed World/Crestfallen (name pending)
https://moddota.com/forums/discussion/986/this-cursed-world-rpg#latest

Comments

  • edited October 2015 Posts: 858

    Creating a global namespace

    --EDIT: I have to update this to use data()

    MAKE CUSTOM GAMES GREAT AGAIN

    Finished-
    kv checker - https://arhowk.github.io
    panorama video series - https://moddota.com/forums/discussion/2021/inclusive-panorama-tutorial-quest-box

    My pet project This Cursed World/Crestfallen (name pending)
    https://moddota.com/forums/discussion/986/this-cursed-world-rpg#latest

  • edited October 2015 Posts: 858

    Is anyone interested in the lib i used to make this tooltip?

    enter image description here

    Basically, you pass it a parent frame (in this case i passed it that item) and it will return a frame that you can put children into. The frame will automatically position and size itself to the frame you pass it. For ex, here's the code shown in that image


    var x = $.CreatePanel("Panel", globalContext.ShowTooltip($.GetContextPanel()), 'ItemTooltip'); x.SetAttributeInt("item", item); x.BLoadLayout( "file://{resources}/layout/custom_game/mmoui/inventory_tooltip.xml", false, false );

    the styling (gray background, black border, fade in) is automatically taken care of by the css of the container.

    Also, I'd like to do the following panorama elements (doing these small little 30 line things is easier for me than working on TCW

    -LuaCall

    --in js
    $.LuaCall("getItemSpecial", item, function(itemSpecial, someOtherVariable){
        $.Msg("Item Special Table", itemSpecial, someOtherVariable);
    });
    
    $.LuaListen("hideButtons", function(buttonsToHide, player){
        //do sutin
    });
    
    --in Lua
    
    LuaCall:Listen("getItemSpecial", function(item)
        return itemDataTable[item], "lol nothing"
    end)
    
    LuaCall:Call("hideButtons", SOME_BUTTON_CONST, 0, function() print("The corresponding function returns nothing, so this just runs when the handshake is complete.) end)
    
    --alternative api
    
    LuaCall:hideButtons(SOME_BUTTON_CONST,0)
    $.onQuitButtonClicked()
    --the names are automatically assumed after the $.LuaListen and LuaCall:Listen calls
    

    so it takes care of game event stuff much easier and much prettier.

    -QuickSetup - Show some options to the host without any needed panorama knowledge

    QuickSetup:AddCheckboxOption("Difficulty", "Easy", "Medium", "Hard")
    QuickSetup:AddNumberOption("Max Mobs");
    
    var difficulty = QuickSetup:GetOption("Difficulty") --would return "Easy", etc
    

    -LuaExecute - execute arbitrary lua code (dangerous :D)

    $.LuaExecute(""
    + "var x = 5\n",
    + "GameRules:IHaventModdedInForever(x)");
    

    -CustomHUDElement - Suggest panorama elements for me to make! I'm up for a challenge :D

    <Panel id="TestCustomHUDElement" class="HTMLScrollWindow OtherStylingOptions" />
    

    -Spriter : Support for sprite sheets
    http://www.fabiobiondi.com/blog/wp-content/uploads/2012/08/runningGrant.png

    MAKE CUSTOM GAMES GREAT AGAIN

    Finished-
    kv checker - https://arhowk.github.io
    panorama video series - https://moddota.com/forums/discussion/2021/inclusive-panorama-tutorial-quest-box

    My pet project This Cursed World/Crestfallen (name pending)
    https://moddota.com/forums/discussion/986/this-cursed-world-rpg#latest

  • Old thread, I know.

    Hey, have you ever done anything with that QuickSetup? Or any mods that use something similar? I'm looking to add host options but don't want to reinvent the wheel if I don't have to.

  • edited August 2016 Posts: 858

    No, this thread was planned to be part of RPGMap (basically the same concept except its just a bunch of extensible plugins used for RPGs) before I just gave up on that and decided to make my own RPG.

    Mods that I know use that kind of stuff right off my head are like... petri reborn, angel arena, guarding athena, idk.

    Tbh it's not alot of code, just a Panel definition with a custom game event message.

    If you feel like making it go ahead and post it here

    (It will be included in the release of Skyguard but thats not slated for another 4 years)

    MAKE CUSTOM GAMES GREAT AGAIN

    Finished-
    kv checker - https://arhowk.github.io
    panorama video series - https://moddota.com/forums/discussion/2021/inclusive-panorama-tutorial-quest-box

    My pet project This Cursed World/Crestfallen (name pending)
    https://moddota.com/forums/discussion/986/this-cursed-world-rpg#latest