魔力宝贝

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

[GP] Tohelos.lua;--时限驱魔香--请打开文件自行修改

[复制链接]
发表于 前天 02:53 | 显示全部楼层 |阅读模式
local NpcName = "计时驱魔香"                --Npc名称(同时也是脚本名称)
local NpcMapPos = {0, 777, 16, 18}                        --Npc地图坐标
local NpcImage = 101022                                                --Npc图档101022
local NpcDir = 6                                                        --Npc方向(0为左上,顺时针转)

------------------------------------------------------------------------------
------------------------------------------------------------------------------
--                 【【【脚本系统设置】】】(非专业人事请勿修改)
------------------------------------------------------------------------------
--驱魔香物品设置
local TohelosItemID = 70122
local TohelosItemName = "驱魔香[10分钟]"
local TohelosTime = 10

local TohelosItemIDB = 70121
local TohelosItemNameB = "驱魔香[5分钟]"
local TohelosTimeB = 5

local TohelosItemIDC = 70120
local TohelosItemNameC = "驱魔香[2分钟]"
local TohelosTimeC = 2

TohelosNpc = 0;
local TohelosPlayer = {}
--ID填写处理完毕后请把物品的特性改成LUA_useTohelosQ
------------------------------------------------------------------------------

function TohelosNpc_Func(index)
        return true;
end
Global_Reg.RegInit("TohelosNpc_Init");

function TohelosNpc_Init()
         TohelosNpc = NL.CreateNpc(nil, "TohelosNpc_Func");
        Char.SetData( TohelosNpc, %对象_形象%, NpcImage);
        Char.SetData( TohelosNpc, %对象_原形%, NpcImage);
        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)
        LuaNpcIndex["TohelosNpc"] = TohelosNpc
        InstallNpc("TohelosNpc",TohelosNpc);
        Char.SetWindowTalkedEvent(nil, "TohelosNpc_WindowTalked", TohelosNpc)
        return true
end


Global_Reg.RegLogoutEvent("TohelosNpc_LogoutEvent");
function TohelosNpc_LogoutEvent(_PlayerIndex)
        TohelosNpc_ChangeStat(_PlayerIndex, 0)
        return 1
end

function GQGet_Item_pos(Char_Index,Item_Index)
        local number,pos=-1;
        for number=8,27 do
                if(Char.GetItemIndex(Char_Index,number) == Item_Index)then
                        pos = number;
                        break;                       
                end

        end

        return pos;
end

function DGADDitemMy(CharIndex,ItemIndex)
        local Pos = GQGet_Item_pos(CharIndex,ItemIndex);
        local ClickItemType = tonumber(Item.GetData(ItemIndex,%道具_双击效果%));
        if(ClickItemType== 1006)then
                TohelosNpc_ItemUse(CharIndex,0,Pos);
                return 1;
        end
        return 0;
end

function TohelosNpc_ItemUse(_PlayerIndex, _ToPlayerIndex, _Slot)
        local _itemindex = Char.GetItemIndex(_PlayerIndex,_Slot);
        local _itemID = Item.GetData(_itemindex,%道具_ID%);
        if (_itemID == TohelosItemID) then
        TohelosNpc_WindowTalked(LuaNpcIndex["TohelosNpc"], _PlayerIndex, 10, 0, 0)
        end

        if (_itemID == TohelosItemIDB) then
        TohelosNpc_WindowTalked(LuaNpcIndex["TohelosNpc"], _PlayerIndex, 20, 0, 0)
        end

        if (_itemID == TohelosItemIDC) then
        TohelosNpc_WindowTalked(LuaNpcIndex["TohelosNpc"], _PlayerIndex, 30, 0, 0)
        end
        return 1
end


function TohelosNpc_WindowTalked( _MeIndex, _PlayerIndex, _Seqno, _Select, _Data)
        --取消按钮
        if _Select==2 or _Seqno==99999 then
                return
        end

        if _Seqno==10 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, %对象_不遇敌开关%)==false then
                        TohelosStat = "关闭"
                end
               
                --Show WinTalk
                local TalkMsg = "        ◆" .. NpcName .. "◆" ..
                                                "\n" ..
                                                "\n[道具名称]:" .. TohelosItemName ..
                                                "\n[消耗方式]:" .. TohelosTime .. "分钟/个(先扣后计时)" ..
                                                "\n[剩余数量]:" .. TohelosItemNum .. "个(约使用" .. TohelosHour .. "小" .. TohelosMinute .. "分)" ..
                                                "\n[使用状态]:" .. TohelosStat .. "(点[确定]按钮修改状态)" ..
                                                "\n" ..
                                                "\n操作提示:" ..
                                                "\n点[确定]控制驱魔使用状态开关,点[取消]关闭窗口"

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

        if _Seqno==20 then
                --Get Stat
                local TohelosItemNum = Char.ItemNum(_PlayerIndex, TohelosItemIDB)
                local TohelosHour = math.floor((TohelosTimeB*TohelosItemNum)/60)
                local TohelosMinute = math.floor(math.fmod(TohelosTimeB*TohelosItemNum, 60))
                local TohelosStat = "开启"
                if Char.GetData(_PlayerIndex, %对象_不遇敌开关%)==false then
                        TohelosStat = "关闭"
                end
               
                --Show WinTalk
                local TalkMsg = "        ◆" .. NpcName .. "◆" ..
                                                "\n" ..
                                                "\n[道具名称]:" .. TohelosItemNameB ..
                                                "\n[消耗方式]:" .. TohelosTimeB .. "分钟/个(先扣后计时)" ..
                                                "\n[剩余数量]:" .. TohelosItemNum .. "个(约使用" .. TohelosHour .. "小" .. TohelosMinute .. "分)" ..
                                                "\n[使用状态]:" .. TohelosStat .. "(点[确定]按钮修改状态)" ..
                                                "\n" ..
                                                "\n操作提示:" ..
                                                "\n点[确定]控制驱魔使用状态开关,点[取消]关闭窗口"

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

        if _Seqno==30 then
                --Get Stat
                local TohelosItemNum = Char.ItemNum(_PlayerIndex, TohelosItemIDC)
                local TohelosHour = math.floor((TohelosTimeC*TohelosItemNum)/60)
                local TohelosMinute = math.floor(math.fmod(TohelosTimeC*TohelosItemNum, 60))
                local TohelosStat = "开启"
                if Char.GetData(_PlayerIndex, %对象_不遇敌开关%) == false then
                        TohelosStat = "关闭"
                end
               
               
                --Show WinTalk
                local TalkMsg = "        ◆" .. NpcName .. "◆" ..
                                                "\n" ..
                                                "\n[道具名称]:" .. TohelosItemNameC ..
                                                "\n[消耗方式]:" .. TohelosTimeC .. "分钟/个(先扣后计时)" ..
                                                "\n[剩余数量]:" .. TohelosItemNum .. "个(约使用" .. TohelosHour .. "小" .. TohelosMinute .. "分)" ..
                                                "\n[使用状态]:" .. TohelosStat .. "(点[确定]按钮修改状态)" ..
                                                "\n" ..
                                                "\n操作提示:" ..
                                                "\n点[确定]控制驱魔使用状态开关,点[取消]关闭窗口"

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

        --【确定】
        if _Seqno==1 and _Select==1 then
                TohelosNpc_ChangeStat(_PlayerIndex)
                return 1
        end

        if _Seqno==2 and _Select==1 then
                TohelosNpc_ChangeStatB(_PlayerIndex)
                return 1
        end

        if _Seqno==3 and _Select==1 then
                TohelosNpc_ChangeStatC(_PlayerIndex)
                return 1
        end
end

function TohelosNpc_ChangeStat(_PlayerIndex, _Stat)
        local tKey = _PlayerIndex
        if _Stat==0 or (Char.GetData(_PlayerIndex, %对象_不遇敌开关%)==true) then
                Char.SetData(_PlayerIndex, %对象_不遇敌开关%, false)
                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, %对象_不遇敌开关%)==false) then
                local TohelosItemNum = Char.ItemNum(_PlayerIndex, TohelosItemID)
                if TohelosItemNum<1 or NLG.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, %对象_不遇敌开关%, true)
                TohelosPlayer[tKey] = os.time()
                NLG.SystemMessage(_PlayerIndex,"[" .. NpcName .. "]:使用状态已开启,你全身散发出让给魔物讨厌的气味...  ")
                --NLG.UpChar(_PlayerIndex)
                return 1
        end
       
end

function TohelosNpc_Loop(_PlayerIndex)
        if Char.GetData(_PlayerIndex, %对象_不遇敌开关%)==true 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 NLG.DelItem(_PlayerIndex, TohelosItemID, 1)<1 then
                                NLG.SystemMessage(_PlayerIndex, "[" .. NpcName .. "]:你的" .. TohelosItemName .. "已全部用完,系统自动关闭!")
                                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 .. "分钟)" )
                end
        end
        return 1
end

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

function TohelosNpc_LoopB(_PlayerIndex)
        if Char.GetData(_PlayerIndex, %对象_不遇敌开关%)==true then
                local tKey = _PlayerIndex
                TohelosPlayer[tKey] = tonumber(TohelosPlayer[tKey]) or 0
                if (os.time()-TohelosPlayer[tKey])>(TohelosTimeB*60) then
                        local TohelosItemNum = Char.ItemNum(_PlayerIndex, TohelosItemIDB)
                        if TohelosItemNum<1 or NLG.DelItem(_PlayerIndex, TohelosItemIDB, 1)<1 then
                                NLG.SystemMessage(_PlayerIndex, "[" .. NpcName .. "]:你的" .. TohelosItemNameB .. "已全部用完,系统自动关闭!")
                                TohelosNpc_ChangeStatB(_PlayerIndex, 0)
                                return -1
                        end
                        local TohelosHour = math.floor((TohelosTimeB*TohelosItemNum)/60)
                        local TohelosMinute = math.floor(math.fmod(TohelosTimeB*TohelosItemNum, 60))
                        TohelosPlayer[tKey] = os.time()
                        NLG.SystemMessage(_PlayerIndex, "[" .. NpcName .. "]:你的" .. TohelosItemNameB .. "还剩" .. TohelosItemNum-1 .. "个(大约还可以持续" .. TohelosHour .. "小时" .. TohelosMinute .. "分钟)" )
                end
        end
        return 1
end

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

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

回复

使用道具 举报

Archiver|魔力研究社

GMT+8, 2025-5-12 18:18 , Processed in 0.119025 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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