[EN] This NPC example is intended to provide the required trade based on the time of day. You can further customize and modify the code to suit your needs.
From 1:00 PM to 5:00 PM, the NPC will provide trade list 528.xml. On the 1st, 15th, and 28th of each month, it will provide trade list 530.xml. In all other cases, it will provide trade list 531.xml.
[RU] Данный пример НПЦ предназначит что бы давать нужный вам трейд в зависимости от времени дня. Далее вы можете дополнять и изменять код под ваши нужды.
С 13:00 и до 17:00 НПЦ будет выдавать трейд лист 528.xml, 1, 15, 28 числа каждого месяца будет выдавать трейд 530.xml, в любых других случаях будет выдавать 531.xml
Code:
Dialog/bypass:
gameserver/html-en/mods/services/40055.htm
Npc Exmaple:
<set name="type" value="TimeDependenceMerchant" />
From 1:00 PM to 5:00 PM, the NPC will provide trade list 528.xml. On the 1st, 15th, and 28th of each month, it will provide trade list 530.xml. In all other cases, it will provide trade list 531.xml.
[RU] Данный пример НПЦ предназначит что бы давать нужный вам трейд в зависимости от времени дня. Далее вы можете дополнять и изменять код под ваши нужды.
С 13:00 и до 17:00 НПЦ будет выдавать трейд лист 528.xml, 1, 15, 28 числа каждого месяца будет выдавать трейд 530.xml, в любых других случаях будет выдавать 531.xml
Code:
Java:
package npc.model;
import l2.gameserver.data.xml.holder.MultiSellHolder;
import l2.gameserver.model.Player;
import l2.gameserver.model.instances.MerchantInstance;
import l2.gameserver.templates.npc.NpcTemplate;
import java.time.LocalDate;
import java.time.LocalTime;
public class TimeDependenceMerchantInstance extends MerchantInstance
{
public TimeDependenceMerchantInstance(int objectId, NpcTemplate template)
{
super(objectId, template);
}
@Override
public void onBypassFeedback(Player player, String command)
{
if(!canBypassCheck(player, this))
return;
if(command.startsWith("give_me_trade"))
{
LocalTime currentTime = LocalTime.now();
LocalDate currentDate = LocalDate.now();
LocalTime startTime = LocalTime.of(13, 0); // 13:00
LocalTime endTime = LocalTime.of(17, 0); // 17:00
int dayOfMonth = currentDate.getDayOfMonth();
if (dayOfMonth == 1 || dayOfMonth == 15 || dayOfMonth == 28)
{
MultiSellHolder.getInstance().SeparateAndSend(530, player, 0);
}
else if (currentTime.isAfter(startTime) && currentTime.isBefore(endTime))
{
MultiSellHolder.getInstance().SeparateAndSend(528, player, 0);
}
else
{
MultiSellHolder.getInstance().SeparateAndSend(531, player, 0);
}
}
else
{
super.onBypassFeedback(player, command);
}
}
}
Dialog/bypass:
gameserver/html-en/mods/services/40055.htm
HTML:
<html><head>
<body>Trader:<br> Trader Depending on time
<br> <br><a action="bypass -h npc_%objectId%_give_me_trade">Show me items.</a>
</body></html>
Npc Exmaple:
<set name="type" value="TimeDependenceMerchant" />
XML:
<npc id="40055" name="Trader" title="Service Manager">
<set name="aggroRange" value="0" />
<set name="ai_type" value="CharacterAI" />
<set name="baseAtkRange" value="40" />
<set name="baseCON" value="43" />
<set name="baseCritRate" value="40" />
<set name="baseDEX" value="30" />
<set name="baseHpMax" value="680" />
<set name="baseHpRate" value="1" />
<set name="baseHpReg" value="0" />
<set name="baseINT" value="21" />
<set name="baseMAtk" value="11" />
<set name="baseMAtkSpd" value="253" />
<set name="baseMDef" value="375180" />
<set name="baseMEN" value="20" />
<set name="baseMpMax" value="2000" />
<set name="baseMpReg" value="0.9" />
<set name="basePAtk" value="17" />
<set name="basePAtkSpd" value="253" />
<set name="basePDef" value="101400" />
<set name="baseRunSpd" value="120" />
<set name="baseSTR" value="40" />
<set name="baseShldDef" value="0" />
<set name="baseShldRate" value="0" />
<set name="baseWIT" value="20" />
<set name="baseWalkSpd" value="30" />
<set name="collision_height" value="23.0" />
<set name="collision_radius" value="8.0" />
<set name="level" value="80" />
<set name="rewardExp" value="0" />
<set name="rewardRp" value="0" />
<set name="rewardSp" value="0" />
<set name="shots" value="NONE" />
<set name="texture" value="" />
<set name="type" value="TimeDependenceMerchant" />
<set name="displayId" value="31790"/>
<set name="htm_root" value="mods/services/" />
<attributes>
<defence attribute="fire" value="20" />
<defence attribute="water" value="20" />
<defence attribute="wind" value="20" />
<defence attribute="earth" value="20" />
<defence attribute="holy" value="20" />
<defence attribute="unholy" value="20" />
</attributes>
</npc>
Last edited: