Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- translations = {
- "TARGET_NOT_FOUND": "Use this command whilst looking at a door/vehicle",
- "NOT_FOR_SALE": "This {0} is not for sale",
- "USELL_USAGE": "Correct Usage: /uSell <amount>",
- "THIS_COSTS": "This {0} costs: {1} experience.",
- "SET_PURCHASABLE": "{0} set to purchasable! Cost: {1}",
- "CANT_PURCHASE": "You don't have enough experience.",
- "DOOR_PURCHASED": "Door purchased: for {0} experience!\nSalvage and replace the door to let your group open it!",
- "VEHICLE_PURCHASED": "Vehicle purchased for {0} experience!\nLeave and rejoin the server to be able to enter the car!",
- "UI_PRICE": "Price: {0} Experience",
- "UI_TIP": "Use /uPurchase to purchase."
- };
- event onLoad(){
- database.nonQuery("CREATE TABLE IF NOT EXISTS uPurchase_Doors(
- id INT PRIMARY KEY,
- price INT NOT NULL DEFAULT 0
- );");
- database.nonQuery("CREATE TABLE IF NOT EXISTS uPurchase_Vehicles(
- id INT PRIMARY KEY,
- price INT NOT NULL DEFAULT 0
- );");
- }
- function isValidTarget(target){
- if(target == null or !["barricade","vehicle"].contains(target.type)) return false;
- if(target.type == "barricade" and target.door == null) return false;
- return true;
- }
- function translate(player, ID, params){
- if(params == null) params = [];
- while(params.count != 4) params.add("");
- player.message(translations[ID].format(params[0],params[1],params[2],params[3]));
- }
- command uPurchase(){
- permission = "upurchase";
- allowedCaller = "player";
- execute(){
- target = player.look.getBarricade() != null ? player.look.getBarricade() : player.look.getVehicle();
- if(!isValidTarget(target))
- return translate(player, "TARGET_NOT_FOUND");
- targetName = target.type == "vehicle" ? "Vehicle" : "Door";
- if(target.owner != null)
- return translate(player, "NOT_FOR_SALE", [targetName.toLower()]);
- DBcheck = database.firstRow("SELECT * FROM uPurchase_{0}s WHERE id = @p0;".format(targetName), target.instanceId);
- if(DBcheck.count == 0)
- return translate(player, "NOT_FOR_SALE", [targetName.toLower()]);
- if(player.experience < DBcheck[1].toNumber())
- return translate(player, "CANT_PURCHASE");
- player.experience-= DBcheck[1].toNumber();
- translate(player, targetName.toUpper() + "_PURCHASED", [DBcheck[1]]);
- database.nonQuery("DELETE FROM uPurchase_{0}s WHERE id = @p0;".format(targetName), target.instanceId);
- target.owner = player.id;
- target.group = player.steamGroup;
- }
- }
- command uPrice(){
- permission = "upurchase";
- allowedCaller = "player";
- execute(){
- target = player.look.getBarricade() != null ? player.look.getBarricade() : player.look.getVehicle();
- if(!isValidTarget(target))
- return translate(player, "TARGET_NOT_FOUND");
- targetName = target.type == "vehicle" ? "Vehicle" : "Door";
- if(target.owner != null)
- return translate(player, "NOT_FOR_SALE", [targetName.toLower()]);
- DBcheck = database.firstRow("SELECT * FROM uPurchase_{0}s WHERE id = @p0;".format(targetName), target.instanceId);
- if(DBcheck.count == 0)
- return translate(player, "NOT_FOR_SALE", [targetName.toLower()]);
- translate(player, "THIS_COSTS", [targetName.toLower(), DBcheck[1]]);
- }
- }
- command uSell(amount){
- permission = "upurchaseadmin";
- allowedCaller = "player";
- execute(){
- target = player.look.getBarricade() != null ? player.look.getBarricade() : player.look.getVehicle();
- if(!isValidTarget(target))
- return translate(player, "TARGET_NOT_FOUND");
- if(amount == null)
- return translate(player, "USELL_USAGE");
- targetName = target.type == "vehicle" ? "Vehicle" : "Door";
- database.nonQuery("DELETE FROM uPurchase_{0}s WHERE id = @p0;".format(targetName), target.instanceId);
- database.nonQuery("INSERT INTO uPurchase_{0}s (id, price) VALUES (@p0, @p1);".format(targetName), target.instanceId, amount);
- target.owner = "0";
- target.group = "0";
- if(target.type == "vehicle") target.isLocked = true;
- translate(player, "SET_PURCHASABLE", [targetName, amount]);
- }
- }
- event onPlayerGestured(player, gesture){
- if(!["PUNCH_LEFT","PUNCH_RIGHT"].contains(gesture)) return;
- target = player.look.getBarricade() != null ? player.look.getBarricade() : player.look.getVehicle();
- if(!isValidTarget(target) or target.owner != null)
- return effectManager.clearUIById(7802,player.id);
- targetName = target.type == "vehicle" ? "Vehicle" : "Door";
- DBcheck = database.firstRow("SELECT * FROM uPurchase_{0}s WHERE id = @p0;".format(targetName), target.instanceId);
- if(DBcheck.count == 0) return;
- name = targetName == "Door" ? targetName : target.name;
- effectManager.sendUI(7802, 7802, player.id, name, translations["UI_PRICE"].format(DBcheck[1]), translations["UI_TIP"]);
- }
Add Comment
Please, Sign In to add comment