Here's one solution:
In script.inc. Add this function at the end of the file:
BUILDIN_FUNC(logout_tick)
{
TBL_PC *sd;
if (!script_rid2sd(sd)) {
script_pushint(st, -1);
return SCRIPT_CMD_FAILURE;
}
if (sd->canlog_tick == 0)
script_pushint(st, 0);
else
script_pushint(st, DIFF_TICK(gettick(), sd->canlog_tick));
return SCRIPT_CMD_SUCCESS;
}
in script_def.inc. Add this line at the end of the file:
BUILDIN_DEF(logout_tick, ""),
Then recompile your server.
This script command will check for the same timer used to check if a player can log out or not. Basically it returns how many milliseconds ago was the character in combat.
Example usage:
- script testscript -1,{
OnInit:
bindatcmd("testcmd", strnpcinfo(3)+"::OnAtCmd");
end;
OnAtCmd:
.@tick = logout_tick();
dispbottom "You have been in combat "+.@tick/1000+" seconds ago.";
if(.@tick >= 5000 || .@tick == 0)
dispbottom "Command used successfully!";
else
dispbottom "You cannot use this command if you have been in combat during the last 5 seconds.";
end;
}
Result: