/** * This file is part of Hercules. * http://herc.ws - http://github.com/HerculesWS/Hercules * * Copyright (C) 2013-2015 Hercules Dev Team * * Hercules is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /// Sample Hercules Plugin #include "common/hercules.h" /* Should always be the first Hercules file included! (if you don't make it first, you won't be able to use interfaces) */ #include "common/mmo.h" #include "common/db.h" #include "common/utils.h" #include "common/timer.h" #include "common/nullpo.h" #include "map/channel.h" #include "map/irc-bot.h" #include "map/pc.h" #include "map/itemdb.h" #include "map/clif.h" #include "map/script.h" #include "map/status.h" #include "plugins/HPMHooking.h" #include "common/HPMDataCheck.h" /* should always be the last Hercules file included! (if you don't make it last, it'll intentionally break compile time) */ #include #include #include HPExport struct hplugin_info pinfo = { "Channel Paid Messages", // Plugin name SERVER_TYPE_MAP,// Which server types this plugin works with? "0.1", // Plugin version HPM_VERSION, // HPM Version (don't change, macro is automatically updated) }; enum { CF_NONE = 0, CF_ZENY = 1, CF_ITEM = 2 }; /** * Sends a message to a channel. * * @param chan The destination channel. * @param sd The source character. * @param msg The message to send. * * If no source character is specified, it'll send an anonymous message. */ void channel_send_fee (struct channel_data *chan, struct map_session_data *sd, const char *msg) { char message[150]; int i, zeny = 0; struct item it; int fee = CF_NONE; int idx; char alert[150]; it.nameid = 0; it.amount = 0; nullpo_retv(chan); nullpo_retv(msg); // FIXME: make a better way to add fee on channels (directly on channels.conf) const struct { char name[HCS_NAME_LENGTH]; int zeny; int nameid; int amount; } channels_fee[] = { // -- Add channels with fee like the example: {"name", zeny, {item id, item count}}; {"main" , 1000, 0 , 0}, // #main - 1000z and no item }; if (sd && chan->msg_delay != 0 && DIFF_TICK(sd->hchsysch_tick + chan->msg_delay*1000, timer->gettick()) > 0 && !pc_has_permission(sd, PC_PERM_HCHSYS_ADMIN)) { clif->messagecolor_self(sd->fd, COLOR_RED, msg_sd(sd,1455)); return; } else if (sd) { // -- Check for fees and pay them if exists for ( i = 0; i < ARRAYLENGTH(channels_fee); i++ ) { if ( strcmpi(channels_fee[i].name, chan->name) == 0 ) { if ( channels_fee[i].zeny > 0 ) { fee |= CF_ZENY; zeny = channels_fee[i].zeny; } if ( itemdb->exists(channels_fee[i].nameid) ) { fee |= CF_ITEM; it.nameid = channels_fee[i].nameid; it.amount = channels_fee[i].amount; } break; } } do { if ( fee ) { bool fee_ok = false; if ( fee&CF_ZENY ) { // -- Zeny if ( zeny > sd->status.zeny ) { safesnprintf(alert, 150, "You need at least %d zeny to send messages on #%s channel.", zeny, chan->name); clif->messagecolor_self(sd->fd, COLOR_RED, alert); break; } else { fee_ok = true; } } if ( fee&CF_ITEM ) { // -- Item idx = pc->search_inventory(sd, it.nameid); if ( idx == INDEX_NOT_FOUND || sd->status.inventory[idx].amount < it.amount ) { struct item_data *id = itemdb->search(it.nameid); safesnprintf(alert, 150, "You need at least [%d x %s] to send messages on #%s channel.", it.amount, id->jname, chan->name); clif->messagecolor_self(sd->fd, COLOR_RED, alert); break; } else { fee_ok = true; } } if ( fee_ok ) { if ( fee&CF_ITEM ) if ( pc->delitem(sd, idx, it.amount, 0, DELITEM_NORMAL, LOG_TYPE_SCRIPT) ) // Returns 0 uppon success and 1 uppon failure (It's strange) break; if ( fee&CF_ZENY ) pc->payzeny(sd, zeny, LOG_TYPE_NPC, NULL); } } safesnprintf(message, 150, "[ #%s ] %s : %s", chan->name, sd->status.name, msg); clif->channel_msg(chan, sd, message); if (chan->type == HCS_TYPE_IRC) ircbot->relay(sd->status.name,msg); if (chan->msg_delay != 0) sd->hchsysch_tick = timer->gettick(); } while(0); } else { safesnprintf(message, 150, "[ #%s ] %s", chan->name, msg); clif->channel_msg2(chan, message); if (chan->type == HCS_TYPE_IRC) ircbot->relay(NULL, msg); } } HPExport void server_online (void) { ShowInfo ("'%s' Plugin by Bio/Hercules. Version '%s'\n", pinfo.name, pinfo.version); channel->send = channel_send_fee; }