viewing paste OnPCIdleEvent.diff | Diff

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 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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
 src/map/atcommand.c |  5 +++-
 src/map/clif.c      | 83 ++++++++++++++++++++++++++++++++++++++++++-----------
 src/map/npc.c       |  1 +
 src/map/npc.h       |  1 +
 src/map/script.c    |  1 +
 src/map/script.h    |  1 +
 6 files changed, 75 insertions(+), 17 deletions(-)
 
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 50ec913..697c9e5 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -9855,8 +9855,11 @@ bool atcommand_exec(const int fd, struct map_session_data *sd, const char *messa
        sprintf(atcmd_msg, "%s", message);
    }
 
-   if( battle_config.idletime_criteria & BCIDLE_ATCOMMAND )
+   if( battle_config.idletime_criteria & BCIDLE_ATCOMMAND ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
    
    //Clearing these to be used once more.
    memset(command, '\0', sizeof(command));
diff --git a/src/map/clif.c b/src/map/clif.c
index d023455..7039fe0 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -9435,6 +9435,9 @@ void clif_parse_LoadEndAck(int fd,struct map_session_data *sd) {
 
        //Login Event
        npc->script_event(sd, NPCE_LOGIN);
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), 100 );
+
    } else {
        //For some reason the client "loses" these on warp/map-change.
        clif->updatestatus(sd,SP_STR);
@@ -9707,8 +9710,11 @@ void clif_parse_WalkToXY(int fd, struct map_session_data *sd)
    RFIFOPOS(fd, packet_db[RFIFOW(fd,0)].pos[0], &x, &y, NULL);
 
    //Set last idle time... [Skotlex]
-   if( battle_config.idletime_criteria & BCIDLE_WALK )
+   if( battle_config.idletime_criteria & BCIDLE_WALK ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
 
    unit->walktoxy(&sd->bl, x, y, 4);
 }
@@ -9858,8 +9864,11 @@ void clif_parse_GlobalMessage(int fd, struct map_session_data* sd)
        }
    }
 
-   if( battle_config.idletime_criteria & BCIDLE_CHAT )
+   if( battle_config.idletime_criteria & BCIDLE_CHAT ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
 
    if( sd->gcbind ) {
        clif->chsys_send(sd->gcbind,sd,message);
@@ -10023,8 +10032,11 @@ void clif_parse_Emotion(int fd, struct map_session_data *sd)
        }
        sd->emotionlasttime = time(NULL);
 
-       if( battle_config.idletime_criteria & BCIDLE_EMOTION )
+       if( battle_config.idletime_criteria & BCIDLE_EMOTION ) {
            sd->idletime = sockt->last_tick;
+           npc->script_event(sd, NPCE_IDLE);
+           pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+       }
 
        if(battle_config.client_reshuffle_dice && emoticon>=E_DICE1 && emoticon<=E_DICE6) {// re-roll dice
            emoticon = rnd()%6+E_DICE1;
@@ -10107,8 +10119,11 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type,
            }
 
            pc->delinvincibletimer(sd);
-           if( battle_config.idletime_criteria & BCIDLE_ATTACK )
+           if( battle_config.idletime_criteria & BCIDLE_ATTACK ) {
                sd->idletime = sockt->last_tick;
+               npc->script_event(sd, NPCE_IDLE);
+               pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+           }
            unit->attack(&sd->bl, target_id, action_type != 0);
        break;
        case 0x02: // sitdown
@@ -10132,8 +10147,11 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type,
            )) //No sitting during these states either.
                break;
 
-           if( battle_config.idletime_criteria & BCIDLE_SIT )
+           if( battle_config.idletime_criteria & BCIDLE_SIT ) {
                sd->idletime = sockt->last_tick;
+               npc->script_event(sd, NPCE_IDLE);
+               pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+           }
 
            pc_setsit(sd);
            skill->sit(sd,1);
@@ -10146,8 +10164,11 @@ void clif_parse_ActionRequest_sub(struct map_session_data *sd, int action_type,
                return;
            }
 
-           if( battle_config.idletime_criteria & BCIDLE_SIT )
+           if( battle_config.idletime_criteria & BCIDLE_SIT ) {
                sd->idletime = sockt->last_tick;
+               npc->script_event(sd, NPCE_IDLE);
+               pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+           }
 
            pc->setstand(sd);
            skill->sit(sd,0);
@@ -10340,8 +10361,11 @@ void clif_parse_WisMessage(int fd, struct map_session_data* sd)
        sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
    }
 
-   if( battle_config.idletime_criteria & BCIDLE_CHAT )
+   if( battle_config.idletime_criteria & BCIDLE_CHAT ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
 
    // Chat logging type 'W' / Whisper
    logs->chat(LOG_CHAT_WHISPER, 0, sd->status.char_id, sd->status.account_id, mapindex_id2name(sd->mapindex), sd->bl.x, sd->bl.y, target, message);
@@ -10560,8 +10584,11 @@ void clif_parse_DropItem(int fd, struct map_session_data *sd)
        if (!pc->dropitem(sd, item_index, item_amount))
            break;
 
-       if( battle_config.idletime_criteria & BCIDLE_DROPITEM )
+       if( battle_config.idletime_criteria & BCIDLE_DROPITEM ) {
            sd->idletime = sockt->last_tick;
+           npc->script_event(sd, NPCE_IDLE);
+           pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+       }
 
        return;
    }
@@ -10588,8 +10615,11 @@ void clif_parse_UseItem(int fd, struct map_session_data *sd)
        return;
 
    //Whether the item is used or not is irrelevant, the char ain't idle. [Skotlex]
