Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- startBalance = 0;
- currencyName = 0;
- zombieKillReward = 0;
- MegaZombieKillReward = 0;
- 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!";
- 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>");
- }
- 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>");
- }
- // 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>", "");
- // 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>", "");
- database.execute("CREATE TABLE IF NOT EXISTS uBalance(
- id VARCHAR(17) PRIMARY KEY,
- balance INT NOT NULL DEFAULT 0
- );");
- }
- event onZombieKilled(player){
- player.message(str.format(zombieKillRewardMessage, zombieKillReward));
- balIncrease(player, zombieKillReward);
- }
- event onMegaZombieKilled(player){
- player.message(str.format(MegaZombieKillRewardMessage, MegaZombieKillReward));
- balIncrease(player, MegaZombieKillReward);
- }
- event onPlayerJoined(player){
- 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 + "');");
- }
- }
- 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