-
Notifications
You must be signed in to change notification settings - Fork 26
/
@whobuy.c
111 lines (98 loc) · 3.38 KB
/
@whobuy.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//===== Hercules Plugin ======================================
//= @whobuy
//===== By: ==================================================
//= by Dastgir/Hercules
//===== Current Version: =====================================
//= 1.0
//===== Description: =========================================
//= Shows the player who is currently buying item(buyingstore)
//===== Changelog: ===========================================
//= v1.0 - Initial Release
//===== Additional Comments: =================================
//= @whobuy ItemName
//===== Repo Link: ===========================================
//= https://github.com/dastgir/HPM-Plugins
//============================================================
#include "common/hercules.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common/HPMi.h"
#include "map/atcommand.h"
#include "map/battle.h"
#include "map/clif.h"
#include "map/itemdb.h"
#include "map/map.h"
#include "map/pc.h"
#include "map/script.h"
#include "common/mapindex.h"
#include "common/nullpo.h"
#include "plugins/HPMHooking.h"
#include "common/HPMDataCheck.h"
HPExport struct hplugin_info pinfo = {
"@whobuy",
SERVER_TYPE_MAP,
"1.0",
HPM_VERSION,
};
ACMD(whobuy)
{
char item_name[100];
int item_id, j, count = 0, sat_num = 0;
bool flag = 0; // Show Location on minimap?
struct map_session_data* pl_sd;
struct s_mapiterator* iter;
unsigned int MinPrice = battle->bc->vending_max_value, MaxPrice = 0;
struct item_data *item_data;
char output[256];
memset(item_name, '\0', sizeof(item_name));
if (!*message || sscanf(message, "�[^\n]", item_name) < 1) {
clif->message(fd, "Input item name or ID (use: @whobuy <name or ID>).");
return false;
}
if ((item_data = itemdb->search_name(item_name)) == NULL &&
(item_data = itemdb->exists(atoi(item_name))) == NULL) {
clif->message(fd, msg_txt(19)); // Invalid item ID or name.
return false;
}
item_id = item_data->nameid;
iter = mapit_getallusers();
for (pl_sd = BL_UCAST(BL_PC, mapit->first(iter)); mapit->exists(iter); pl_sd = BL_UCAST(BL_PC, mapit->next(iter))) {
if (sd == pl_sd)
continue;
if (pl_sd->state.buyingstore) { // Check if player is autobuying
for (j = 0; j < pl_sd->buyingstore.slots; j ) {
if(pl_sd->buyingstore.items[j].nameid == item_id) {
snprintf(output, CHAT_SIZE_MAX, "Price %d | Amount %d | Buyer %s | Map %s[%d,%d]", pl_sd->buyingstore.items[j].price, pl_sd->buyingstore.items[j].amount, pl_sd->status.name, mapindex_id2name(pl_sd->mapindex), pl_sd->bl.x, pl_sd->bl.y);
if ((unsigned int)pl_sd->buyingstore.items[j].price < MinPrice)
MinPrice = pl_sd->buyingstore.items[j].price;
if ((unsigned int)pl_sd->buyingstore.items[j].price > MaxPrice)
MaxPrice = pl_sd->buyingstore.items[j].price;
clif->message(fd, output);
count ;
flag = 1;
}
}
if (flag && pl_sd->mapindex == sd->mapindex) {
clif->viewpoint(sd, 1, 1, pl_sd->bl.x, pl_sd->bl.y, sat_num, 0xFFFFFF);
flag = 0;
}
}
}
mapit->free(iter);
if (count > 0) {
snprintf(output, CHAT_SIZE_MAX, "Found %d ea. Prices from %udz to %udz", count, MinPrice, MaxPrice);
clif->message(fd, output);
} else
clif->message(fd, "Nobody buying it now.");
return true;
}
/* Server Startup */
HPExport void plugin_init(void)
{
addAtcommand("whobuy", whobuy);
}
HPExport void server_online(void)
{
ShowInfo("'%s' Plugin by Dastgir/Hercules. Version '%s'\n", pinfo.name, pinfo.version);
}