summaryrefslogtreecommitdiff
path: root/src/plugins/sample.c
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2013-10-04 16:12:09 -0300
committershennetsind <ind@henn.et>2013-10-04 16:12:09 -0300
commita49787ff1589d86efa87263676761ddcbecd64ce (patch)
tree3f4c4f003f261d51995f0e3ff7092bbf82bbab68 /src/plugins/sample.c
parent2f2afbd3b63a75695f8f96e3bcb4db9fff5a7dc6 (diff)
downloadhercules-a49787ff1589d86efa87263676761ddcbecd64ce.tar.gz
hercules-a49787ff1589d86efa87263676761ddcbecd64ce.tar.bz2
hercules-a49787ff1589d86efa87263676761ddcbecd64ce.tar.xz
hercules-a49787ff1589d86efa87263676761ddcbecd64ce.zip
HPM: Hooking!
http://hercules.ws/board/topic/2399-hpm-hooking-now-available/ Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/plugins/sample.c')
-rw-r--r--src/plugins/sample.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/src/plugins/sample.c b/src/plugins/sample.c
index 4f9e34f74..d1a95c71d 100644
--- a/src/plugins/sample.c
+++ b/src/plugins/sample.c
@@ -88,6 +88,26 @@ void sample_packet0f3(int fd) {
clif->pGlobalMessage(fd,sd);
}
+int my_pc_dropitem_storage;/* storage var */
+/* my custom prehook for pc_dropitem, checks if amount of item being dropped is higher than 1 and if so cap it to 1 and store the value of how much it was */
+int my_pc_dropitem_pre(struct map_session_data *sd,int *n,int *amount) {
+ my_pc_dropitem_storage = 0;
+ if( *amount > 1 ) {
+ my_pc_dropitem_storage = *amount;
+ *amount = 1;
+ }
+ return 0;
+}
+/* postHook receive retVal as the first param, allows posthook to act accordingly to whatever the original was going to return */
+int my_pc_dropitem_post(int retVal, struct map_session_data *sd,int *n,int *amount) {
+ if( retVal != 1 ) return retVal;/* we don't do anything if pc_dropitem didn't return 1 (success) */
+ if( my_pc_dropitem_storage ) {/* signs whether pre-hook did this */
+ char output[99];
+ snprintf(output,99,"[ Warning ] you can only drop 1 item at a time, capped from %d to 1",my_pc_dropitem_storage);
+ clif->colormes(sd->fd,COLOR_RED,output);
+ }
+ return 1;
+}
/* run when server starts */
HPExport void plugin_init (void) {
char *server_type;
@@ -103,6 +123,7 @@ HPExport void plugin_init (void) {
/* map-server interfaces */
script = GET_SYMBOL("script");
clif = GET_SYMBOL("clif");
+ pc = GET_SYMBOL("pc");
/* session[] */
session = GET_SYMBOL("session");
@@ -132,7 +153,16 @@ HPExport void plugin_init (void) {
if( HPMi->addPacket != NULL ) {//link our 'sample' packet to map-server
HPMi->addPacket(0xf3,-1,sample_packet0f3,hpClif_Parse,HPMi->pid);
}
-
+
+ /* in this sample we add a PreHook to pc->dropitem */
+ /* to identify whether the item being dropped is on amount higher than 1 */
+ /* if so, it stores the amount on a variable (my_pc_dropitem_storage) and changes the amount to 1 */
+ addHookPre("pc->dropitem",my_pc_dropitem_pre);
+ /* in this sample we add a PostHook to pc->dropitem */
+ /* if the original pc->dropitem was successful and the amount stored on my_pc_dropitem_storage is higher than 1, */
+ /* our posthook will display a message to the user about the cap */
+ /* - by checking whether it was successful (retVal value) it allows for the originals conditions to take place */
+ addHookPost("pc->dropitem",my_pc_dropitem_post);
}
/* run when server is ready (online) */
HPExport void server_online (void) {