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;