Effects / Buffs


  • Forum Admin

    There is a new script function player.seteffect(duration, type, params) which can set several effects or "buffs". Here a script for testing it:

    function onPlayerSays(pl) {
        switch (pl.chat) {
            case "effect slow":    { pl.seteffect(10, "speed",  {factor:0.5}); break; }
            case "effect fast":    { pl.seteffect(10, "speed",  {factor:2}); break; }
            case "effect hurt":    { pl.seteffect(10, "hurt",   {hp:1}); break; }
            case "effect heal":    { pl.seteffect(10, "heal",   {hp:1}); break; }
            case "effect damage":  { pl.seteffect(10, "damage", {hp:10}); break; }
            case "effect shield":  { pl.seteffect(10, "shield", {hp:10}); break; }
            case "effect inverse": { pl.seteffect(10, "inverse"); break; }
            case "effect freeze":  { pl.seteffect(10, "freeze"); break; }
        }
    }
    

    It's setting a temporary effect, such as inverse movement ala Bomberman. Additionally there are the new events onEffectStart and onEffectEnd in player.js which can be used to change the look of the player, such as setting player.aniarg1 to add particles to the player:

    function onEffectStart(player, type) {
        echo("effect starts: " + player.name + " -> " + type);
    }
    function onEffectEnd(player, type) {
        echo("effect ends: " + player.name + " -> " + type);
    }
    

    I will try to also setup a more complete example later.



  • This looks great! I really like the progress of your engine


  • Forum Admin

    Example of NPC which sets the player on fire on collision:

    1. Add animations/effect_fire.bani to Files

    This is basically an empty animation with one emitter which has a position and interval so that it's automatically emitting new particles each few moments.

    {
      "filetype": "bbuilderani",
      "aniversion": 1,
      "copyright": "2019 iAppsBeats LTD",
    
      "options": {
        "particlescontinueafterdeath": true
      },
    
      "defaults":{
      },
    
      "emitters": {
        "1": {
          "position": [16,-8,0],
          "relative": false,
          "interval": 0.15,
          "reduceonmobile": false,
          "quantity": [0,2],
          "limit": 50,
          "draworder": "up",
    
          "particles": [
            {
              "lifetime": [1,1.4],
              "image": "bbuilder_smoke.png",
              "mode": "add",
              "alpha": 1,
              "zoom": 0.2,
              "red": 1,
              "green": 0.25,
              "blue": 0,
              "rotation": [0, 360],
              "spin": [0, 5],
              "zangle": 120,
              "gravity": 80,
    
              "effects": [
                {"type":"range","time":[0.5,1.4],"attr":"alpha","mode":"replace","value":[1,0.05]},
                {"type":"range","time":[0.05,0.2],"attr":"zoom","mode":"replace","value":[0.2,0.35]},
                {"type":"range","time":[0.5,1.4],"attr":"zoom","mode":"replace","value":[0.35,0.05]}
              ]
            }
          ]
        }
      },
    
      "sprites":{
         "1": {"gfx":"bbuilder_smoke1.png", "bounds": [0, 0, 128, 128]}
      },
    
      "frames":[
      ]
    }
    

    2. Add an NPC with /addscriptnpc and call seteffect on "touch"

    function onCreated() {
        this.ani = "player_idle";
        this.head = "bbuilder_head1.png";
        this.body = "bbuilder_body1.png";
        
        this.aniarg1 = "effect_fire.bani";
    }
    function onUpdated() {
        this.onCreated();
        this.save();
    }
    function onPlayerTouchsMe() {
        player.seteffect(10, "hurt", {hp:1});
        player.aniarg1 = this.aniarg1;
        player.showmessage("Oh no you got burned!");
    }
    

    3. In scriptfiles/players.js clear the particles in onEffectEnd

    function onEffectEnd(player, type) {
        if (player.aniarg1 && player.aniarg1.startsWith("effect"))
            player.aniarg1 = null;
    }
    

    Note: Instead of aniarg1 you can also use 2..9
    Note: Right now setting a bani file to aniarg1 is only working for particles, not regular animations with sprites



  • wow stefan I love these new appsbeats scripts, I love keep it up!.


Log in to reply