Рейтинг темы:
  • 0 Голос(ов) - 0 в среднем
  • 1
  • 2
  • 3
  • 4
  • 5
Телепорт при атаке.
#1
В таблице npc есть тип L2Npc.
Как сделать, чтоб при атаке npc c типом L2Npc.
Телепортировало например сюда x = 1, y = -1, z = 5.

Я думаю копать нужно сюда:
data\scripts\handlers\actionhandlers\L2NpcAction.java

Код:
/*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package handlers.actionhandlers;

import com.l2jserver.gameserver.ai.CtrlIntention;
import com.l2jserver.gameserver.handler.IActionHandler;
import com.l2jserver.gameserver.model.L2Object;
import com.l2jserver.gameserver.model.L2Object.InstanceType;
import com.l2jserver.gameserver.model.actor.L2Character;
import com.l2jserver.gameserver.model.actor.L2Npc;
import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
import com.l2jserver.gameserver.model.entity.L2Event;
import com.l2jserver.gameserver.model.quest.Quest;
import com.l2jserver.gameserver.network.serverpackets.ActionFailed;
import com.l2jserver.gameserver.network.serverpackets.MyTargetSelected;
import com.l2jserver.gameserver.network.serverpackets.StatusUpdate;
import com.l2jserver.gameserver.network.serverpackets.ValidateLocation;
import com.l2jserver.util.Rnd;

public class L2NpcAction implements IActionHandler
{
    /**
     * Manage actions when a player click on the L2Npc.<BR><BR>
     *
     * <B><U> Actions on first click on the L2Npc (Select it)</U> :</B><BR><BR>
     * <li>Set the L2Npc as target of the L2PcInstance player (if necessary)</li>
     * <li>Send a Server->Client packet MyTargetSelected to the L2PcInstance player (display the select window)</li>
     * <li>If L2Npc is autoAttackable, send a Server->Client packet StatusUpdate to the L2PcInstance in order to update L2Npc HP bar </li>
     * <li>Send a Server->Client packet ValidateLocation to correct the L2Npc position and heading on the client </li><BR><BR>
     *
     * <B><U> Actions on second click on the L2Npc (Attack it/Intercat with it)</U> :</B><BR><BR>
     * <li>Send a Server->Client packet MyTargetSelected to the L2PcInstance player (display the select window)</li>
     * <li>If L2Npc is autoAttackable, notify the L2PcInstance AI with AI_INTENTION_ATTACK (after a height verification)</li>
     * <li>If L2Npc is NOT autoAttackable, notify the L2PcInstance AI with AI_INTENTION_INTERACT (after a distance verification) and show message</li><BR><BR>
     *
     * <FONT COLOR=#FF0000><B> <U>Caution</U> : Each group of Server->Client packet must be terminated by a ActionFailed packet in order to avoid
     * that client wait an other packet</B></FONT><BR><BR>
     *
     * <B><U> Example of use </U> :</B><BR><BR>
     * <li> Client packet : Action, AttackRequest</li><BR><BR>
     *
     * @param activeChar The L2PcInstance that start an action on the L2Npc
     *
     */
    public boolean action(L2PcInstance activeChar, L2Object target, boolean interact)
    {
        if (!((L2Npc)target).canTarget(activeChar))
            return false;
        
        activeChar.setLastFolkNPC((L2Npc)target);
        
        // Check if the L2PcInstance already target the L2Npc
        if (target != activeChar.getTarget())
        {
            // Set the target of the L2PcInstance activeChar
            activeChar.setTarget(target);
            
            // Check if the activeChar is attackable (without a forced attack)
[color=Red]            if (target.isAutoAttackable(activeChar))[/color]
            {
                ((L2Npc)target).getAI(); //wake up ai
                // Send a Server->Client packet MyTargetSelected to the L2PcInstance activeChar
                // The activeChar.getLevel() - getLevel() permit to display the correct color in the select window
                MyTargetSelected my = new MyTargetSelected(target.getObjectId(), activeChar.getLevel() - ((L2Character)target).getLevel());
                activeChar.sendPacket(my);
                
                // Send a Server->Client packet StatusUpdate of the L2Npc to the L2PcInstance to update its HP bar
                StatusUpdate su = new StatusUpdate(target);
                su.addAttribute(StatusUpdate.CUR_HP, (int) ((L2Character)target).getCurrentHp());
                su.addAttribute(StatusUpdate.MAX_HP, ((L2Character)target).getMaxHp());
                activeChar.sendPacket(su);
            }
            else
            {
                // Send a Server->Client packet MyTargetSelected to the L2PcInstance activeChar
                MyTargetSelected my = new MyTargetSelected(target.getObjectId(), 0);
                activeChar.sendPacket(my);
            }
            
            // Send a Server->Client packet ValidateLocation to correct the L2Npc position and heading on the client
            activeChar.sendPacket(new ValidateLocation((L2Character)target));
        }
        else if (interact)
        {
            activeChar.sendPacket(new ValidateLocation((L2Character)target));
            // Check if the activeChar is attackable (without a forced attack) and isn't dead
            if (target.isAutoAttackable(activeChar) && !((L2Character)target).isAlikeDead())
            {
                // Check the height difference
                if (Math.abs(activeChar.getZ() - target.getZ()) < 400) // this max heigth difference might need some tweaking
                {
                    // Set the L2PcInstance Intention to AI_INTENTION_ATTACK
                    activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_ATTACK, target);
                    // activeChar.startAttack(this);
                }
                else
                {
                    // Send a Server->Client ActionFailed to the L2PcInstance in order to avoid that the client wait another packet
                    activeChar.sendPacket(ActionFailed.STATIC_PACKET);
                }
            }
            else if (!target.isAutoAttackable(activeChar))
            {
                // Calculate the distance between the L2PcInstance and the L2Npc
                if (!((L2Npc)target).canInteract(activeChar))
                {
                    // Notify the L2PcInstance AI with AI_INTENTION_INTERACT
                    activeChar.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, target);
                }
                else
                {
                    if (((L2Npc)target).hasRandomAnimation())
                        ((L2Npc)target).onRandomAnimation(Rnd.get(8));
                    
                    // Open a chat window on client with the text of the L2Npc
                    if (((L2Npc)target).isEventMob)
                    {
                        L2Event.showEventHtml(activeChar, String.valueOf(target.getObjectId()));
                    }
                    else
                    {
                        Quest[] qlsa = ((L2Npc)target).getTemplate().getEventQuests(Quest.QuestEventType.QUEST_START);
                        if ((qlsa != null) && qlsa.length > 0)
                            activeChar.setLastQuestNpcObject(target.getObjectId());
                        Quest[] qlst = ((L2Npc)target).getTemplate().getEventQuests(Quest.QuestEventType.ON_FIRST_TALK);
                        if ((qlst != null) && qlst.length == 1)
                            qlst[0].notifyFirstTalk((L2Npc)target, activeChar);
                        else
                            ((L2Npc)target).showChatWindow(activeChar);
                    }
                }
            }
        }
        return true;
    }
    
    public InstanceType getInstanceType()
    {
        return InstanceType.L2Npc;
    }
}

