summaryrefslogtreecommitdiff
path: root/npc
diff options
context:
space:
mode:
Diffstat (limited to 'npc')
-rw-r--r--npc/boss/_import.txt1
-rw-r--r--npc/boss/manamarket.txt107
-rw-r--r--npc/functions/input.txt39
3 files changed, 147 insertions, 0 deletions
diff --git a/npc/boss/_import.txt b/npc/boss/_import.txt
index c3051c8d7..60544f5ea 100644
--- a/npc/boss/_import.txt
+++ b/npc/boss/_import.txt
@@ -1,3 +1,4 @@
// Map boss: Boss Arena
// This file is generated automatically. All manually added changes will be removed when running the Converter.
+"npc/boss/manamarket.txt",
"npc/boss/throne.txt",
diff --git a/npc/boss/manamarket.txt b/npc/boss/manamarket.txt
new file mode 100644
index 000000000..6f9f3a940
--- /dev/null
+++ b/npc/boss/manamarket.txt
@@ -0,0 +1,107 @@
+// TMW2 Scripts.
+// Author:
+// Jesusalva
+// Description:
+// ManaMarket sketch
+
+boss,41,41,0 script ManaMarket NPC_TEDDYGIRL,{
+ function MMCooldown;
+ function MMBuy;
+ function MMBuyMenu;
+
+ if (!is_staff()) end;
+ mesn;
+ mesq l("Hello! How can I help you?");
+ if (MM_DELAY > gettimetick(2)) close;
+ next;
+ select
+ l("Buy"),
+ l("Sell"),
+ l("Nothing");
+ mes "";
+ if (@menu == 1)
+ MMBuy();
+ close;
+
+
+// Set the cooldown value to the same as interserver value
+function MMCooldown {
+ MM_DELAY=gettimetick(2)+300;
+ return;
+}
+
+// MMBuy(page=0)
+function MMBuy {
+ .@p=getarg(0,0);
+ .@v=MMBuyMenu(.@p);
+
+ // Special results
+ switch (.@v) {
+ case -1:
+ return;
+ case -2:
+ // FIXME
+ MMBuy(.@p+1);
+ break;
+ default:
+ break;
+ }
+
+ .@it=$@MM_nameid[.@v];
+ // Can't buy stuff you already have
+ if (countitem(.@it)) {
+ mesn;
+ mesq l("You already have this.");
+ return;
+ }
+
+
+ // Report
+ mesn;
+ mesq l("Purchase %02d %s for %d GP?",
+ $@MM_amount[.@v], getitemlink(.@it), $@MM_price[.@v]);
+ next;
+ if (askyesno() == ASK_YES) {
+ // TODO: Check if still in stock
+ mesn;
+ mesq l("Sorry. The arrays can't have zeros.");
+ // getitem2
+ }
+ return;
+}
+
+// MMBuyMenu ( page=0 )
+function MMBuyMenu {
+ deletearray @mm_menu$;
+ setarray @mm_menu$, l("Cancel"), -1;
+ .@pg=getarg(0, 0);
+ .@limit=min(getarraysize($@MM_id), (.@pg+1)*20);
+
+ // Prepare the information array
+ for (.@i=.@pg*20; .@i < .@limit; .@i++) {
+ //@mm_menu$+=getitemname($@MM_nameid[.@i])+":";
+ array_push(@mm_menu$, getitemname($@MM_nameid[.@i]));
+ array_push(@mm_menu$, str(.@i));
+ }
+
+ // Still more pages
+ if (.@limit < getarraysize($@MM_id)) {
+ array_push(@mm_menu$, "Next Page >>");
+ array_push(@mm_menu$, -2);
+ }
+
+ // Handle input
+ menuint2("@mm_menu$");
+ deletearray @mm_menu$;
+ return @menuret;
+}
+
+OnInit:
+ .distance=6;
+ .sex = G_FEMALE;
+
+ // Load ManaMarket (max 100 entries)
+ .@nb = query_sql("SELECT `id`, `account_id`, `price`, `expire_time`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `opt_idx0`, `opt_val0`, `opt_idx1`, `opt_val1`, `opt_idx2`, `opt_val2`, `opt_idx3`, `opt_val3`, `opt_idx4`, `opt_val4` FROM `manamarket` ORDER BY `id` DESC LIMIT 100", $@MM_id, $@MM_account_id, $@MM_price, $@MM_expire_time, $@MM_nameid, $@MM_amount, $@MM_equip, $@MM_identify, $@MM_refine, $@MM_attribute, $@MM_card0, $@MM_card1, $@MM_card2, $@MM_card3, $@MM_opt_idx0, $@MM_opt_val0, $@MM_opt_idx1, $@MM_opt_val1, $@MM_opt_idx2, $@MM_opt_val2, $@MM_opt_idx3, $@MM_opt_val3, $@MM_opt_idx4, $@MM_opt_val4);
+ end;
+}
+
diff --git a/npc/functions/input.txt b/npc/functions/input.txt
index cf0382d25..1ccfc0578 100644
--- a/npc/functions/input.txt
+++ b/npc/functions/input.txt
@@ -1,6 +1,7 @@
// Evol functions.
// Author:
// 4144
+// Jesusalva
// Description:
// Input utility functions
// Variables:
@@ -64,3 +65,41 @@ function script menustr {
@menuret$ = .@vals$[@menu];
return @menuret$;
}
+
+// menuint2(<array>)
+function script menuint2 {
+ .@ar$=getarg(0);
+ .@vals=0;
+ .@menustr$="";
+
+ if (getarraysize(.@ar$) % 2 != 0)
+ Exception("Invalid array size", RB_DEFAULT|RB_ISFATAL);
+
+ freeloop(true);
+ for (.@f=0; .@f < getarraysize(.@ar$); .@f++) {
+ // String vs Int
+ if (.@f % 2 == 0) {
+ .@menustr$+=getd(.@ar$+"["+.@f+"]")+":";
+ } else {
+ array_push(.@vals, getd(.@ar$+"["+.@f+"]"));
+ }
+ }
+ freeloop(false);
+
+ // Do the request
+ // We have: .@vals and .@menustr$
+ .@vals[.@cnt] = -1;
+ @menu = 255;
+ @menuret = -1;
+ select(.@menustr$);
+ if (@menu == 255)
+ return -1;
+
+ @menu --;
+ if (@menu < 0 || @menu >= getarraysize(.@vals) - 1)
+ return -1;
+
+ @menuret = .@vals[@menu];
+ return @menuret;
+}
+