viewing paste samuel_timer_atcommand2 | C

Posted on the
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
#include "common/hercules.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "map/pc.h"
#include "map/clif.h"
#include "map/atcommand.h"
#include "common/timer.h"
#include "common/nullpo.h"
#include "common/HPMDataCheck.h"
 
HPExport struct hplugin_info pinfo = {
        "samuel",
        SERVER_TYPE_MAP,
        "^.^",
        HPM_VERSION,
};
 
int timer_id = INVALID_TIMER;
int timer_countdown = 0;
 
int countdown( int tid, int64 tick, int id, intptr data ) {
        TBL_PC *sd = map->id2sd(id);
        if ( sd ) {
                if ( --timer_countdown ) {
                        char aaa[CHAT_SIZE_MAX];
                        safesnprintf( aaa, CHAT_SIZE_MAX, "%d", timer_countdown );
                        clif->message( sd->fd, aaa );
                        timer_id = timer->add( timer->gettick() + 1000, countdown, sd->bl.id, 0 );
                }
                else {
                        clif->specialeffect( &sd->bl, 49, SELF );
                        clif->message( sd->fd, "BOOM !! just kidding." );
                }
        }
        else
                 timer_countdown = 0;
        return false;
}
 
ACMD(test) {
        if ( timer_countdown )
                return false;
        timer_id = timer->add( timer->gettick() + 1000, countdown, sd->bl.id, 0 );
        clif->message( sd->fd, "After 5 seconds, you'll die ..." );
        timer_countdown = 5;
        return true;
}
       
HPExport void plugin_init (void) {
        addAtcommand( "test", test );
}
Viewed 722 times, submitted by AnnieRuru.