И после if (target.isAutoAttackable(activeChar))
Нужно что-то прописать, типа чара телепортирует туда-то тудато, но сделать проверку на тип L2Npc.

SmileSmileSmile
Ответ
#2
ну можно взять например скил закена который телепортирует кудато, дать етим нпц, дать им агр чтобы при ударе юзали скил, а скил настроить на координаты..

Красивее будет Smile
Ответ
#3
APKO Написал:ну можно взять например скил закена который телепортирует кудато, дать етим нпц, дать им агр чтобы при ударе юзали скил, а скил настроить на координаты..

Красивее будет Smile

Не, такое не подходит.
Ответ
#4
куда подставить player.teleToLocation(147451, 46728, -3410, 0);, чтоб телепортнуло при атаке NPC(Не моба!).
Код:
@Override
    public void onAction(L2Player player, boolean shift)
    {
        if(player.getTarget() != this)
        {
            player.setTarget(this);
            if(player.getTarget() == this)
            {
                player.sendPacket(new MyTargetSelected(getObjectId(), player.getLevel() - getLevel()));
                if(isAutoAttackable(player))
                {
                    player.sendPacket(makeStatusUpdate(StatusUpdate.CUR_HP, StatusUpdate.MAX_HP));
                }
            }
            player.sendPacket(new ValidateLocation(this), Msg.ActionFail);
            return;
        }

        if(Events.onAction(player, this, shift))
        {
            player.sendActionFailed();
            return;
        }

        if(isAutoAttackable(player))
        {
            player.getAI().Attack(this, false, shift);
            return;
        }

        if(!isInRange(player, INTERACTION_DISTANCE))
        {
            if(player.getAI().getIntention() != CtrlIntention.AI_INTENTION_INTERACT)
                player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this, null);
            return;
        }

        if(!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && player.getKarma() < 0 && !player.isGM() && !(this instanceof L2WarehouseInstance || this instanceof L2ResidenceManager || this instanceof L2ClanHallDoormenInstance || this instanceof L2CastleDoormenInstance || this instanceof L2FortressDoormenInstance))
        {
            player.sendActionFailed();
            return;
        }

        // С NPC нельзя разговаривать мертвым и сидя
        if(!Config.ALLOW_TALK_WHILE_SITTING && player.isSitting() || player.isAlikeDead())
            return;

        if(System.currentTimeMillis() - _lastSocialAction > 10000 && !getTemplate().getAIParams().getBool("randomAnimationDisabled", false))
        {
            broadcastPacket(new SocialAction(getObjectId(), 2));
            _lastSocialAction = System.currentTimeMillis();
        }

        player.sendActionFailed();
        player.stopMove(false);
        if(isAutoAttackable(player))
                {
                    player.teleToLocation(147451, 46728, -3410, 0);
                }

        if(_isBusy)
            showBusyWindow(player);
        else if(hasChatWindow)
        {
            boolean flag = false;
            Quest[] qlst = getTemplate().getEventQuests(QuestEventType.NPC_FIRST_TALK);
            if(qlst != null && qlst.length > 0)
                for(Quest element : qlst)
                {
                    QuestState qs = player.getQuestState(element.getName());
                    if((qs == null || !qs.isCompleted()) && element.notifyFirstTalk(this, player))
                        flag = true;
                }
            if(!flag)
                showChatWindow(player, 0);
        }
    }
