1
2local titleFont = "verdana-11px-rounded"
3local OPCODE = 134
4function init()
5 connect(Creature, {
6 onAppear = requestData,
7
8 })
9 ProtocolGame.registerExtendedOpcode(OPCODE, handleData)
10end
11
12function terminate()
13
14disconnect(Creature, {
15 onAppear = requestData,
16 })
17 ProtocolGame.unregisterExtendedOpcode(OPCODE, handleData)
18end
19
20
21function requestData(creature)
22if creature:isPlayer() then
23 local tbl = {
24 creature = creature:getId()
25 }
26 local protocolGame = g_game.getProtocolGame()
27 if protocolGame then
28 protocolGame.sendExtendedOpcode(protocolGame,OPCODE, json.encode(tbl))
29 end
30end
31end
32
33function handleData(protocol, code, buffer)
34 local json_status, json_data = pcall(function ()
35 return json.decode(buffer)
36 end)
37
38 if not json_status then
39 g_logger.error("JSON error: " .. json_data)
40 return false
41 end
42
43 local data = json_data
44 local response = json_data.response
45 if data ~= nil then
46 if response == "SetGuildNick" then
47 updateTitle(data.creatureId, data.guildNick)
48 elseif response == "SetGuildName" then
49 updateTitle(data.creatureId, data.guildName)
50 end
51end
52
53return
54end
55
56function updateTitle(creatureId, guildName)
57 local target = g_map.getCreatureById(creatureId)
58 if target then
59 target:setTitle(guildName, titleFont,"#fdf3cd")
60 end
61 return
62end
63