Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.46 KB | None | 0 0
  1. /*
  2. Andy, I've managed to script the single stocking part and a
  3. bunch more. Also, strings/variables do not save. I used
  4. DB_NewBiz to store information like items dropped on the
  5. NPC and if it's ready to be stocked or not. The NPC is a
  6. lot more complicated now, but the stocking NPC is 100%
  7. completed (with the exception that we don't know if a setshape
  8. increases the area you can drop in). Read what's in the
  9. NPCs in the test level to see how it works and what's been
  10. done more thoroughly.
  11.  
  12. Check the test business level. I added a script to add flowers
  13. to yourself each time you or I says "flowers." Don't be mad at
  14. me :[
  15.  
  16. -Hachi
  17. */
  18. /*function onPlayerEnters()
  19. {
  20. showtext(1, x+imgwidth(#f)/32, y, "Tahoma", "bc", "Disabled");
  21. changeimgzoom(1, 0.6);
  22. changeimgcolors(1, 0.9, 0.9, 0.9, 1);
  23. changeimgvis(1, 3);
  24. }*/
  25. function onCreated()
  26. {
  27. //join("newbiz-stocklimits");
  28. if (DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) == NULL)
  29. DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = this.itemsamount;
  30.  
  31. if (DB_NewBiz.(this.business @ "-" @ this.item) == NULL)
  32. DB_NewBiz.(this.business @ "-" @ this.item) = 0;
  33.  
  34. level.("stocker-" @ this.business @ "-" @ this.item) = level.name;
  35.  
  36. onTimeout();
  37. }
  38. function onActionDoubleMouse() player.addMessage("Item stocker for: " @ this.itemname @ ".");
  39. function onActionGrab()
  40. {
  41.  
  42. hideimg(2);
  43.  
  44. if (DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] > 0)
  45. {
  46. player.addMessage(DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0] SPC "still has"
  47. SPC DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] SPC "seconds to buy this item", "b", "");
  48.  
  49. return;
  50. }
  51.  
  52. //Let the owner be affected by the time
  53. // if (player.trial)
  54. // return;
  55.  
  56. //Now check if it's guild locked
  57. if (this.totalgrabs == NULL)
  58. {
  59. if (player.guild != this.guild && this.guild.length() > 1)
  60. {
  61. player.addMessage("You must be in '" @ this.guild @ "' to stock this item", "b", "");
  62. return;
  63. }
  64.  
  65. if (player.account != this.account && this.account.length() > 1)
  66. {
  67. player.addMessage("You must be '" @ this.account @ "' to stock this item", "b", "");
  68. return;
  69. }
  70. }
  71.  
  72. // First, let's check if you can actually build the item
  73. if (DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) == NULL)
  74. {
  75. createMessage(1);
  76. return;
  77. }
  78.  
  79. /* if (DB_NewBiz.(this.business @ "-" @ this.item) >= this.("limit"@this.item))
  80. {
  81. if(player.account in {"",""}){
  82. player.addMessage("This item is already fully stocked.", "b", "");
  83. return;
  84. }
  85. }*/
  86.  
  87. //Do a check to see if it can actually be grabbed
  88. if (this.timer != NULL) return;
  89.  
  90. //Find the item owner
  91. if (player.account != this.temp_lock && this.temp_lock != NULL && this.totalgrabs < 1) {
  92. player.addMessage(this.temp_lock SPC "is currently using this stocker.", "b", "");
  93. return;
  94. }
  95.  
  96. if (this.owner == NULL)
  97. this.owner = player.account;
  98.  
  99. //A gani check
  100. this.totalgrabs += this.grabs[0];
  101.  
  102. //Once the grabs are greater than the total grabs
  103. if (this.totalgrabs => this.grabs[1])
  104. {
  105.  
  106. showtext(1, x+imgwidth(#f)/32, y, "Tahoma", "bc", "Done");
  107. changeimgzoom(1, 0.5);
  108. changeimgcolors(1, 0.9, 0.9, 0.9, 1);
  109. changeimgvis(1, 3);
  110. if (this.stockingtype == "gangs")
  111. level.(this.owner @ "-" @ this.business @ "-" @ this.item) += 1;
  112. increaseGrabs();
  113. hideimg(3);
  114. showani(3, x, y, 2, "era_serverside_SFX", "shotgun_reload.wav");
  115.  
  116. //Add this to the database
  117. if (this.stockingtype != "gangs" && this.price > 0)
  118. {
  119. DB_NewBiz.(this.business @ "-" @ this.item) += 1;
  120. DB_NewBiz.(this.owner @ "-" @ this.item) += 1;
  121. }else {
  122.  
  123. //If the price is 0 or less, it goes straight to the player
  124. if (this.price > 0)
  125. {
  126. findplayer(this.owner).addMessage("Left click to buy the item. Right click to stock it. You have 60 seconds before it stocks automatically.", "b", "");
  127. DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = {this.owner, 60};
  128. DB_NewBiz.("disable-" @ this.business @ "-" @ this.item).add(this.owner);
  129. }
  130. else
  131. {
  132. with (findplayer(this.owner))
  133. {
  134. player.addItem(this.item, 1);
  135. player.addMessage("The item has been added to your inventory", "b", "");
  136. this.owner == NULL;
  137. }
  138. }
  139. }
  140.  
  141. //Reset the whole thing
  142. this.totalgrabs = NULL;
  143. DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = NULL;
  144. this.founditems = NULL;
  145. DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = this.itemsamount;
  146.  
  147. if (this.stockingtype != "gangs")
  148. this.owner = NULL;
  149.  
  150. hideImages();
  151. onTimeout();
  152. return;
  153. }
  154.  
  155. hideimg(3);
  156. showani(3, x, y, 2, "era_serverside_SFX", "shotgun_reload.wav");
  157. showtext(1, x+imgwidth(#f)/32, y, "Tahoma", "bc", this.totalgrabs @ "/" @ this.grabs[1] SPC "(" @ this.owner @ ")");
  158. changeimgzoom(1, 0.5);
  159. changeimgcolors(1, 0.9, 0.9, 0.9, 1);
  160. changeimgvis(1, 3);
  161.  
  162. increaseGrabs();
  163.  
  164. hideImages();
  165. }
  166. function hideImages()
  167. {
  168. sleep(0.1);
  169. hideimg(3);
  170. sleep(1.9);
  171. hideimg(1);
  172. }
  173. function increaseGrabs()
  174. {
  175. for (i=0;i<DB_NewBiz.("topstocking-" @ this.business).size();i++)
  176. {
  177. if (this.exist != 1)
  178. {
  179. if (DB_NewBiz.("topstocking-" @ this.business)[i][0] == player.account)
  180. {
  181. this.exist = 1;
  182. DB_NewBiz.("topstocking-" @ this.business)[i][1] ++;
  183. }
  184. }
  185. }
  186.  
  187. if (this.exist != 1)
  188. DB_NewBiz.("topstocking-" @ this.business).add({player.account, 1});
  189.  
  190. this.exist = NULL;
  191. }
  192. function onActionPlacedItem()
  193. {
  194. this.location = 0;
  195. this.giveback = 0;
  196. this.produceitem = "";
  197.  
  198. for (obj: findareanpcs(x,y,imgwidth(#f)/16,imgheight(#f)/16))
  199. {
  200. if (obj.isinclass("items") && obj.item in this.itemsrequired)
  201. {
  202. this.location = this.itemsrequired.index(obj.item);
  203.  
  204. //Check if someone's waiting to buy the item
  205. if (DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] > 0)
  206. {
  207. findplayer(obj.owner2).addItem(obj.item, obj.amount);
  208. findplayer(obj.owner2).addMessage(DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0] SPC "still has"
  209. SPC DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] SPC "seconds to buy this item", "b", "");
  210. obj.destroy();
  211. return;
  212. }
  213.  
  214. if (player.account != this.temp_lock && this.temp_lock != NULL) {
  215. findplayer(obj.owner2).addItem(obj.item, obj.amount);
  216. findplayer(obj.owner2).addMessage(this.temp_lock SPC "is currently using this stocker.", "b", "");
  217. obj.destroy();
  218. return;
  219. }
  220.  
  221. //Do a quick check to see if we can actually start production
  222. if (DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) == 1)
  223. {
  224. findplayer(obj.owner2).addItem(obj.item, obj.amount);
  225. obj.destroy();
  226. return;
  227. }
  228.  
  229. if (findplayer(obj.owner2).guild != this.guild && this.guild.length() > 1)
  230. {
  231. findplayer(obj.owner2).addItem(obj.item, obj.amount);
  232. findplayer(obj.owner2).addMessage("You must be in '" @ this.guild @ "' to stock this item", "b", "");
  233. obj.destroy();
  234. return;
  235. }
  236.  
  237. if (!(findplayer(obj.owner2).account in this.account) && this.account.length() > 1)
  238. {
  239. findplayer(obj.owner2).addItem(obj.item, obj.amount);
  240. findplayer(obj.owner2).addMessage("You must be '" @ this.account @ "' to stock this item", "b", "");
  241. obj.destroy();
  242. return;
  243. }
  244.  
  245. //Check if the item has already been accepted
  246. if (DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[this.itemsrequired.index(obj.item)] <= 0)
  247. {
  248. findplayer(obj.owner2).addItem(obj.item, obj.amount);
  249. findplayer(obj.owner2).addMessage("This item is already fully stocked", "b", "");
  250. obj.destroy();
  251. return;
  252. }
  253.  
  254. //A small check
  255. if (obj.amount > (this.itemsamount[this.location] + 10))
  256. {
  257. findplayer(obj.owner2).addItem(obj.item, obj.amount);
  258. findplayer(obj.owner2).addMessage("Cannot drop that much", "b", "");
  259. obj.destroy();
  260. return;
  261. }
  262.  
  263. if (this.stocking == 1)
  264. {
  265. findplayer(obj.owner2).addItem(obj.item, obj.amount);
  266. obj.destroy();
  267. return;
  268. }
  269.  
  270. this.stocking = 1;
  271.  
  272. //If it's greater, return the items lost
  273. if (obj.amount > DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[this.location])
  274. this.giveback = (obj.amount - DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[this.location]);
  275.  
  276. //Stores the item/Owner, for returning
  277. this.produceitem = {obj.owner2,obj.item};
  278.  
  279. //It'll add the item to the produce list
  280. //All items need to be in here for it to be produced (the item)
  281. this.temp_lock = obj.owner2;
  282. cancelEvents("UnsetTempOwner");
  283. scheduleEvent(5, "UnsetTempOwner");
  284. obj.destroy();
  285. }else{
  286. findplayer(obj.owner2).addItem(obj.item, obj.amount);
  287. findplayer(obj.owner2).addMessage("This is not a required item", "b", "");
  288. obj.destroy();
  289. return;
  290. }
  291. }
  292.  
  293. //A small check, to see if any 'hacking' is being made
  294. if (this.produceitem.size() > 2)
  295. return;
  296.  
  297. //Return the items if it's greater than 0
  298. if (this.giveback > 0)
  299. {
  300. with(findplayer(this.produceitem[0]))
  301. {
  302. player.addItem(this.produceitem[1], this.giveback);
  303. //player.chat = "Returned:" SPC this.giveback;
  304. }
  305. }
  306.  
  307. this.stocking = NULL;
  308.  
  309. //Now do a check to see if it can be added
  310. for (i = 0; i < this.itemsrequired.size(); i += 1)
  311. {
  312. if (this.produceitem[1] == this.itemsrequired[i][0])
  313. {
  314. DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[i] -= obj.amount;
  315. createMessage(0);
  316. }
  317. }
  318. }
  319.  
  320. function onUnsetTempOwner()
  321. this.temp_lock = NULL;
  322.  
  323. function listToString(list) {
  324. list = list.tokenize(",");
  325. if (list[list.size() - 1] == null) {
  326. list.delete(list.size() - 1);
  327. }
  328.  
  329. if (list.size() <= 0) {
  330. return "<none>";
  331. }
  332.  
  333. if (list.size() == 1) {
  334. return list[0];
  335. }
  336.  
  337. temp.string = list[0];
  338. list.delete(0);
  339.  
  340. for (temp.item : list) {
  341. string @= "," SPC item;
  342. }
  343.  
  344. return string;
  345. }
  346. function createMessage(messagemode)
  347. {
  348. if (DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) == NULL)
  349. {
  350. for (i = 0; i < this.itemsrequired.size(); i+= 1)
  351. {
  352. if (DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[i] > 0)
  353. {
  354. this.message1.add(DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[i] @ "x" SPC this.itemsdescript[i]);
  355. }
  356. }
  357. if (this.message1 != NULL)
  358. {
  359.  
  360. showtext(1, x+imgwidth(#f)/32, y, "Tahoma", "bc", "Items needed:" SPC listToString(this.message1));
  361.  
  362. changeimgzoom(1, 0.5);
  363. changeimgcolors(1, 0.9, 0.9, 0.9, 1);
  364. changeimgvis(1, 3);
  365.  
  366. if (messagemode == 1)
  367. {
  368. // if (this.message1.size() != 1)
  369. player.addMessage("The required items are not met (" @ listToString(this.message1) @ ")", "b", "");
  370. //else
  371. //player.addMessage("The required items are not met (" @ this.message1[0] @ ")", "b", "");
  372. }
  373.  
  374. }else{
  375. DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = 1;
  376. onTimeout();
  377. }
  378.  
  379. this.message1 = NULL;
  380. sleep(2);
  381. hideImages();
  382. }
  383. }
  384.  
  385. /*
  386. function listToString(list) {
  387. list = list.tokenize(",");
  388. if (list[list.size() - 1] == null) {
  389. list.delete(list.size() - 1);
  390. }
  391.  
  392. if (list.size() <= 0) {
  393. return "<none>";
  394. }
  395.  
  396. if (list.size() == 1) {
  397. return list[0];
  398. }
  399.  
  400. temp.string = list[0];
  401. list.delete(0);
  402.  
  403. for (temp.item : list) {
  404. string @= "," SPC item;
  405. }
  406.  
  407. return string;
  408. }
  409. */
  410. function onActionLeftMouse() {
  411. if (DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0] == player.account) {
  412. if (player.rupees >= this.price * level.(player.account @ "-" @ this.business @ "-" @ this.item)) {
  413. player.rupees -= this.price;
  414. player.addItem(this.item, level.(player.account @ "-" @ this.business @ "-" @ this.item));
  415. player.addMessage("Bought" SPC level.(player.account @ "-" @ this.business @ "-" @ this.item) SPC this.itemname SPC "for $" @ this.price, "b", "");
  416. this.owner = NULL;
  417. temp.thisaccount = DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0];
  418. DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = NULL;
  419. level.(player.account @ "-" @ this.business @ "-" @ this.item) = NULL;
  420. hideimg(1);
  421. sleep(0.3);
  422. DB_NewBiz.("disable-" @ this.business @ "-" @ this.item).remove(temp.thisaccount);
  423. //findplayer("Bl0nkt").chat = DB_NewBiz.("disable-" @ this.business @ "-" @ this.item);
  424. }else
  425. player.addMessage("You don't have enough money! The item costs $" @ this.price * level.(player.account @ "-" @ this.business @ "-" @ this.item) @ "!", "b", "");
  426. }
  427. }
  428.  
  429. function onActionRightMouse() {
  430. if (player.account == DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0]){
  431. if (this.stockingtype == "gangs") {
  432. DB_NewBiz.("disable-" @ this.business @ "-" @ this.item).remove(DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0]);
  433. DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = NULL;
  434. DB_NewBiz.(this.business @ "-" @ this.item) += level.(player.account @ "-" @ this.business @ "-" @ this.item);
  435. player.addMessage("Added" SPC level.(player.account @ "-" @ this.business @ "-" @ this.item) SPC this.itemname SPC "to the supply", "b", 0);
  436. level.(player.account @ "-" @ this.business @ "-" @ this.item) = NULL;
  437. this.owner = NULL;
  438. }
  439. }
  440. }
  441.  
  442. function onPlayerChats()
  443. {
  444. if (player.chat == "reset" SPC this.itemname)
  445. {
  446. if (clientr.staff >= 2)
  447. {
  448. DB_NewBiz.("itemsamount-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = this.itemsamount;
  449. DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = NULL;
  450. player.chat = "Reset required items of" SPC this.itemname;
  451. hideimg(1);
  452. hideimg(2);
  453. }
  454. }
  455. }
  456. function onTimeout()
  457. {
  458. if (DB_NewBiz.("canproduceitem-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) == 1 && this.totalgrabs == NULL)
  459. {
  460. hideimg(1);
  461. showtext(2, x+imgwidth(#f)/32, y, "Tahoma", "bc", "Ready to stock");
  462. changeimgzoom(2, 0.5);
  463. changeimgcolors(2, 0.9, 0.9, 0.9, 1);
  464. changeimgvis(2, 3);
  465. }
  466. if (this.stockingtype == "gangs")
  467. {
  468. if (DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] > 0)
  469. {
  470. DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[1] -= 1;
  471. //findplayer("Bl0nkt").chat = DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid);
  472. }else{
  473. if (DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) != NULL)
  474. {
  475. DB_NewBiz.(this.business @ "-" @ this.item) += 1;
  476. DB_NewBiz.("disable-" @ this.business @ "-" @ this.item).remove(DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid)[0]);
  477. DB_NewBiz.("waiting-" @ this.business @ "-" @ this.item @ "-" @ this.itemid) = NULL;
  478. level.(this.owner @ "-" @ this.business @ "-" @ this.item) -= 1;
  479. this.owner = NULL;
  480. }
  481. }
  482. }
  483.  
  484. setTimer(1);
  485. }
  486.  
  487. //#CLIENTSIDE
  488. function onCreated() {
  489. hideimg(3);
  490. onTimeout();
  491. }
  492.  
  493. function onActionGrab() {
  494. this.frozen = client.freeze = 0.05;
  495. }
  496.  
  497. function onTimeout() {
  498. if (this.frozen == 0.05) client.freeze = 0;
  499. if (this.frozen > 0) this.frozen-=0.05;
  500. setTimer(0.05);
  501. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement