View unanswered posts | View active topics It is currently 18 Sep 2018 20:40

Forum rules


- Use common sense and be respectful towards each other at all times, even when disagreeing.
- Do not reveal sensitive game information. Guild secrets, player seconds are examples of things not allowed.



Reply to topic  [ 9 posts ] 
Genesis Webclient 
Author Message
Apprentice

Joined: 13 Sep 2013 16:58
Posts: 25
Hello everyone,

I was wondering, are people using the webclient any? If so, is there an interest for triggers?
Maybe we could create a set of usable ones together?

Below is an example of how to create a script for the web client, I havent played much on it,
but I figured you would find it lacking in this area. Try it, improve upon it, enjoy it. This is an
old nugget of code that I created when the webclient came out, havent really used it since..

Keep this is mind: "Scripting in the game is tolerable, but botting is NOT."

All this would enter an alias named script, with the alias you can use things like, "script <name>",
"script off", "script pause", for it to move to the next command it uses "script step".
Code:
gwc.userdata.script.scriptlist = [
     ["RedFang",
      "nw|kill goblin", "kill wolf", "w|kill goblin", "kill wolf", "nw|kill goblin", "kill wolf",
      "n|kill goblin", "kill wolf", "n|kill goblin", "kill wolf", "ne|kill goblin", "kill wolf",
      "s|kill goblin", "kill wolf", "s|kill goblin", "kill wolf", "e|kill goblin", "kill wolf",
      "n|kill goblin", "kill wolf", "n|kill goblin", "kill wolf", "e|kill goblin", "kill wolf",
      "s|kill goblin", "kill wolf", "s|kill goblin", "kill wolf", "e|kill goblin", "kill wolf",
      "n|kill goblin", "kill wolf", "n|kill goblin", "kill wolf", "e|kill goblin", "kill wolf",
      "w|w|w|w|sw|s|s|se|e|se"],
     ["OtherExampleScript", "first command|second command", "do something else"],
     ];
 
  if (gwc.userdata.script.pause == "on") { return; }
 
  function sList() {
    var string = [];
    gwc.userdata.script.scriptlist.forEach(function(list) {
      string.push(list[0]);
    });
    return string;
  }
  switch(args[1]) {
    case "off":
      if (gwc.userdata.script.scriptvars[0] == "true") {
        gwc.output.append("You have turned off the "+
          gwc.userdata.script.scriptvars[1]+" script");
        gwc.userdata.script.scriptvars = ["false", "", ""];
      } else {
        gwc.output.append("You currently have no active scripts.");
      }
        break;
     
    case "pause":
      if (gwc.userdata.script.scriptvars[0] == "true") {
        gwc.userdata.script.scriptvars[0] = "pause";
        gwc.output.append("Your script is now paused.");
      } else if (gwc.userdata.script.scriptvars[0] == "pause") {
        gwc.userdata.script.scriptvars[0] = "true";
        gwc.output.append("Your script is no longer paused.");
      } else {
        gwc.output.append("You have no active script.");
      }
        break;
     
    case "step":
      if (gwc.userdata.script.scriptvars[0] == "true") {
        gwc.userdata.script.scriptlist.forEach(function(dest){
          if (dest[0].match(gwc.userdata.script.scriptvars[1]))
          {
            if (dest[gwc.userdata.script.scriptvars[2]]) {
              var step = dest[gwc.userdata.script.scriptvars[2]].split("|");
                step.forEach(function(go){
                  setTimeout(function() {
                    gwc.connection.send(go, true);
                  }, 120);
                });
            gwc.userdata.script.scriptvars[2]++;
            } else {
              gwc.connection.send("script off", true);
            }
          }
        });
      }
        break;
     
    default:
      if (args[1] && args[1].match(sList().join('|'))) {
        gwc.output.append(args[1]+" has now been activated.");
        gwc.userdata.script.scriptvars = ["true", args[1], "1"];
        gwc.connection.send("script step", true);
      } else {
        gwc.output.append("You may only choose from the listed scripts. "+
                          sList().join(', '));
      }
        break;
  }


If you want it to move, like in a "You search everywhere, but find no such herbs" situation, you
simply

Code:
gwc.connection.send("script step", true);


Regards,
The Friendly Trigger Helper.


16 Feb 2018 08:44
Profile
Adventurer
User avatar

Joined: 12 Feb 2017 06:07
Posts: 87
Location: Studying spell scrolls
Thank you!


17 Feb 2018 04:13
Profile
Beginner

Joined: 12 Oct 2017 19:31
Posts: 10
I've written a bunch for the Web UI as well. Thanks for sharing.

I use this one for my kill alias. Provides random emotes and war cries to help spice up my Merc/Pirate character:

act = [
"mspit",
"mnarrow",
];

cries = [
"tsnarl Have a face full o' me boot ye jelly boned thumb suckin' crud bucket !",
"shout example 2",
];

var item = act[Math.floor(Math.random()*act.length)];
var cry_item = cries[Math.floor(Math.random()*cries.length)];

if (args[1] !== undefined){
gwc.userdata.last_target = args['*'];
gwc.connection.send( item + ' ' + args['*'] );
gwc.connection.send( cry_item );
gwc.connection.send( 'mattack ' + args['*'] );
gwc.connection.send( 'pbash');
}
else{
gwc.output.append('Kill what?');
gwc.output.color('red');
}


17 Feb 2018 07:26
Profile
Apprentice

Joined: 26 Jul 2017 23:08
Posts: 45
Carnak

It is perfect. Thanks a lot. But I would like to ask you, more advanced in java coding, how to add to Carnak's code checking if someone is already fighting on the location? Just to avoid kill steal? Since this is the most oftec crime relafed with scripts and scripters. Their code dont check if someone is not already fighting on the location....


17 Feb 2018 10:10
Profile
Apprentice

Joined: 13 Sep 2013 16:58
Posts: 25
Saimon wrote:
Carnak

It is perfect. Thanks a lot. But I would like to ask you, more advanced in java coding, how to add to Carnak's code checking if someone is already fighting on the location? Just to avoid kill steal? Since this is the most oftec crime relafed with scripts and scripters. Their code dont check if someone is not already fighting on the location....

Well, the simplest way to do it, without altering the script alias would probably be to add a checkroom alias in with your scripts. Like so:
"w|n|checkroom kill orc", "w|checkroom kill wolf"

And then you create an alias named checkroom and insert something along the lines of this:
Code:
if (!args[1]) { return; }

if (!gwc.userdata.script.checkroom) {
    gwc.userdata.script.checkroom = [];
}
 
if (!gwc.userdata.script.checkroom.timer) {
    gwc.connection.send("glance");
    gwc.userdata.script.checkroom.timer = setTimeout(function() {
        if (!gwc.userdata.script.checkroom.occupied) {
            gwc.connection.send(args['*'], true);
        } else {
            gwc.connection.send("script step", true);
        }
        gwc.userdata.script.checkroom = [];
    }, 500);
}

And then you would need a trigger to prevent you from attacking in the room, youd need something like:

Pattern: "are fighting eachother"
Code:
if (gwc.userdata.script.checkroom.timer) {
    gwc.userdata.script.checkroom.occupied = 1;
}


Untested, on-the-fly code. Use this code for the good of all mankind.
Carnak.


Last edited by Carnak on 21 Feb 2018 01:34, edited 1 time in total.



20 Feb 2018 03:14
Profile
Apprentice

Joined: 13 Sep 2013 16:58
Posts: 25
I remember that creating accurate color triggers was an annoying task to say the least. I came up with this in the past to be able to create string specific coloring. This code may be a bit high when it comes to consumption of processing power. Have any of you arrived at any better solutions?