-   if( battle_config.idletime_criteria & BCIDLE_USEITEM )
+   if( battle_config.idletime_criteria & BCIDLE_USEITEM ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
    n = RFIFOW(fd,packet_db[RFIFOW(fd,0)].pos[0])-2;
 
    if(n <0 || n >= MAX_INVENTORY)
@@ -10635,8 +10665,11 @@ void clif_parse_EquipItem(int fd,struct map_session_data *sd) {
        return;
    }
 
-   if( battle_config.idletime_criteria & BCIDLE_USEITEM )
+   if( battle_config.idletime_criteria & BCIDLE_USEITEM ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
 
    //Client doesn't send the position for ammo.
    if(sd->inventory_data[p->index]->type == IT_AMMO)
@@ -10755,8 +10788,11 @@ void clif_parse_UnequipItem(int fd,struct map_session_data *sd)
 
    index = RFIFOW(fd,2)-2;
 
-   if( battle_config.idletime_criteria & BCIDLE_USEITEM )
+   if( battle_config.idletime_criteria & BCIDLE_USEITEM ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
 
    pc->unequipitem(sd,index,1);
 }
@@ -11304,8 +11340,11 @@ void clif_parse_UseSkillToId(int fd, struct map_session_data *sd)
    }
 
    // Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
-   if( battle_config.idletime_criteria & BCIDLE_USESKILLTOID )
+   if( battle_config.idletime_criteria & BCIDLE_USESKILLTOID ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
 
    if( sd->npc_id || sd->state.workinprogress&1 ){
 #ifdef RENEWAL
@@ -11405,8 +11444,11 @@ void clif_parse_UseSkillToPosSub(int fd, struct map_session_data *sd, uint16 ski
 #endif
 
    //Whether skill fails or not is irrelevant, the char ain't idle. [Skotlex]
-   if( battle_config.idletime_criteria & BCIDLE_USESKILLTOPOS )
+   if( battle_config.idletime_criteria & BCIDLE_USESKILLTOPOS ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
 
    if( skill->not_ok(skill_id, sd) )
        return;
@@ -12161,8 +12203,11 @@ void clif_parse_PartyMessage(int fd, struct map_session_data* sd)
        sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
    }
 
-   if( battle_config.idletime_criteria & BCIDLE_CHAT )
+   if( battle_config.idletime_criteria & BCIDLE_CHAT ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
 
    party->send_message(sd, text, textlen);
 }
@@ -13223,8 +13268,11 @@ void clif_parse_GuildMessage(int fd, struct map_session_data* sd)
        sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
    }
 
-   if( battle_config.idletime_criteria & BCIDLE_CHAT )
+   if( battle_config.idletime_criteria & BCIDLE_CHAT ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
 
    if( sd->bg_id )
        bg->send_message(sd, text, textlen);
@@ -16212,8 +16260,11 @@ void clif_parse_BattleChat(int fd, struct map_session_data* sd)
        sd->cantalk_tick = timer->gettick() + battle_config.min_chat_delay;
    }
 
-   if( battle_config.idletime_criteria & BCIDLE_CHAT )
+   if( battle_config.idletime_criteria & BCIDLE_CHAT ) {
        sd->idletime = sockt->last_tick;
+       npc->script_event(sd, NPCE_IDLE);
+       pc->setreg( sd, script->add_str( "@last_action_timer" ), (int)time(NULL) );
+   }
 
    bg->send_message(sd, text, textlen);
 }
diff --git a/src/map/npc.c b/src/map/npc.c
index f77359b..ea68f5a 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -4137,6 +4137,7 @@ void npc_read_event_script(void)
        {"Die Event",script->config.die_event_name},
        {"Kill PC Event",script->config.kill_pc_event_name},
        {"Kill NPC Event",script->config.kill_mob_event_name},
+       {"Idle Event",script->config.idle_event_name},
    };
 
    for (i = 0; i < NPCE_MAX; i++)
diff --git a/src/map/npc.h b/src/map/npc.h
index 346a9f8..b2b81d0 100644
--- a/src/map/npc.h
+++ b/src/map/npc.h
@@ -137,6 +137,7 @@ enum npce_event {
    NPCE_DIE,
    NPCE_KILLPC,
    NPCE_KILLNPC,
+   NPCE_IDLE,
    NPCE_MAX
 };
 
diff --git a/src/map/script.c b/src/map/script.c
index 09a6f7b..039b8ce 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -19421,6 +19421,7 @@ void script_defaults(void) {
    script->config.loadmap_event_name = "OnPCLoadMapEvent";
    script->config.baselvup_event_name = "OnPCBaseLvUpEvent";
    script->config.joblvup_event_name = "OnPCJobLvUpEvent";
+   script->config.idle_event_name = "OnPCIdleEvent";
    script->config.ontouch_name = "OnTouch_";//ontouch_name (runs on first visible char to enter area, picks another char if the first char leaves)
    script->config.ontouch2_name = "OnTouch";//ontouch2_name (run whenever a char walks into the OnTouch area)
 
diff --git a/src/map/script.h b/src/map/script.h
index cf7f22a..9d2208e 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -334,6 +334,7 @@ struct Script_Config {
    const char *loadmap_event_name;
    const char *baselvup_event_name;
    const char *joblvup_event_name;
+   const char *idle_event_name;
 
    const char* ontouch_name;
    const char* ontouch2_name;
 
Viewed 1561 times, submitted by AnnieRuru.