Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Andy, I've managed to script the single stocking part and a
- bunch more. Also, strings/variables do not save. I used
- DB_NewBiz to store information like items dropped on the
- NPC and if it's ready to be stocked or not. The NPC is a
- lot more complicated now, but the stocking NPC is 100%
- completed (with the exception that we don't know if a setshape
- increases the area you can drop in). Read what's in the
- NPCs in the test level to see how it works and what's been
- done more thoroughly.
- Check the test business level. I added a script to add flowers
- to yourself each time you or I says "flowers." Don't be mad at
- me :[
- -Hachi
- */
- /*function onPlayerEnters()
- {
- showtext(1, x+imgwidth(#f)/32, y, "Tahoma", "bc", "Disabled");
- changeimgzoom(1, 0.6);
- changeimgcolors(1, 0.9, 0.9, 0.9, 1);
- changeimgvis(1, 3);
- }*/
- function onCreated()
- {
- //join("newbiz-stocklimits");
- if (DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) == NULL)
- DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = this.itemsamount;
- if (DB_NewBiz.(this.business @ "-" @ this.item) == NULL)
- DB_NewBiz.(this.business @ "-" @ this.item) = 0;
- level.("stocker-" @ this.business @ "-" @ this.item) = level.name;
- onTimeout();
- }
- function onActionDoubleMouse() player.addMessage("Item stocker for: " @ this.itemname @ ".");
- function onActionGrab()
- {
- hideimg(2);
- if (DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] > 0)
- {
- player.addMessage(DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0] SPC "still has"
- SPC DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] SPC "seconds to buy this item", "b", "");
- return;
- }
- //Let the owner be affected by the time
- // if (player.trial)
- // return;
- //Now check if it's guild locked
- if (this.totalgrabs == NULL)
- {
- if (player.guild != this.guild && this.guild.length() > 1)
- {
- player.addMessage("You must be in '" @ this.guild @ "' to stock this item", "b", "");
- return;
- }
- if (player.account != this.account && this.account.length() > 1)
- {
- player.addMessage("You must be '" @ this.account @ "' to stock this item", "b", "");
- return;
- }
- }
- // First, let's check if you can actually build the item
- if (DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) == NULL)
- {
- createMessage(1);
- return;
- }
- /* if (DB_NewBiz.(this.business @ "-" @ this.item) >= this.("limit"@this.item))
- {
- if(player.account in {"",""}){
- player.addMessage("This item is already fully stocked.", "b", "");
- return;
- }
- }*/
- //Do a check to see if it can actually be grabbed
- if (this.timer != NULL) return;
- //Find the item owner
- if (player.account != this.temp_lock && this.temp_lock != NULL && this.totalgrabs < 1) {
- player.addMessage(this.temp_lock SPC "is currently using this stocker.", "b", "");
- return;
- }
- if (this.owner == NULL)
- this.owner = player.account;
- //A gani check
- this.totalgrabs += this.grabs[0];
- //Once the grabs are greater than the total grabs
- if (this.totalgrabs => this.grabs[1])
- {
- showtext(1, x+imgwidth(#f)/32, y, "Tahoma", "bc", "Done");
- changeimgzoom(1, 0.5);
- changeimgcolors(1, 0.9, 0.9, 0.9, 1);
- changeimgvis(1, 3);
- if (this.stockingtype == "gangs")
- level.(this.owner @ "-" @ this.business @ "-" @ this.item) += 1;
- increaseGrabs();
- hideimg(3);
- showani(3, x, y, 2, "era_serverside_SFX", "shotgun_reload.wav");
- //Add this to the database
- if (this.stockingtype != "gangs" && this.price > 0)
- {
- DB_NewBiz.(this.business @ "-" @ this.item) += 1;
- DB_NewBiz.(this.owner @ "-" @ this.item) += 1;
- }else {
- //If the price is 0 or less, it goes straight to the player
- if (this.price > 0)
- {
- findplayer(this.owner).addMessage("Left click to buy the item. Right click to stock it. You have 60 seconds before it stocks automatically.", "b", "");
- DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = {this.owner, 60};
- DB_NewBiz.("disable-" @ this.business @ "-" @ this.item).add(this.owner);
- }
- else
- {
- with (findplayer(this.owner))
- {
- player.addItem(this.item, 1);
- player.addMessage("The item has been added to your inventory", "b", "");
- this.owner == NULL;
- }
- }
- }
- //Reset the whole thing
- this.totalgrabs = NULL;
- DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = NULL;
- this.founditems = NULL;
- DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = this.itemsamount;
- if (this.stockingtype != "gangs")
- this.owner = NULL;
- hideImages();
- onTimeout();
- return;
- }
- hideimg(3);
- showani(3, x, y, 2, "era_serverside_SFX", "shotgun_reload.wav");
- showtext(1, x+imgwidth(#f)/32, y, "Tahoma", "bc", this.totalgrabs @ "/" @ this.grabs[1] SPC "(" @ this.owner @ ")");
- changeimgzoom(1, 0.5);
- changeimgcolors(1, 0.9, 0.9, 0.9, 1);
- changeimgvis(1, 3);
- increaseGrabs();
- hideImages();
- }
- function hideImages()
- {
- sleep(0.1);
- hideimg(3);
- sleep(1.9);
- hideimg(1);
- }
- function increaseGrabs()
- {
- for (i=0;i<DB_NewBiz.("topstocking-" @ this.business).size();i++)
- {
- if (this.exist != 1)
- {
- if (DB_NewBiz.("topstocking-" @ this.business)[i][0] == player.account)
- {
- this.exist = 1;
- DB_NewBiz.("topstocking-" @ this.business)[i][1] ++;
- }
- }
- }
- if (this.exist != 1)
- DB_NewBiz.("topstocking-" @ this.business).add({player.account, 1});
- this.exist = NULL;
- }
- function onActionPlacedItem()
- {
- this.location = 0;
- this.giveback = 0;
- this.produceitem = "";
- for (obj: findareanpcs(x,y,imgwidth(#f)/16,imgheight(#f)/16))
- {
- if (obj.isinclass("items") && obj.item in this.itemsrequired)
- {
- this.location = this.itemsrequired.index(obj.item);
- //Check if someone's waiting to buy the item
- if (DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] > 0)
- {
- findplayer(obj.owner2).addItem(obj.item, obj.amount);
- findplayer(obj.owner2).addMessage(DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0] SPC "still has"
- SPC DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] SPC "seconds to buy this item", "b", "");
- obj.destroy();
- return;
- }
- if (player.account != this.temp_lock && this.temp_lock != NULL) {
- findplayer(obj.owner2).addItem(obj.item, obj.amount);
- findplayer(obj.owner2).addMessage(this.temp_lock SPC "is currently using this stocker.", "b", "");
- obj.destroy();
- return;
- }
- //Do a quick check to see if we can actually start production
- if (DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) == 1)
- {
- findplayer(obj.owner2).addItem(obj.item, obj.amount);
- obj.destroy();
- return;
- }
- if (findplayer(obj.owner2).guild != this.guild && this.guild.length() > 1)
- {
- findplayer(obj.owner2).addItem(obj.item, obj.amount);
- findplayer(obj.owner2).addMessage("You must be in '" @ this.guild @ "' to stock this item", "b", "");
- obj.destroy();
- return;
- }
- if (!(findplayer(obj.owner2).account in this.account) && this.account.length() > 1)
- {
- findplayer(obj.owner2).addItem(obj.item, obj.amount);
- findplayer(obj.owner2).addMessage("You must be '" @ this.account @ "' to stock this item", "b", "");
- obj.destroy();
- return;
- }
- //Check if the item has already been accepted
- if (DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[this.itemsrequired.index(obj.item)] <= 0)
- {
- findplayer(obj.owner2).addItem(obj.item, obj.amount);
- findplayer(obj.owner2).addMessage("This item is already fully stocked", "b", "");
- obj.destroy();
- return;
- }
- //A small check
- if (obj.amount > (this.itemsamount[this.location] + 10))
- {
- findplayer(obj.owner2).addItem(obj.item, obj.amount);
- findplayer(obj.owner2).addMessage("Cannot drop that much", "b", "");
- obj.destroy();
- return;
- }
- if (this.stocking == 1)
- {
- findplayer(obj.owner2).addItem(obj.item, obj.amount);
- obj.destroy();
- return;
- }
- this.stocking = 1;
- //If it's greater, return the items lost
- if (obj.amount > DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[this.location])
- this.giveback = (obj.amount - DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[this.location]);
- //Stores the item/Owner, for returning
- this.produceitem = {obj.owner2,obj.item};
- //It'll add the item to the produce list
- //All items need to be in here for it to be produced (the item)
- this.temp_lock = obj.owner2;
- cancelEvents("UnsetTempOwner");
- scheduleEvent(5, "UnsetTempOwner");
- obj.destroy();
- }else{
- findplayer(obj.owner2).addItem(obj.item, obj.amount);
- findplayer(obj.owner2).addMessage("This is not a required item", "b", "");
- obj.destroy();
- return;
- }
- }
- //A small check, to see if any 'hacking' is being made
- if (this.produceitem.size() > 2)
- return;
- //Return the items if it's greater than 0
- if (this.giveback > 0)
- {
- with(findplayer(this.produceitem[0]))
- {
- player.addItem(this.produceitem[1], this.giveback);
- //player.chat = "Returned:" SPC this.giveback;
- }
- }
- this.stocking = NULL;
- //Now do a check to see if it can be added
- for (i = 0; i < this.itemsrequired.size(); i += 1)
- {
- if (this.produceitem[1] == this.itemsrequired[i][0])
- {
- DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[i] -= obj.amount;
- createMessage(0);
- }
- }
- }
- function onUnsetTempOwner()
- this.temp_lock = NULL;
- function listToString(list) {
- list = list.tokenize(",");
- if (list[list.size() - 1] == null) {
- list.delete(list.size() - 1);
- }
- if (list.size() <= 0) {
- return "<none>";
- }
- if (list.size() == 1) {
- return list[0];
- }
- temp.string = list[0];
- list.delete(0);
- for (temp.item : list) {
- string @= "," SPC item;
- }
- return string;
- }
- function createMessage(messagemode)
- {
- if (DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) == NULL)
- {
- for (i = 0; i < this.itemsrequired.size(); i+= 1)
- {
- if (DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[i] > 0)
- {
- this.message1.add(DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[i] @ "x" SPC this.itemsdescript[i]);
- }
- }
- if (this.message1 != NULL)
- {
- showtext(1, x+imgwidth(#f)/32, y, "Tahoma", "bc", "Items needed:" SPC listToString(this.message1));
- changeimgzoom(1, 0.5);
- changeimgcolors(1, 0.9, 0.9, 0.9, 1);
- changeimgvis(1, 3);
- if (messagemode == 1)
- {
- // if (this.message1.size() != 1)
- player.addMessage("The required items are not met (" @ listToString(this.message1) @ ")", "b", "");
- //else
- //player.addMessage("The required items are not met (" @ this.message1[0] @ ")", "b", "");
- }
- }else{
- DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = 1;
- onTimeout();
- }
- this.message1 = NULL;
- sleep(2);
- hideImages();
- }
- }
- /*
- function listToString(list) {
- list = list.tokenize(",");
- if (list[list.size() - 1] == null) {
- list.delete(list.size() - 1);
- }
- if (list.size() <= 0) {
- return "<none>";
- }
- if (list.size() == 1) {
- return list[0];
- }
- temp.string = list[0];
- list.delete(0);
- for (temp.item : list) {
- string @= "," SPC item;
- }
- return string;
- }
- */
- function onActionLeftMouse() {
- if (DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0] == player.account) {
- if (player.rupees >= this.price * level.(player.account @ "-" @ this.business @ "-" @ this.item)) {
- player.rupees -= this.price;
- player.addItem(this.item, level.(player.account @ "-" @ this.business @ "-" @ this.item));
- player.addMessage("Bought" SPC level.(player.account @ "-" @ this.business @ "-" @ this.item) SPC this.itemname SPC "for $" @ this.price, "b", "");
- this.owner = NULL;
- temp.thisaccount = DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0];
- DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = NULL;
- level.(player.account @ "-" @ this.business @ "-" @ this.item) = NULL;
- hideimg(1);
- sleep(0.3);
- DB_NewBiz.("disable-" @ this.business @ "-" @ this.item).remove(temp.thisaccount);
- //findplayer("Bl0nkt").chat = DB_NewBiz.("disable-" @ this.business @ "-" @ this.item);
- }else
- player.addMessage("You don't have enough money! The item costs $" @ this.price * level.(player.account @ "-" @ this.business @ "-" @ this.item) @ "!", "b", "");
- }
- }
- function onActionRightMouse() {
- if (player.account == DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0]){
- if (this.stockingtype == "gangs") {
- DB_NewBiz.("disable-" @ this.business @ "-" @ this.item).remove(DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0]);
- DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = NULL;
- DB_NewBiz.(this.business @ "-" @ this.item) += level.(player.account @ "-" @ this.business @ "-" @ this.item);
- player.addMessage("Added" SPC level.(player.account @ "-" @ this.business @ "-" @ this.item) SPC this.itemname SPC "to the supply", "b", 0);
- level.(player.account @ "-" @ this.business @ "-" @ this.item) = NULL;
- this.owner = NULL;
- }
- }
- }
- function onPlayerChats()
- {
- if (player.chat == "reset" SPC this.itemname)
- {
- if (clientr.staff >= 2)
- {
- DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = this.itemsamount;
- DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = NULL;
- player.chat = "Reset required items of" SPC this.itemname;
- hideimg(1);
- hideimg(2);
- }
- }
- }
- function onTimeout()
- {
- if (DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) == 1 && this.totalgrabs == NULL)
- {
- hideimg(1);
- showtext(2, x+imgwidth(#f)/32, y, "Tahoma", "bc", "Ready to stock");
- changeimgzoom(2, 0.5);
- changeimgcolors(2, 0.9, 0.9, 0.9, 1);
- changeimgvis(2, 3);
- }
- if (this.stockingtype == "gangs")
- {
- if (DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] > 0)
- {
- DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] -= 1;
- //findplayer("Bl0nkt").chat = DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid);
- }else{
- if (DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) != NULL)
- {
- DB_NewBiz.(this.business @ "-" @ this.item) += 1;
- DB_NewBiz.("disable-" @ this.business @ "-" @ this.item).remove(DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0]);
- DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = NULL;
- level.(this.owner @ "-" @ this.business @ "-" @ this.item) -= 1;
- this.owner = NULL;
- }
- }
- }
- setTimer(1);
- }
- //#CLIENTSIDE
- function onCreated() {
- hideimg(3);
- onTimeout();
- }
- function onActionGrab() {
- this.frozen = client.freeze = 0.05;
- }
- function onTimeout() {
- if (this.frozen == 0.05) client.freeze = 0;
- if (this.frozen > 0) this.frozen-=0.05;
- setTimer(0.05);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement