Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- startBalance = 0;
- currencyName = 0;
- zombieKillReward = 0;
- MegaZombieKillReward = 0;
- useUI = "False";
- zombieKillRewardMessage = "Message Not Set!";
- MegaZombieKillRewardMessage = "Message Not Set!";
- PlayerNotSpecified = "Message Not Set!";
- PlayerNotFound = "Message Not Found!";
- AmountUnspecified = "Message Not Found!";
- NotEnoughBalance = "Message Not Found!";
- IncomingPayment = "Message Not Found!";
- OutgoingPayment = "Message Not Found!";
- PlayerCheckBalance = "Message Not Found!";
- IncreasedPlayersBalance = "Message Not Found!";
- DecreasedPlayersBalance = "Message Not Found!";
- ResetPlayersBalance = "Message Not Found!";
- uAddUsage = "Message Not Found!";
- uAddSuccess = "Message Not Found!";
- uBuyUsage = "Message Not Found!";;
- uBuySuccess = "Message Not Found!";
- uBuyItemNotForSale = "Message Not Found!";
- uBuyNotEnoughFunds = "Message Not Found!";
- uSellUsage = "Message Not Found!";
- uSellItemNotSellable = "Message Not Found!";
- uSellNotHaveItem = "Message Not Found!";
- uSellSuccess = "Message Not Found!";
- event onLoad(){
- logger.log("uBalance Loaded!");
- file.write("../uBalance_configuration.txt","");
- if(file.read("../uBalance_configuration.txt") != ""){
- logger.log("uBalance Configuration Found!");
- }
- else{
- logger.log("uBalance Configuration Created!");
- file.writeAll("../uBalance_configuration.txt", "<startingBalance>0</startingBalance>\n<currencyName>Credits</currencyName>\n<zombieKillReward>15</zombieKillReward>\n<MegaZombieKillReward>50</MegaZombieKillReward>\n<useUI>False</useUI>");
- }
- file.write("../uBalance_translations.txt","");
- if(file.read("../uBalance_translations.txt") != ""){
- logger.log("uBalance Translations Found!");
- }
- else{
- logger.log("uBalance Translations Created!");
- file.writeAll("../uBalance_translations.txt", "<zombieKillRewardMessage>You earned {0} for killing a zombie!</zombieKillRewardMessage>\n<MegaZombieKillRewardMessage>You earned {0} for killing a mega zombie!</MegaZombieKillRewardMessage>\n<PlayerNotSpecified>You must specify a player!</PlayerNotSpecified>\n<PlayerNotFound>Target player could not be found</PlayerNotFound>\n<AmountUnspecified>You must specify an amount!</AmountUnspecified>\n<NotEnoughBalance>You do not have that amount</NotEnoughBalance>\n<IncomingPayment>{0} paid you {1} {2}</IncomingPayment>\n<OutgoingPayment>You paid {0} {1} {2}</OutgoingPayment>\n<PlayerCheckBalance>You have {0} {1}</PlayerCheckBalance>\n<IncreasedPlayersBalance>Increased {0}'s balance by {1}</IncreasedPlayersBalance>\n<DecreasedPlayersBalance>Decreased {0}'s balancy by {1}</DecreasedPlayersBalance>\n<ResetPlayersBalance>{0}'s Balance Has Been Reset!</ResetPlayersBalance>\n<uAddUsage>Correct Usage: /Add ItemID BuyPrice SellPrice</uAddUsage>\n<uAddSuccess>Set cost of {0} to {1} {3} and sell price to {2} {3}!</uAddSuccess>\n<uBuyUsage>Correct Usage: /Buy ItemID</uBuyUsage>\n<uBuySuccess>Purchased {0} for {1} {2}</uBuySuccess>\n<uBuyItemNotForSale>{0} is not for sale!</uBuyItemNotForSale>\n<uBuyNotEnoughFunds>You do not have enough {0} to purchase {1}</uBuyNotEnoughFunds>\n<uSellUsage>Correct Usage: /sell ItemID</uSellUsage>\n<uSellItemNotSellable>{0} cannot be sold!</uSellItemNotSellable>\n<uSellNotHaveItem>You do not have any {0} in your inventory!</uSellNotHaveItem>\n<uSellSuccess>You have sold {0} for {1} {2}!</uSellSuccess>");
- }
- // Translations
- translationFile = file.read("../uBalance_translations.txt").split("\n");
- zombieKillRewardMessage = translationFile[0].replace("<zombieKillRewardMessage>", "");
- zombieKillRewardMessage = zombieKillRewardMessage.replace("</zombieKillRewardMessage>", "");
- MegaZombieKillRewardMessage = translationFile[1].replace("<MegaZombieKillRewardMessage>", "");
- MegaZombieKillRewardMessage = MegaZombieKillRewardMessage.replace("</MegaZombieKillRewardMessage>", "");
- PlayerNotSpecified = translationFile[2].replace("<PlayerNotSpecified>", "");
- PlayerNotSpecified = PlayerNotSpecified.replace("</PlayerNotSpecified>", "");
- PlayerNotFound = translationFile[3].replace("<PlayerNotFound>", "");
- PlayerNotFound = PlayerNotFound.replace("</PlayerNotFound>", "");
- AmountUnspecified = translationFile[4].replace("<AmountUnspecified>", "");
- AmountUnspecified = AmountUnspecified.replace("</AmountUnspecified>", "");
- NotEnoughBalance = translationFile[5].replace("<NotEnoughBalance>", "");
- NotEnoughBalance = NotEnoughBalance.replace("</NotEnoughBalance>", "");
- IncomingPayment = translationFile[6].replace("<IncomingPayment>", "");
- IncomingPayment = IncomingPayment.replace("</IncomingPayment>", "");
- OutgoingPayment = translationFile[7].replace("<OutgoingPayment>", "");
- OutgoingPayment = OutgoingPayment.replace("</OutgoingPayment>", "");
- PlayerCheckBalance = translationFile[8].replace("<PlayerCheckBalance>", "");
- PlayerCheckBalance = PlayerCheckBalance.replace("</PlayerCheckBalance>", "");
- IncreasedPlayersBalance = translationFile[9].replace("<IncreasedPlayersBalance>", "");
- IncreasedPlayersBalance = IncreasedPlayersBalance.replace("</IncreasedPlayersBalance>", "");
- DecreasedPlayersBalance = translationFile[10].replace("<DecreasedPlayersBalance>", "");
- DecreasedPlayersBalance = DecreasedPlayersBalance.replace("</DecreasedPlayersBalance>", "");
- ResetPlayersBalance = translationFile[11].replace("<ResetPlayersBalance>", "");
- ResetPlayersBalance = ResetPlayersBalance.replace("</ResetPlayersBalance>", "");
- uAddUsage = translationFile[12].replace("<uAddUsage>", "");
- uAddUsage = uAddUsage.replace("</uAddUsage>", "");
- uAddSuccess = translationFile[13].replace("<uAddSuccess>", "");
- uAddSuccess = uAddSuccess.replace("</uAddSuccess>", "");
- uBuyUsage = translationFile[14].replace("<uBuyUsage>", "");
- uBuyUsage = uBuyUsage.replace("</uBuyUsage>", "");
- uBuySuccess = translationFile[15].replace("<uBuySuccess>", "");
- uBuySuccess = uBuySuccess.replace("</uBuySuccess>", "");
- uBuyItemNotForSale = translationFile[16].replace("<uBuyItemNotForSale>", "");
- uBuyItemNotForSale = uBuyItemNotForSale.replace("</uBuyItemNotForSale>", "");
- uBuyNotEnoughFunds = translationFile[17].replace("<uBuyNotEnoughFunds>", "");
- uBuyNotEnoughFunds = uBuyNotEnoughFunds.replace("</uBuyNotEnoughFunds>", "");
- uSellUsage = translationFile[18].replace("<uSellUsage>", "");
- uSellUsage = uSellUsage.replace("</uSellUsage>", "");
- uSellItemNotSellable = translationFile[19].replace("<uSellItemNotSellable>", "");
- uSellItemNotSellable = uSellItemNotSellable.replace("</uSellItemNotSellable>", "");
- uSellNotHaveItem = translationFile[20].replace("<uSellNotHaveItem>", "");
- uSellNotHaveItem = uSellNotHaveItem.replace("</uSellNotHaveItem>", "");
- uSellSuccess = translationFile[21].replace("<uSellSuccess>", "");
- uSellSuccess = uSellSuccess.replace("</uSellSuccess>", "");
- // Configuration
- configFile = file.read("../uBalance_configuration.txt").split("\n");
- startBalance = configFile[0].replace("<startingBalance>", "");
- startBalance = startBalance.replace("</startingBalance>", "");
- currencyName = configFile[1].replace("<currencyName>", "");
- currencyName = currencyName.replace("</currencyName>", "");
- zombieKillReward = configFile[2].replace("<zombieKillReward>", "");
- zombieKillReward = zombieKillReward.replace("</zombieKillReward>", "");
- MegaZombieKillReward = configFile[3].replace("<MegaZombieKillReward>", "");
- MegaZombieKillReward = MegaZombieKillReward.replace("</MegaZombieKillReward>", "");
- useUI = configFile[4].replace("<useUI>", "");
- useUI = useUI.replace("</useUI>", "");
- logger.log(currencyName);
- database.execute("CREATE TABLE IF NOT EXISTS uBalance(
- id VARCHAR(17) PRIMARY KEY,
- balance INT NOT NULL DEFAULT 0
- );");
- database.execute("CREATE TABLE IF NOT EXISTS uBalanceShop(
- itemid INT PRIMARY KEY,
- buyPrice INT NOT NULL DEFAULT 0,
- sellPrice INT NOT NULL DEFAULT 0
- );");
- foreach(player in server.players){
- player.setData("zombieCooldown", false);
- player.setData("MegazombieCooldown", false);
- player.setData("uBuyCooldown", false);
- player.setData("uSellCooldown", false);
- }
- }
- event onInterval(10){
- if(useUI == "True"){
- foreach(player in server.players){
- balance = balGet(player);
- effectManager.sendUI(24107, 24107, player.id, " $" + toString(balance));
- }
- }
- }
- function balui(player){
- if(useUI == "True"){
- balance = balGet(player);
- effectManager.sendUI(24107, 24107, player.id, " $" + toString(balance));
- }
- }
- command add(itemID, bPrice, sPrice){
- allowedCaller = "both";
- permission = "uBalance.add";
- execute(){
- if(isSet(itemID) and isSet(bPrice) and isSet(sPrice)){
- Result = database.execute("SELECT * FROM uBalanceShop WHERE itemid = '" + itemID + "';");
- foreach(listing in Result){
- database.execute("DELETE FROM uBalanceShop WHERE itemid = '" + itemID + "';");
- }
- database.execute("INSERT INTO uBalanceShop (itemid, buyPrice, sellPrice) VALUES ('" + itemID + "', '" + bPrice + "', '" + sPrice + "');");
- player.message(str.format(uAddSuccess, itemManager.getItemName(itemID), bPrice, sPrice, currencyName));
- }
- else{
- player.message(uAddUsage);
- }
- }
- }
- command Buy(itemID){
- permission = "uBalance.buy";
- execute(){
- if(isSet(itemID)){
- Result = array();
- if(player.getData("uBuyCooldown") == false){
- Result = database.execute("SELECT * FROM uBalanceShop WHERE itemid = '" + itemID + "';");
- }
- if(Result.count != 0){
- Item = Result[0];
- if(toNumber(balGet(player)) >= toNumber(Item[1])){
- balDecrease(player, Item[1]);
- player.give(Item[0], 1);
- player.message(str.format(uBuySuccess, itemManager.getItemName(itemID), Item[1], currencyName));
- }
- else{
- player.message(str.format(uBuyNotEnoughFunds, currencyName, itemManager.getItemName(itemID)));
- }
- }
- else{
- player.message(str.format(uBuyItemNotForSale, itemManager.getItemName(itemID)));
- }
- player.setData("uBuyCooldown", true);
- wait.seconds(1, player.setData("uBuyCooldown", false));
- }
- else{
- player.message(uBuyUsage);
- }
- }
- }
- command Sell(itemID){
- permission = "uBalance.sell";
- execute(){
- if(isSet(itemID)){
- Result = array();
- if(player.getData("uSellCooldown") == false){
- Result = database.execute("SELECT * FROM uBalanceShop WHERE itemid = '" + itemID + "';");
- }
- if(Result.count != 0){
- Item = Result[0];
- if(player.inventory.hasItem(itemID)){
- player.inventory.removeItem(itemID, 1);
- balIncrease(player, Item[2]);
- player.message(str.format(uSellSuccess, itemManager.getItemName(itemID), Item[2], currencyName));
- }
- else{
- player.message(str.format(uSellNotHaveItem, itemManager.getItemName(itemID)));
- }
- }
- else{
- player.message(str.format(uSellItemNotSellable, itemManager.getItemName(itemID)));
- }
- player.setData("uSellCooldown", true);
- wait.seconds(1, player.setData("uSellCooldown", false));
- }
- else{
- player.message(uSellUsage);
- }
- }
- }
- event onZombieKilled(player){
- if(player.getData("zombieCooldown") == false){
- player.message(str.format(zombieKillRewardMessage, zombieKillReward));
- balIncrease(player, zombieKillReward);
- player.setData("zombieCooldown", true);
- wait.seconds(1, player.setData("zombieCooldown", false));
- }
- }
- event onMegaZombieKilled(player){
- if(player.getData("MegazombieCooldown") == false){
- player.message(str.format(MegaZombieKillRewardMessage, MegaZombieKillReward));
- balIncrease(player, MegaZombieKillReward);
- player.setData("MegazombieCooldown", true);
- wait.seconds(1, player.setData("MegazombieCooldown", false));
- }
- }
- event onPlayerJoined(player){
- player.setData("zombieCooldown", false);
- Result = database.execute("SELECT * FROM uBalance WHERE id = '" + player.id + "';");
- if(Result.count == 0){
- database.execute("INSERT INTO uBalance (id, balance) VALUES ('" + player.id + "', '" + startBalance + "');");
- }
- balui(player);
- }
- function balDecrease(player, amount){
- database.execute(str.format("UPDATE uBalance SET balance = balance - '{0}' WHERE id = '{1}';", amount, player.id));
- }
- function balIncrease(player, amount){
- database.execute(str.format("UPDATE uBalance SET balance = balance + '{0}' WHERE id = '{1}';", amount, player.id));
- }
- function balGet(player){
- Result = database.execute(str.format("Select * FROM uBalance WHERE id = '{0}';", player.id));
- Player = Result[0];
- Balance = Player[1];
- Balance = toNumber(Balance);
- return Balance;
- }
- function balreset(player){
- database.execute(str.format("UPDATE uBalance SET balance = balance - balance WHERE id = '{0}';", player.id));
- }
- event onUnload(){
- logger.log("uBalance Unloaded!");
- }
- command pay(target, amount){
- permission = "uBalance.pay";
- execute(){
- if(isSet(target)){
- target = toPlayer(target);
- if(isSet(target)){
- if(isSet(amount)){
- if(amount <= balGet(player)){
- player.message(str.format(OutgoingPayment, player.name, amount, currencyName));
- target.message(str.format(IncomingPayment, player.name, amount, currencyName));
- balDecrease(player, amount);
- balIncrease(target, amount);
- }
- else{
- player.message(NotEnoughBalance);
- }
- }
- else{
- player.message(AmountUnspecified);
- }
- }
- else{
- player.message(PlayerNotFound);
- }
- }
- else{
- player.message(PlayerNotSpecified);
- }
- }
- }
- command balance(){
- permission = "uBalance.balance";
- execute(){
- playerBalance = balGet(player);
- player.message(str.format(PlayerCheckBalance, playerBalance, currencyName));
- }
- }
- command bal(){
- permission = "uBalance.balance";
- execute(){
- playerBalance = balGet(player);
- player.message(str.format(PlayerCheckBalance, playerBalance, currencyName));
- }
- }
- command addBal(target, amount){
- permission = "uBalance.addBal";
- execute(){
- if(isSet(target)){
- target = toPlayer(target);
- if(isSet(target)){
- if(isSet(amount)){
- balIncrease(target, amount);
- player.message(str.format(IncreasedPlayersBalance, target.name, amount));
- }
- else{
- player.message(AmountUnspecified);
- }
- }
- else{
- player.message(PlayerNotFound);
- }
- }
- else{
- player.message(PlayerNotSpecified);
- }
- }
- }
- command remBal(target, amount){
- permission = "uBalance.remBal";
- execute(){
- if(isSet(target)){
- target = toPlayer(target);
- if(isSet(target)){
- if(isSet(amount)){
- balDecrease(target, amount);
- player.message(str.format(DecreasedPlayersBalance, target.name, amount));
- }
- else{
- player.message(AmountUnspecified);
- }
- }
- else{
- player.message(PlayerNotFound);
- }
- }
- else{
- player.message(PlayerNotSpecified);
- }
- }
- }
- command resetBal(target){
- permission = "uBalance.resetBal";
- execute(){
- if(isSet(target)){
- target = toPlayer(target);
- if(isSet(target)){
- balreset(target);
- player.message(str.format(ResetPlayersBalance, target.name));
- }
- else{
- player.message(PlayerNotFound);
- }
- }
- else{
- player.message(PlayerNotSpecified);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement