- UID
- 31231
- 阅读权限
- 40
- 回帖
- 320
- 喵币
- 0
- 有爱
- 101
- DKP
- 1827
- 金币
- 872
- 在线时间
- 779 小时
- 注册时间
- 2022-2-5
- 最后登录
- 2026-2-14
声望: 1343   虚弱: 0

Lv.4(锻造者)

|

楼主 |
发表于 2024-7-22 12:44:33
|
显示全部楼层
一共2个方法,一个纯客户端的,一个带服务器的,可以传送需要的数据,第一个方法不怎么用的,除非,不和服务器要数据
方法1.客户端调用:参考这个
- -- -- function Gossip_click(self, event, ...) 这个是客户端调用,现在修改城服务端调用
-- -- -- if event == "GOSSIP_SHOW" and NpcName==UnitName("mouseover") then
-- -- -- print(1)
-- -- -- from()
-- -- -- CloseGossip()
-- -- -- elseif event == "QUEST_GREETING" then
-- -- -- print("Quest greeting window opened")
-- -- -- elseif event == "QUEST_DETAIL" then
-- -- -- print("Quest detail window opened")
-- -- -- elseif event == "QUEST_PROGRESS" then
-- -- -- print("Quest progress window opened")
-- -- -- elseif event == "QUEST_COMPLETE" then
-- -- -- print("Quest complete window opened")
-- -- -- end
-- -- -- end
-- -- -- -- 监听玩家点击NPC事件
-- -- -- local eventFrame = CreateFrame("Frame")
-- -- -- eventFrame:RegisterEvent("GOSSIP_SHOW")
-- -- -- eventFrame:SetScript("OnMouseDown",Gossip_click)
服务器调用2.: 先写个服务器事件来检测用户点击了NPC,然后给客户端发送指令
local objectEntry=192178
function OnobjectGossipHello(event, player, object)
local SendData={
playerName=player:GetName(),
objectEntry=object:GetEntry()
}
player:SendAddonMessage("mianmenus", SendData.playerName .. "," .. SendData.objectEntry , 0x00, player)
return false
end
然后在写个客户端接受服务器的指令
local function OnEvent(self, event, ...)
if event == "PLAYER_ENTERING_WORLD" then
-- 请求服务器获取玩家数据
SendChatMessage(".mydata", "SAY")
elseif event == "CUSTOM_PACKET_RECEIVED" then
--处理登入触发的事件
SeceiverSevertInfo(...)
elseif event=="CHAT_MSG_ADDON" then
SeceiverSevertInfo(...) --指令有很多 单独写了个函数来判断哪些指令
end
end
function SeceiverSevertInfo(...)
local prefix, msg, channel, sender = ... --获取指令,和服务器传送过来的数据
local data = {strsplit(",", msg)}
if prefix=="mianmenus" then --判断指令,要打开菜单
mianmen=newmianmenuModel() --获取我们的菜单文件的接口
mianmen.showform() --调用模板
--mianmen.mianmenuinfo={{}} 修改参数,我写的是死的,你们自己修改就行,具体数据 msg传送过来
end
end
frame:RegisterEvent("CHAT_MSG_ADDON") --CHAT_MSG_TEXT_EMOTE
frame:RegisterEvent("CHAT_MSG_TEXT_EMOTE")
|
|