魔力宝贝

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz

[GA] Tohelos.lua--计时驱魔香

[复制链接]
发表于 前天 02:29 | 显示全部楼层 |阅读模式
------------------------------------------------------------------------------
------------------------------------------------------------------------------
--                 【【【脚本说明】】】
------------------------------------------------------------------------------
--计时驱魔香 For GA
--
--启用驱魔香后,每隔10分钟(可设置)扣除一个驱魔香,该10分钟内不遇敌
--
--in 2014.8.2
------------------------------------------------------------------------------
------------------------------------------------------------------------------
--                 【【【基础NPC设置】】】
------------------------------------------------------------------------------
local NpcName = "计时驱魔香"                --Npc名称(同时也是脚本名称)
local NpcMapPos = {0, 999, 16, 18}                        --Npc地图坐标
local NpcImage = 101022                                                --Npc图档101022
local NpcDir = 6                                                        --Npc方向(0为左上,顺时针转)
------------------------------------------------------------------------------
------------------------------------------------------------------------------
--                 【【【脚本系统设置】】】(非专业人事请勿修改)
------------------------------------------------------------------------------
--呼出菜单指令
local TohelosCMD = "/2"

--驱魔香物品设置
local TohelosItemID = 80150
local TohelosItemName = "驱魔香"

--每个驱魔香使用时长(单位:分钟)
local TohelosTime = 10
local TohelosPlayer = {}
------------------------------------------------------------------------------

function TohelosNpc_Func(index)
        --print("TohelosNpc=" .. index);
        return 1;
end

Delegate.RegInit("TohelosNpc_Init");
function TohelosNpc_Init()
        local TohelosNpc = NL.CreateNpc("lua/Module/PetTechScroll.lua", "TohelosNpc_Func");
        Char.SetData( TohelosNpc, %对象_形象%, NpcImage);
        Char.SetData( TohelosNpc, %对象_原形%, NpcImage);
        --Char.SetData( TohelosNpc, %对象_MAP%, NpcMapPos[1]);
        Char.SetData( TohelosNpc, %对象_地图%, NpcMapPos[2]);
        Char.SetData( TohelosNpc, %对象_X%, NpcMapPos[3]);
        Char.SetData( TohelosNpc, %对象_Y%, NpcMapPos[4]);
        Char.SetData( TohelosNpc, %对象_方向%, NpcDir);
        Char.SetData( TohelosNpc, %对象_名字%, NpcName);
        NLG.UpChar(TohelosNpc)

        tbl_LuaNpcIndex = tbl_LuaNpcIndex or {}
        tbl_LuaNpcIndex["TohelosNpc"] = TohelosNpc

        --Char.SetTalkedEvent("lua/Module/Tohelos.lua", "TohelosNpc_Talked", TohelosNpc)
        Char.SetWindowTalkedEvent("lua/Module/Tohelos.lua", "TohelosNpc_WindowTalked", TohelosNpc)
        --Char.SetLoopEvent("lua/Module/Tohelos.lua", "TohelosNpc_Loop", TohelosNpc, 10000)
       
        --return true;
end


Delegate.RegDelLogoutEvent("TohelosNpc_LogoutEvent");
function TohelosNpc_LogoutEvent(_PlayerIndex)
        TohelosNpc_ChangeStat(_PlayerIndex, 0)
        return 1
end

function TohelosNpc_WindowTalked( _MeIndex, _PlayerIndex, _Seqno, _Select, _Data)

        --print("\n_MeIndex=" .. _MeIndex .. ", _PlayerIndex=" .. _PlayerIndex .. ", _Seqno=" .. _Seqno .. ", _Select=" .. _Select .. ", _Data=" .. _Data)

        --取消按钮
        if _Select==2 or _Seqno==99999 then
                return
        end

        if _Seqno==0 then
                --Get Stat
                local TohelosItemNum = Char.ItemNum(_PlayerIndex, TohelosItemID)
                local TohelosHour = math.floor((TohelosTime*TohelosItemNum)/60)
                local TohelosMinute = math.floor(math.fmod(TohelosTime*TohelosItemNum, 60))
                local TohelosStat = "开启"
                if Char.GetData(_PlayerIndex, %对象_不遇敌开关%)==0 then
                        TohelosStat = "关闭"
                end
               
                --Show WinTalk
                local TalkMsg = "        ◆" .. NpcName .. "◆" ..
                                                "\n" ..
                                                "\n感谢你的支持,当前系统信息如下:" ..
                                                "\n" .. os.date("%X") ..
                                                "\n[物品消耗]:每" .. TohelosTime .. "分钟1个" .. TohelosItemName .. "(先扣除后计时)" ..
                                                "\n[剩余数量]:" .. TohelosItemName .. TohelosItemNum .. "个(大约使用" .. TohelosHour .. "小时" .. TohelosMinute .. "分钟)" ..
                                                "\n[使用状态]:" .. TohelosStat .. "   (点[确定]按钮修改状态)" ..
                                                "\n" ..
                                                "\n操作提示:" ..
                                                "\n点[确定]控制驱魔使用状态开关,点[取消]关闭窗口"

                NLG.ShowWindowTalked(_PlayerIndex, _MeIndex, 0, 3, 1, TalkMsg);
                return 1
        end

        --【确定】
        if _Seqno==1 and _Select==1 then
                TohelosNpc_ChangeStat(_PlayerIndex)
--                TohelosNpc_WindowTalked( tbl_LuaNpcIndex["TohelosNpc"], _PlayerIndex, 0, 0, 0)
                return 1
        end
end

Delegate.RegDelTalkEvent("TohelosNpc_TalkEvent");
function TohelosNpc_TalkEvent(_PlayerIndex,_Msg,_color,_range,_size)
        if _Msg==TohelosCMD then
                TohelosNpc_WindowTalked( tbl_LuaNpcIndex["TohelosNpc"], _PlayerIndex, 0, 0, 0)
                return 0
        end
        return 0
end

NL.RegItemString(nil, "TohelosNpc_ItemUse", "LUA_useTohelosQ");
function TohelosNpc_ItemUse(_PlayerIndex, _ToPlayerIndex, _Slot)
        TohelosNpc_WindowTalked( tbl_LuaNpcIndex["TohelosNpc"], _PlayerIndex, 0, 0, 0)
        return 1
end

function TohelosNpc_ChangeStat(_PlayerIndex, _Stat)
        local tKey = _PlayerIndex
        if _Stat==0 or (Char.GetData(_PlayerIndex, %对象_不遇敌开关%)==1) then
                Char.SetData(_PlayerIndex, %对象_不遇敌开关%, 0)
                Char.SetLoopEvent(nil, nil, _PlayerIndex, 0)
                TohelosPlayer[tKey] = 0
                NLG.SystemMessage(_PlayerIndex,"[" .. NpcName .. "] 使用状态已关闭.")
                --NLG.UpChar(_PlayerIndex)
                return 0
        elseif _Stat==1 or (Char.GetData(_PlayerIndex, %对象_不遇敌开关%)==0) then
                local TohelosItemNum = Char.ItemNum(_PlayerIndex, TohelosItemID)
                if TohelosItemNum<1 or Char.DelItem(_PlayerIndex, TohelosItemID, 1)<1 then
                        NLG.SystemMessage(_PlayerIndex,"[" .. NpcName .. "] 你的" .. TohelosItemName .. "数量不足,无法启动.")
                        return -1
                end
                Char.SetLoopEvent(nil, nil, _PlayerIndex, 0)
                Char.SetLoopEvent(nil, "TohelosNpc_Loop", _PlayerIndex, 1000)
                Char.SetData(_PlayerIndex, %对象_不遇敌开关%, 1)
                TohelosPlayer[tKey] = os.time()
                NLG.SystemMessage(_PlayerIndex,"[" .. NpcName .. "] 使用状态已开启,你全身散发出让给魔物讨厌的气味...  " .. os.date("%X"))
                --NLG.UpChar(_PlayerIndex)
                return 1
        end
       
end

function TohelosNpc_Loop(_PlayerIndex)
        if Char.GetData(_PlayerIndex, %对象_不遇敌开关%)==1 then
                local tKey = _PlayerIndex
                TohelosPlayer[tKey] = tonumber(TohelosPlayer[tKey]) or 0
                if (os.time()-TohelosPlayer[tKey])>(TohelosTime*60) then
                        local TohelosItemNum = Char.ItemNum(_PlayerIndex, TohelosItemID)
                        if TohelosItemNum<1 or Char.DelItem(_PlayerIndex, TohelosItemID, 1)<1 then
                                NLG.SystemMessage(_PlayerIndex, "[" .. NpcName .. "] 你的" .. TohelosItemName .. "已全部用完,系统自动关闭  " .. os.date("%X"))
                                TohelosNpc_ChangeStat(_PlayerIndex, 0)
                                return -1
                        end
                        local TohelosHour = math.floor((TohelosTime*TohelosItemNum)/60)
                        local TohelosMinute = math.floor(math.fmod(TohelosTime*TohelosItemNum, 60))
                        TohelosPlayer[tKey] = os.time()
                        NLG.SystemMessage(_PlayerIndex, "[" .. NpcName .. "] 你的" .. TohelosItemName .. "还剩" .. TohelosItemNum-1 .. "个(大约" .. TohelosHour .. "小时" .. TohelosMinute .. "分钟)  " .. os.date("%X"))
                end
        end
        return 1
end


回复

使用道具 举报

Archiver|魔力研究社

GMT+8, 2025-5-12 18:48 , Processed in 0.120121 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表