viewing paste Autopots | C

Posted on the | Last edited on
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "common/HPMi.h"
#include "common/timer.h"
#include "map/script.h"
#include "map/pc.h"
#include "map/map.h"
#include "map/unit.h"
#include "map/atcommand.h"
#include "map/itemdb.h"
 
#include "common/HPMDataCheck.h"/* should always be the last file included! (if you don't make it last, it'll intentionally break compile time) */
 
#define OPTION_AUTOPOTS 0x40000000
 
 
/*
3.1 Plugins Release [Mhalicot]
3.2 Update to Latest Revision [Mhalicot]
4.0 Added autohp, autosp command Rev. 137* [Mhalicot]
4.1 Fixed Compilation error. Rev. 145*** [Mhalicot]
-----------------------------------------------------
Documentation
@autopots <hp_rate> <hp_item id> <sp_rate> <sp_item id>
@autohp <hp_rate> <hp_item id>
@autosp <sp_rate> <sp_item id
// Change autopots/hp/sp timer by replacing +500 in milisec
        timer->add(timer->gettick()+500,autoatpots_timer,sd->bl.id,0);
*/
HPExport struct hplugin_info pinfo = {  
    "autopots",     // Plugin name
    SERVER_TYPE_MAP,    // Which server types this plugin works with?
    "4.0",              // Plugin version
    HPM_VERSION,        // HPM Version (don't change, macro is automatically updated)
};
struct autopots {
unsigned int hp_rate, sp_rate, hp_nameid, sp_nameid;
};
struct autopots autopots;
void autoatpots_clean(struct map_session_data *sd)
{
    if( sd )
    {
        sd->sc.option &= ~OPTION_AUTOPOTS;
        autopots.hp_nameid = 0;
        autopots.hp_rate = 0;
        autopots.sp_nameid = 0;
        autopots.sp_rate = 0;
        clif->changeoption(&sd->bl);
    }
    return;
}
void autoathp_clean(struct map_session_data *sd)
{
    if( sd )
    {
        sd->sc.option &= ~OPTION_AUTOPOTS;
        autopots.hp_nameid = 0;
        autopots.hp_rate = 0;
        clif->changeoption(&sd->bl);
    }
    return;
}
void autoatsp_clean(struct map_session_data *sd)
{
    if( sd )
    {
        sd->sc.option &= ~OPTION_AUTOPOTS;
        autopots.sp_nameid = 0;
        autopots.sp_rate = 0;
        clif->changeoption(&sd->bl);
    }
    return;
}
int autoatpots_timer(int tid, int64 tick, int id, intptr_t data)
{
    struct map_session_data *sd=NULL;
    struct item_data* item = NULL;
    int index;
    sd=map->id2sd(id);
    if( sd == NULL )
        return 0;
    if(sd->sc.option & OPTION_AUTOPOTS)
    {
        unsigned int hp_rate = autopots.hp_rate;
        unsigned int sp_rate = autopots.sp_rate;
        unsigned int hp_nameid = autopots.hp_nameid;
        unsigned int sp_nameid = autopots.sp_nameid;
        if( ( !sp_rate && !hp_rate ) || pc_isdead(sd) )
        {
            if( !hp_rate ) 
            {
                clif->message(sd->fd, "Auto-SP : OFF_");
                autoatsp_clean(sd);
                return 0;
            }else
            if( !sp_rate )
            {
                clif->message(sd->fd, "Auto-HP : OFF_");
                autoathp_clean(sd);
                return 0;
            }
        else{
            clif->message(sd->fd, "Auto-pots : OFF_");
            autoatpots_clean(sd);
            return 0;
            }
        }
 
        if( ( sd->battle_status.hp*100/sd->battle_status.max_hp ) < hp_rate && hp_nameid && hp_rate )
        {
            ARR_FIND(0, MAX_INVENTORY, index, sd->status.inventory[index].nameid == hp_nameid);
            if( sd->status.inventory[index].nameid == hp_nameid )
                pc->useitem(sd,index);
        }
        if( ( sd->battle_status.sp*100/sd->battle_status.max_sp ) < sp_rate && sp_nameid && sp_rate )
        {
            ARR_FIND(0, MAX_INVENTORY, index, sd->status.inventory[index].nameid == sp_nameid);
            if( sd->status.inventory[index].nameid == sp_nameid )
                pc->useitem(sd,index);
        }
        timer->add(timer->gettick()+500,autoatpots_timer,sd->bl.id,0);
    }
    return 0;
}
ACMD(autopots)
{
    int hp_rate=0, hp_nameid=0, sp_rate=0, sp_nameid=0;
    if( !sd ) return 0;
 
    if ( !message || !*message || (
        sscanf_s(message, "%d %d %d %d ", &hp_rate, &hp_nameid, &sp_rate, &sp_nameid) < 4) ||
        ( hp_rate < 0 || hp_rate > 99 ) ||
        ( sp_rate < 0 || sp_rate > 99 ) )
    {
        if ( sscanf_s(message, "%d %d %d %d ", &hp_rate, &hp_nameid, &sp_rate, &sp_nameid) < 4 &&
            sscanf_s(message, "%d %d %d %d ", &hp_rate, &hp_nameid, &sp_rate, &sp_nameid) > 0)
        {
            clif->message(fd, "@autopots <hp_rate> <hp_item id> <sp_rate> <sp_item id>");
            return false;
        }
        clif->message(fd, "Auto-pots : OFF");
        autoatpots_clean(sd);
        return true;
    }
 
    if (sd->sc.option & OPTION_AUTOPOTS)
    {
        autoatpots_clean(sd);
    }
    if( hp_rate == 0 ) hp_nameid = 0;
    if( sp_rate == 0 ) sp_nameid = 0;
    if( hp_nameid == 0 ) hp_rate = 0;
    if( sp_nameid == 0 ) sp_rate = 0;
    if( itemdb->exists(hp_nameid) == NULL && hp_nameid )
    {
        hp_nameid = 0;
        hp_rate = 0;
        clif->message(fd, "Auto-pots : Invalid item for HP");
    }
    if( itemdb->exists(sp_nameid) == NULL && sp_nameid )
    {
        sp_nameid = 0;
        sp_rate = 0;
        clif->message(fd, "Auto-pots : Invalid item for SP");
        return true;
    }
    clif->message(fd, "Auto-pots : ON");
    sd->sc.option |= OPTION_AUTOPOTS;
    autopots.hp_nameid = hp_nameid;
    autopots.hp_rate = hp_rate;
    autopots.sp_nameid = sp_nameid;
    autopots.sp_rate = sp_rate;
    timer->add(timer->gettick()+200,autoatpots_timer,sd->bl.id,0);
 
    clif->changeoption(&sd->bl);
    return true;
}
ACMD(autohp)
{
    int hp_rate=0, hp_nameid=0;
    if( !sd ) return 0;
 
    if (!message || !*message || (
        sscanf_s(message, "%d %d ", &hp_rate, &hp_nameid) < 2) ||
        ( hp_rate < 0 || hp_rate > 99 ) )
    {
        if ( sscanf_s(message, "%d %d ", &hp_rate, &hp_nameid) < 2 &&
            sscanf_s(message, "%d %d ", &hp_rate, &hp_nameid) > 0) 
        {
            clif->message(fd, "@autohp <hp_rate> <hp_item id>");
            return true;
        }
        clif->message(fd, "Auto-HP : OFF");
        autoathp_clean(sd);
        return true;
    }
 
    if (sd->sc.option & OPTION_AUTOPOTS)
    {
        autoathp_clean(sd);
    }
    if( hp_rate == 0 ) hp_nameid = 0;
    if( hp_nameid == 0 ) hp_rate = 0;
    if( itemdb->exists(hp_nameid) == NULL && hp_nameid )
    {
        hp_nameid = 0;
        hp_rate = 0;
        clif->message(fd, "Auto-HP : Invalid item for HP");
        return true;
    }
    clif->message(fd, "Auto-HP : ON");
    sd->sc.option |= OPTION_AUTOPOTS;
    autopots.hp_nameid = hp_nameid;
    autopots.hp_rate = hp_rate;
    timer->add(timer->gettick()+200,autoatpots_timer,sd->bl.id,0);
 
    clif->changeoption(&sd->bl);
    return true;
}
ACMD(autosp)
{
    int sp_rate=0, sp_nameid=0;
    if( !sd ) return 0;
 
    if (!message || !*message || (
        sscanf_s(message, "%d %d ", &sp_rate, &sp_nameid) < 2) ||
        ( sp_rate < 0 || sp_rate > 99 ) )
    {
        if ( sscanf_s(message, "%d %d ", &sp_rate, &sp_nameid) < 2 &&
            sscanf_s(message, "%d %d ", &sp_rate, &sp_nameid) > 0) 
        {
            clif->message(fd, "@autosp <sp_rate> <sp_item id>");
            return true;
        }
        clif->message(fd, "Auto-SP : OFF");
        autoatsp_clean(sd);
        return true;
    }
 
    if (sd->sc.option & OPTION_AUTOPOTS)
    {
        autoatsp_clean(sd);
    }
    if( sp_rate == 0 ) sp_nameid = 0;
    if( sp_nameid == 0 ) sp_rate = 0;
    if( itemdb->exists(sp_nameid) == NULL && sp_nameid )
    {
        sp_nameid = 0;
        sp_rate = 0;
        clif->message(fd, "Auto-SP : Invalid item for SP");
        return true;
    }
    clif->message(fd, "Auto-SP : ON");
    sd->sc.option |= OPTION_AUTOPOTS;
    autopots.sp_nameid = sp_nameid;
    autopots.sp_rate = sp_rate;
    timer->add(timer->gettick()+200,autoatpots_timer,sd->bl.id,0);
 
    clif->changeoption(&sd->bl);
    return true;
}
/* Server Startup */
HPExport void plugin_init (void)
{
    addAtcommand("autopots",autopots);//link our '@autopots' command
    addAtcommand("autohp",autohp);//link our '@autohp' command
    addAtcommand("autosp",autosp);//link our '@autosp' command
}
 
Viewed 1285 times, submitted by Dastgir.