Pattern: ^(.*)
Code:
  function strip(html){
      var doc = new DOMParser().parseFromString(html, 'text/html');
      return doc.body.textContent || "";
  }
   
  function decode(str) {
      str = strip($('<textarea />').html(str).text());
      return decodeURIComponent(str);
  }
 
  function escapeRegExp(str) {
      return str.replace(/([.*'<>+?^=!:$\{\}\(\)\[\]\/\\])/g, ".");
  }
 
  function ListRegex(regex, str) {
      if (! regex.global) {
          throw new Error('Please set flag /g of regex');
      }
      return (str.match(regex) || []);
  }
 
  function replaceAll(str, find, replace) {
      return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
  }
   
  function uniq(a) {
      var seen = new Set();
      return a.filter(function(x) {
          return !seen.has(x) && seen.add(x);
      });
  }
   
  // ** COLOURS **
   
  function colors(str) {
      var ColorList = [
          ["darkmagenta",
           "you", "You", gwc.gmcp.data.character.status.name,
          // Team
          ],
          ["red",
          // Health
           "at death's door", "barely alive", "terribly hurt",
           "in a very bad shape", "in agony", "in a bad shape",
           "very hurt", "suffering", "hurt", "aching", "somewhat hurt",
           "slightly hurt", "sore", "feeling well", "feeling very well",
          // Low Durability
           "a little worn down",
          // Combat
           "beat", "seriously beat",
           "pound", "seriously pound",
           "batter",
          ],
     
          ["lime",
          // High Durability
           "in prime condition", "in a fine condition"],
          ["aqua",
          // Progress
           "a tiny amount of progress", "minimal progress",
           "slight progress", "low progress", "a little progress",
           "some progress", "modest progress", "decent progress",
           "nice progress", "good progress", "very good progress",
           "major progress", "great progress", "extremely good progress",
           "awesome progress", "immense progress", "tremendous progress",
           "fantastic progress"
          ],
       
          ["white",
          // Equipment
           "sturdy black greaves", "sturdy black bracers", "black platemail",
          ],
         
          //["ADDCOLOR",""]
      ];
   
      str = decode(str);
   
      for (k = 0; k < ColorList.length; k++) {
          var regex = new RegExp(escapeRegExp(ColorList[k].slice(1).join('|')), 'g');
          var matches = uniq(ListRegex(regex,str));
          for (l = 0; l < matches.length; l++) {
              str = replaceAll(str, matches[l], matches[l].fontcolor(ColorList[k][0]));
          }
      }
   
      if (str.match(/obvious exit?.\:/g)) {
          var exits = gwc.gmcp.data.room.exits;
         
          exits.sort(function(a, b){
              return b.length - a.length;
          });
       
          exits.forEach(function(w) {
              str = replaceAll(str, w, w.fontcolor("white"));
          });
      }
     
      return str.fontcolor("green");
  }
 
  gwc.output.replace(decode(args[1]), colors(args[1]));


I would enjoy your input.

Regards,
Carnak


20 Feb 2018 06:53
Profile
Wizard
User avatar

Joined: 03 Mar 2014 13:03
Posts: 139
Location: US West
This looks super helpful, except for the part where I don't know JS. Lua seemed easier to learn so I went with Mudlet.
But now I might start using this stuff so I can have some of my triggers/scripts on mobile...


21 Feb 2018 02:24
Profile
Apprentice

Joined: 13 Sep 2013 16:58
Posts: 25
Carnak wrote:
I remember that creating accurate color triggers was an annoying task to say the least. I came up with this in the past to be able to create string specific coloring. This code may be a bit high when it comes to consumption of processing power. Have any of you arrived at any better solutions?

Pattern: ^(.*)
Code:
  function strip(html){
      var doc = new DOMParser().parseFromString(html, 'text/html');
      return doc.body.textContent || "";
  }
  ...


I would enjoy your input.

Regards,
Carnak


Noticed that there was an outdated function still in play, and an error in handling words within <>, this code should work better.
Code:
function decode(html){
    var doc = new DOMParser().parseFromString(html, 'text/html');
    return doc.body.textContent || "";
}

function escapeRegExp(str) {
    return str.replace(/([.*'<>+?^=!:$\{\}\(\)\[\]\/\\])/g, ".");
}

function ListRegex(regex, str) {
    if (! regex.global) {
        throw new Error('Please set flag /g of regex');
    }
    return (str.match(regex) || []);
}
 
function replaceAll(str, find, replace) {
    return str.replace(new RegExp(escapeRegExp(find), 'g'), replace);
}
   
function uniq(a) {
    var seen = new Set();
    return a.filter(function(x) {
        return !seen.has(x) && seen.add(x);
    });
}
   
// ** COLOURS **
   
function colors(str) {
    var ColorList = [
        ["darkmagenta",
         "you", "You", gwc.gmcp.data.character.status.name,
        // Team
        ],
        ["red",
        // Health
         "at death's door", "barely alive", "terribly hurt",
         "in a very bad shape", "in agony", "in a bad shape",
         "very hurt", "suffering", "hurt", "aching", "somewhat hurt",
         "slightly hurt", "sore", "feeling well", "feeling very well",
        // Low Durability
         "a little worn down",
        // Combat
         "beat", "seriously beat",
         "pound", "seriously pound",
         "batter",
        ],
     
        ["lime",
        // High Durability
         "in prime condition", "in a fine condition"],
        ["aqua",
        // Progress
         "a tiny amount of progress", "minimal progress",
         "slight progress", "low progress", "a little progress",
         "some progress", "modest progress", "decent progress",
         "nice progress", "good progress", "very good progress",
         "major progress", "great progress", "extremely good progress",
         "awesome progress", "immense progress", "tremendous progress",
         "fantastic progress"
        ],
     
        ["white",
        // Equipment
         "sturdy black greaves", "sturdy black bracers", "black platemail",
        ],
         
        //["ADDCOLOR",""]
    ];
   
    // Handles coloring
    for (k = 0; k < ColorList.length; k++) {
        var regex = new RegExp(escapeRegExp(ColorList[k].slice(1).join('|')), 'g');
        var matches = uniq(ListRegex(regex,str));
        for (l = 0; l < matches.length; l++) {
            str = replaceAll(str, matches[l], matches[l].fontcolor(ColorList[k][0]));
        }
    }
 
    // Changes color of exits to white
    if (str.match(/obvious exit?.\:/g)) {
        var exits = gwc.gmcp.data.room.exits;
       
        exits.sort(function(a, b){
            return b.length - a.length;
        });
     
        exits.forEach(function(w) {
            str = replaceAll(str, w, w.fontcolor("white"));
        });
    }
   
    // Fixes a bug where words within <> arent shown in output.replace
    str = str.replace(/<(?!font|\/font)(.*?)>/g, "<" + "$1".fontcolor("white") + ">");
    // Sets the default color to green
    return str.fontcolor("green");
}
// Utilizes decode functions to remove "noise"
var new_arg = decode(args[1]);
gwc.output.replace(new_arg, colors(new_arg));


22 Feb 2018 06:52
Profile
Veteran

Joined: 24 Jan 2016 21:27
Posts: 223
I hope I'm not bombing the thread: Would it be possible to have packet repository where people can contribute their stuff now and then? Thinking something akin to linux repositories for alias/trigger packets.


22 Feb 2018 15:13
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software.