Ответ
#5
Попробуй поставить сюда-

Код:
@Override
    public void onAction(L2Player player, boolean shift)
    {
        if(player.getTarget() != this)
        {
            player.setTarget(this);
            if(player.getTarget() == this)
            {
                player.sendPacket(new MyTargetSelected(getObjectId(), player.getLevel() - getLevel()));
                if(isAutoAttackable(player))
                {
                    [B][color=Red]player.teleToLocation(147451, 46728, -3410, 0);[/color][/B]
                    player.sendPacket(makeStatusUpdate(StatusUpdate.CUR_HP, StatusUpdate.MAX_HP));
                }
            }
            player.sendPacket(new ValidateLocation(this), Msg.ActionFail);
            return;
        }

        if(Events.onAction(player, this, shift))
        {
            player.sendActionFailed();
            return;
        }

        if(isAutoAttackable(player))
        {
            [B][color=Red]player.teleToLocation(147451, 46728, -3410, 0);[/color][/B]
            player.getAI().Attack(this, false, shift);
            return;
        }

        if(!isInRange(player, INTERACTION_DISTANCE))
        {
            if(player.getAI().getIntention() != CtrlIntention.AI_INTENTION_INTERACT)
                player.getAI().setIntention(CtrlIntention.AI_INTENTION_INTERACT, this, null);
            return;
        }

        if(!Config.ALT_GAME_KARMA_PLAYER_CAN_SHOP && player.getKarma() < 0 && !player.isGM() && !(this instanceof L2WarehouseInstance || this instanceof L2ResidenceManager || this instanceof L2ClanHallDoormenInstance || this instanceof L2CastleDoormenInstance || this instanceof L2FortressDoormenInstance))
        {
            player.sendActionFailed();
            return;
        }

        // С NPC нельзя разговаривать мертвым и сидя
        if(!Config.ALLOW_TALK_WHILE_SITTING && player.isSitting() || player.isAlikeDead())
            return;

        if(System.currentTimeMillis() - _lastSocialAction > 10000 && !getTemplate().getAIParams().getBool("randomAnimationDisabled", false))
        {
            broadcastPacket(new SocialAction(getObjectId(), 2));
            _lastSocialAction = System.currentTimeMillis();
        }

        player.sendActionFailed();
        player.stopMove(false);
        if(isAutoAttackable(player))
                {
                    player.teleToLocation(147451, 46728, -3410, 0);
                }

        if(_isBusy)
            showBusyWindow(player);
        else if(hasChatWindow)
        {
            boolean flag = false;
            Quest[] qlst = getTemplate().getEventQuests(QuestEventType.NPC_FIRST_TALK);
            if(qlst != null && qlst.length > 0)
                for(Quest element : qlst)
                {
                    QuestState qs = player.getQuestState(element.getName());
                    if((qs == null || !qs.isCompleted()) && element.notifyFirstTalk(this, player))
                        flag = true;
                }
            if(!flag)
                showChatWindow(player, 0);
        }
    }
[Изображение: guru.gif] Сижу на zone-game, помогаю и напрягаю других.
Ответ
#6
Не помогло, вообще не сюда вставлять надо)))
Ответ


Возможно похожие темы ...
Тема Автор Ответы Просмотры Последний пост
  Рандомный телепорт gaaf 9 3,176 02-04-2014, 06:37 AM
Последний пост: WoWan-SM
  Проверка на weapon при атаке Delpin 4 1,935 11-28-2012, 09:17 PM
Последний пост: Delpin
  где хранится телепорт лист bybs 3 1,460 11-19-2012, 01:20 PM
Последний пост: [STIGMATED]
  Телепорт в Comunuty Board NightWar 4 1,478 08-27-2012, 02:59 PM
Последний пост: Ashe
  Телепорт админа в рефлекшин(инст) Munhgauzen 8 1,923 01-15-2012, 02:02 PM
Последний пост: KilRoy
  Скрипт Оффлайн телепорт для сайта МВ!) Evil-Soft 5 3,832 07-01-2009, 10:55 PM
Последний пост: kolya_ch
  Нормальный Телепорт qweqweqwe 1 2,362 06-04-2009, 02:15 PM
Последний пост: kostetr

Перейти к форуму:


Пользователи, просматривающие эту тему: 1 Гость(ей)