viewing paste topic/11584- nightmap | 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
//===== Hercules Plugin ======================================
//= nightmap
//===== By: ==================================================
//= AnnieRuru
//= original by Masao
//===== Current Version: =====================================
//= 0.1
//===== Compatible With: ===================================== 
//= Hercules 2015-12-28
//===== Description: =========================================
//= turn only the one current map into day/night mode
//===== Topic ================================================
//= http://herc.ws/board/topic/11584-stop-gaining-exp-at-specific-level/?p=68089
//===== Additional Comments: =================================  
//= maybe I should've done this as paid release ...
//============================================================
 
#include "common/hercules.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "map/pc.h"
#include "common/memmgr.h"
#include "common/nullpo.h"
#include "common/HPMDataCheck.h"
 
HPExport struct hplugin_info pinfo = {
    "nightmap",
    SERVER_TYPE_MAP,
    "0.1",
    HPM_VERSION,
};
 
struct mapflag_data {
    unsigned nightmap : 1;
};
 
 
int buildin_nightmap_sub( struct block_list *bl, va_list ap ) {
    TBL_PC *sd = BL_CAST( BL_PC, bl );
    bool flag = va_arg( ap, bool );
    if ( flag == true )
        clif->status_change( &sd->bl, SI_SKE, 1, 0, 0, 0, 0 );
    else
        clif->sc_end( &sd->bl, sd->bl.id, SELF, SI_SKE );
    return true;
}
 
void npc_parse_unknown_mapflag_pre( const char *name, char *w3, char *w4, const char* start, const char* buffer, const char* filepath, int *retval ) {
    if ( !strcmp(w3,"nightmap") ) {
        int16 m = map->mapname2mapid( name );
        struct mapflag_data *mf = getFromMAPD( &map->list[m], 0 );
        if ( !mf ) {
            CREATE( mf, struct mapflag_data, 1 );
            addToMAPD( &map->list[m], mf, 0, true );
        }
        mf->nightmap = true;
        map->foreachinmap( buildin_nightmap_sub, m, BL_PC, true );
        hookStop();
    }
    return;
}
 
//  flush all nightmap mapflag back to default upon @reloadscript
void map_flags_init_pre(void) {
    int i;
    for ( i = 0; i < map->count; ++i ) {
        struct mapflag_data *mf = getFromMAPD( &map->list[i], 0 );
        if ( mf ) {
            removeFromMAPD( &map->list[i], 0 );
            map->foreachinmap( buildin_nightmap_sub, i, BL_PC, false );
        }
    }
    return;
}
 
void clif_parse_LoadEndAck_post( int fd, struct map_session_data *sd ) {
    struct mapflag_data *mf = getFromMAPD( &map->list[sd->bl.m], 0 );
    if ( mf && mf->nightmap == true )
        clif->status_change( &sd->bl, SI_SKE, 1, 0, 0, 0, 0 );
    else if ( !sd->sc.data[SC_SOULLINK] )
        clif->sc_end( &sd->bl, sd->bl.id, SELF, SI_SKE );
}
 
ACMD(nightmap) {
    struct mapflag_data *mf = getFromMAPD( &map->list[sd->bl.m], 0 );
    if ( !mf ) {
        CREATE( mf, struct mapflag_data, 1 );
        addToMAPD( &map->list[sd->bl.m], mf, 0, true );
        mf->nightmap = false;
    }
    mf->nightmap = !(mf->nightmap);
    map->foreachinmap( buildin_nightmap_sub, sd->bl.m, BL_PC, mf->nightmap );
    if ( mf->nightmap == false )
        clif->message( fd, "Daymode has activated." );
    else
        clif->message( fd, "Nightmode has activated." );
    return true;
}
 
HPExport void plugin_init (void) {
    addHookPre( "npc->parse_unknown_mapflag", npc_parse_unknown_mapflag_pre );
    addHookPre( "map->flags_init", map_flags_init_pre );
    addHookPost( "clif->pLoadEndAck", clif_parse_LoadEndAck_post );
    addAtcommand( "nightmap", nightmap );
}
Viewed 1325 times, submitted by AnnieRuru.