温馨提示:按ctrl+D可将【神途之家】放入IE收藏夹中,方便下次浏览~ 加入收藏设为首页手机版
您现在的位置:首页 > GM手册 > 脚本库 > 正文

野蛮冲锋

更新时间:2014-09-23 13:42:56   点击:

野蛮冲锋

--script\skill\野蛮冲锋.lua
--脚本挂在技能中即可

local self_buffs = {"野蛮冲锋3级", "野蛮冲锋2级", "野蛮冲锋1级"};        --野蛮冲锋技能给自己附加的BUFF
local self_hp = {10, 50};        --冲撞失败后自身扣HP值(10~50随机)
local target_hp = {5, 30};        --冲撞成功后目标扣HP值(随机)

function post_apply(player, skill, x, y, targets)
    local id = lualib:GenTimerId(player);
    local map = lualib:MapGuid(player);
    local target = "";
    if #targets == 1 then
        target = targets[1];
    elseif #targets > 1 then
        target = get_target(player, targets);
    end

    lualib:AddTimerEx(player, id, 1000, 1, "on_timer_post_apply", target);
end

function on_timer_post_apply(player, id, target)
    if target == nil then
        target = "";
    end
    
    local result = false;
    for _, v in ipairs(self_buffs) do
        if lualib:HasBuff(player, v) then
            result = true;
            break;
        end
    end
    
    if not result then
        --冲撞被打断
        if target == "" then
            ReduceHp(player, self_hp);        --无目标(撞墙等),自身扣血
        else
            if lualib:Level(player) <= lualib:Level(target) or lualib:HasBuff(target, "无敌") then
                ReduceHp(player, self_hp);        --未撞动,自身扣血
            else
                if IsFront(player, target) then
                    ReduceHp(target, target_hp);    --撞动,目标扣血
                end
            end
        end
    else
        --冲撞未被打断        
        if target ~= "" and IsFront(player, target) then
            ReduceHp(target, target_hp);
        end
    end
end

function get_target(player, targets)
    local index = 1;
    local temp = lualib:Distance(player, targets[1]);
    for i = 2, #targets do
        local distance = lualib:Distance(player, targets[i]);
        if distance < temp then
            temp = distance;
            index = i;
        end
    end
    
    return targets[index];
end

function ReduceHp(role, hp)
    hp = lualib:GenRandom(hp[1], hp[2]);
    local hp_ref = -1 * hp;
    hp = lualib:Hp(role, false) - hp;
    if hp > 0 then
        lualib:SetHp(role, hp, false);
    else
        lualib:Kill(role);
    end
    lualib:SendRoleHPNtf(role);        --通知周围角色的血条,较耗,自行斟酌是否需要
    lualib:ShowRoleHPRef("", role, hp_ref);        --通知周围角色头顶冒血,较耗,自行斟酌是否需要(若需要请更新测试版最新的引擎)
end

function IsFront(role, target)
    local dxs = {[0] = 0, 1, 1, 1, 0, -1, -1, -1};
    local dys = {[0] = -1, -1, 0, 1, 1, 1, 0, -1};
    local role_x, role_y = lualib:X(role), lualib:Y(role);
    local target_x, target_y = lualib:X(target), lualib:Y(target);
    local dir = lualib:Dir(role);
    if (target_x == (role_x + dxs[dir])) and (target_y == (role_y + dys[dir])) then
        return true;
    else
        return false;
    end
end

上一篇:lua字符串脚本
下一篇:客户端外挂检测

随机推送文章

频道月排行

本神途发布网发布的所有神途开区资讯都经过严格测试,本站只推送人气好、散人多、版本好的神途,力争打早业界最出色的神途开服表。

神途开服表_神途传奇_神途发布网_神途之家官网 - www.shentuzhijia.com

CopyRight 2006 - 2015 神途之家 版权所有. 网站备案号:湘ICP备14005290号-1