Hack Forums
[Java] Pokemon Attacker(uses PKMN references) and Urbandictionary Definer (uses chat ref) - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Java] Pokemon Attacker(uses PKMN references) and Urbandictionary Definer (uses chat ref) (/showthread.php?tid=4105155)



Pokemon Attacker(uses PKMN references) and Urbandictionary Definer (uses chat ref) - Utilisupport - Mar 9, 2014

Code
// VARIABLE
    // ******** ******** ********
    var vMessage = message;
    var vOtherDefine = true;
    var UNK = ""
    var vChannel = client.channelName(channel);
    var vMyName = client.ownName();
    var vUserSent = vMessage.substring(0, vMessage.indexOf(':'));
    var min = 1;
    var max = 2000;
    var dmg = Math.floor(Math.random() * (max - min + 1)) + min;
    var minZ = 1;
    var maxZ = 616;
    var dmgZ = Math.floor(Math.random() * (maxZ - minZ + 1)) + minZ;
    var vChannelPlayerID = client.channel(channel).players();
    var vChannelPlayerName = [];
    for (var x = 0; x < vChannelPlayerID.length; x++){
    vChannelPlayerName[x] = client.name(vChannelPlayerID[x]);
    }
    var vRndm = vChannelPlayerName[Math.floor((Math.random()*vChannelPlayerName.length)+0)];
    var vMoveName = [];
    var vMoveNameDone = false;
    for (x=0; vMoveNameDone == false; x++){
    vMoveName[x] = sys.move(x);
    if (vMoveName[x] == undefined){
    vMoveNameDone = true;
   // REMOVE (No Move)
   vMoveName.shift();
   // REMOVE LAST ENTRY undefined
   vMoveName.pop()
   vMove = vMoveName[dmgZ]
   }
   }


    // EXTRACT MESSAGE BY TAKING OUT THE NAME
    if (vMessage.indexOf(':') >= 0) {vMessage = vMessage.substr(vMessage.indexOf(':') + 2);}
    // SET THE MESSAGE MESSAGE TEXT TO LOWERCASE
    vMessage = vMessage.toLowerCase();


   //Pokemon Attack        
           if (["-move"].indexOf(vMessage) !== -1){
        if (dmg > 1500)        
        UNK = " Critical";
        else
        UNK = " Regular";
            var vName = "/me ±Ditto: ";
            var vMsg = [];
            vMsg[0] = vUserSent + " used " + vMove + ", it dealt " + dmg + UNK + " Damage to " + vRndm;
            vMsg[1] = vUserSent + " used " + vMove + ", it missed!... " + vRndm + " was unharmed!";
            var vRNG = Math.floor((Math.random()*vMsg.length)+0);
            if (vUserSent == vMyName) {vRndm = "their self!?!"}
            client.network().sendChanMessage(channel, vName + vMsg[vRNG]);
            }
          
// DEFINE
                    // ******** ******** ********
                    var vCommand = "-def";
                    if (((vCommand == vMessage.substring(0, vCommand.length)) && (vMyName == vUserSent)) || ((vCommand == vMessage.substring(0, vCommand.length)) && (vOtherDefine == true))) {
                        var vCommand = vMessage.substring(vCommand.length + 1).toUpperCase();
                        // WHO REQUESTED AND WHERE CHECK
                        if (vMyName == vUserSent){
                            print(vName + "Obtaining definition from Urban Dictionary…");
                            }
                        var vResponse = sys.synchronousWebCall("http://api.urbandictionary.com/v0/define?term=" + (encodeURIComponent(vCommand)));
                        var vDef = JSON.parse(vResponse);
                        if (vMyName == vUserSent){
                            print(vName + "Done.");
                            }
                        if (vDef.result_type != "exact") {
                            client.network().sendChanMessage(channel, vCommand + " is fake, gay and not defined!")
                            }
                        else {
                            // OBTAIN STRING TO ALLOW LENGTH CHECK
                            var vDefString = vDef.list[0].definition;
                            var vStringLimit = 300;
                            if (vDefString.length <= vStringLimit){
                                client.network().sendChanMessage(channel, vCommand + ": " + vDefString);
                                }
                            if (vDefString.length > vStringLimit){
                                client.network().sendChanMessage(channel, vCommand + ": " + vDefString.substring(0, vStringLimit) + " [String Limit of "+ vStringLimit + " Reached]");
                                }
                            }
                        }


These codes a for an auto response bot for a Netplay client. I programmed it my self, the first one "Pokemon attack" is just a 'randomized' auto response to Get a Random User From the Channel list and then "attack" them with a random "Move" (actual move references) and an randomized damage / critical.

As for the Urbandictionary reference im sure someone has made it before, but probably not the way I did it. Either way I just felt like posting this somewhere.


* - matt - Mar 9, 2014

This is Java Script not Java, please post this thread in the web development section.


* - Utilisupport - Mar 9, 2014

(Mar 9, 2014 12:15 PM)Midnight Blue™ Wrote:  This is Java Script not Java, please post this thread in the web development section.

Javascript is java? Sorry I learned javascript just to make this, but later got banned.


* - SIM-2015410 - Mar 9, 2014

(Mar 9, 2014 01:25 PM)Utilisupport Wrote:  Javascript is java? Sorry I learned javascript just to make this, but later got banned.

No javascript isnt java. the names are very misleading, there is actually no relation between java and javascript. here is an amusing description of javascript:

"1995 - Brendan Eich reads up on every mistake ever made in designing a programming language, invents a few more, and creates LiveScript. Later, in an effort to cash in on the popularity of Java the language is renamed JavaScript. Later still, in an effort to cash in on the popularity of skin diseases the language is renamed ECMAScrip."

Source, the best history of programming languages i have ever read: http://james-iry.blogspot.co.nz/2009/05/brief-incomplete-and-mostly-wrong.html