Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Correct
- var Shopcolor = "250,250,47"; //A color, which will be used by the whole command
- var enabled = true; // Whether shop is currently enabled or not
- var plr; //Making the player global, so I don't have to pass it to every function that needs it
- //This is what creates the command. Sets plr to reference player who executed the command, calls shopSwitch and onCommandExecuted if it's defined
- var shopCommand = acmd_alias_create("shop", 0, 0, "shop", function (player, args) {
- plr = player;
- if (args !== undefined) {
- shopSwitch(player, args);
- try {
- onCommandExecuted();
- } catch (e) {}
- }
- });
- //Correct
- function trace(msg) {
- tshock_msg_colour(Shopcolor, plr, String(msg));
- }
- //Correct
- function findItemByName(test, callback) {
- if (test.length < 3) {
- return false;
- }
- for (var prop in itemDataQWERTY) {
- if(test.substring(0, 3) == prop.substring(0,3)) {
- callback(prop);
- return true;
- }
- }
- }
- function fail() {
- trace("Failed to execute desired statement. Try again and make sure you didn't mispell any parameter.");
- if(typeof onFailed == "function") {
- onFailed();
- }
- }
- function procceedToBuy(block, name) {
- for (var prop in block) {
- if (block.hasOwnProperty(prop)) {
- if (block[prop].Xcmd == name) {
- buy(block[prop]);
- return;
- }
- }
- }
- fail();
- }
- function buy(item) {
- if (plr.InventorySlotAvailable) {
- var secAcc = seconomy_get_account(plr);
- var cost = seconomy_parse_money(item.XitemPrice);
- seconomy_pay_async(secAcc, seconomy_get_account(tshock_get_player("Nalah")) ? tshock_get_player("Nalah") : seconomy_world_account(), cost, item.Xcmd, function (payResult) {
- if (payResult.TransferSucceeded === true) {
- for (i = 0; i < item.Xitems.length; i++) {
- tshock_exec(tshock_server(), '/give \"' + item.Xitems[i] + '\" \"' + plr.Name + '\"');
- }
- if(typeof item.XonBought == "function") {
- item.XonBought();
- }
- }
- else {
- try {
- onPaymentFailed();
- }
- catch (e) {
- trace("Sorry, you are too broke, you need " + item.XitemPrice + " Cookies/Cuboids to buy this. Do /bank bal to see how much do you currently have.");
- }
- }
- });
- }
- else {
- trace("Your inventory is full! Make sure you have enough free space");
- }
- }
- function seeInfo(block, cmd) {
- for (var prop in block) {
- if (block[prop].Xcmd == cmd) {
- var subblock = block[prop];
- var i = 0;
- for (var subprop in subblock) {
- switch (i) {
- case 0:
- trace(" price : " + String(subblock[subprop]));
- break;
- case 1:
- trace(" name : " + String(subblock[subprop]));
- break;
- case 2:
- trace(" items : " + String(subblock[subprop]));
- break;
- }
- i++;
- }
- }
- }
- }
- function alertAll() {
- if(tshock_has_permission(plr, "youshouldnthavethis")) {
- //Things like vanity, armor, etc...
- for (var prop in itemDataQWERTY) {
- trace(prop + " :");
- var Property = itemDataQWERTY[prop];
- //Things like item, anotheritem, etc...
- for (var subprop in Property) {
- trace(" " + subprop + " : ");
- var subProperty = Property[subprop];
- //Xcmd, Xprice, etc...
- for (var subsubprop in subProperty) {
- trace(" " + subsubprop + " : " + String(subProperty[subsubprop]));
- }
- break;
- }
- }
- }
- else {
- fail();
- }
- }
- function traceHelp() {
- trace("Welcome to /shop help! Behold:");
- trace("/shop help - print this help");
- trace("/shop (type) (name) - purchase an item/package from the shop");
- trace("/shop see (type) (name) - view information about the package/item");
- if(tshock_has_permission(plr, "youshouldnthavethis")) {
- trace("/shop ON/OFF - enable/disable the shop");
- trace("/shop test - test");
- }
- }
- function shopSwitch(player, args) {
- if (args.Count > 0) {
- if (String(args[0]) == "ON" && enabled === false && tshock_has_permission(player, "youshouldnthavethis")) {
- enabled = true;
- trace("Shop enabled.");
- } else if (enabled === false) {
- trace("Sorry! The shop is currently disabled! Come back next time");
- return;
- } else if (!tshock_has_permission(player, "youshouldnthavethis") && args[0] == "ON") {
- trace("You are not allowed to do that.");
- }
- switch (args[0]) {
- case "OFF":
- enabled = false;
- trace("Shop disabled.");
- break;
- case "ON":
- trace("Shop is already enabled");
- break;
- case "test":
- alertAll();
- break;
- case "see":
- if (findItemByName(args[1], function(prop) {seeInfo(itemDataQWERTY[prop], args[2]); }) !== true) {
- fail();
- }
- break;
- case "help":
- traceHelp();
- break;
- default:
- if (findItemByName(args[0], function(prop) {procceedToBuy(itemDataQWERTY[prop], args[1]); }) !== true) {
- trace("Thingy not found! Try /shop help or check the spreadsheet!");
- }
- break;
- }
- }
- else {
- trace("Shop is currently enabled.");
- trace("Welcome to the shop, use /shop help to see what you can do");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement