1local LoginEvent = CreatureEvent("InspectLogin")
2
3function LoginEvent.onLogin(player)
4 player:registerEvent("InspectExtended")
5 return true
6end
7
8local ExtendedEvent = CreatureEvent("InspectExtended")
9
10function ExtendedEvent.onExtendedOpcode(player, opcode, buffer)
11 if opcode == OPCODE_TESTPROFILE then
12 local status, json_data =
13 pcall(
14 function()
15 return json.decode(buffer)
16 end
17 )
18 if not status then
19 return
20 end
21
22 local action = json_data.action
23 local data = json_data.data
24
25 if action == "inspect" then
26 inspectPlayer(player, data)
27 print("Inspect")
28 end
29 end
30end
31
32function inspectPlayer(player, targetName)
33 local exhaustionTime = player:getExhaustion(PlayerStorageKeys.inspectProfileOpcodeExhaustion)
34
35 if exhaustionTime > 0 then
36 local message = "[pt-BR] Espere " .. exhaustionTime .. " segundos antes de fazer isso novamente.\n\n" ..
37 "[en-US] Please wait " .. exhaustionTime .. " seconds before doing this again."
38
39 player:popupFYI(message)
40 return false
41 end
42
43 local target = Player(targetName)
44 if target then
45 local stats = {}
46 stats.name = target:getName()
47 local guild = target:getGuild()
48 stats.guild = guild and guild:getName() or "None"
49 stats.vocation = target:getVocation():getName()
50 stats.health = target:getHealth()
51 stats.maxHealth = target:getMaxHealth()
52 stats.mana = target:getMana()
53 stats.maxMana = target:getMaxMana()
54 stats.level = target:getLevel()
55 stats.exp = target:getExperience()
56 stats.skills = {}
57 for i = SKILL_FIST, SKILL_FISHING do
58 local totalSkill = target:getEffectiveSkillLevel(i)
59 local baseSkill = target:getSkillLevel(i)
60 local skillPercent = target:getSkillPercent(i)
61 local bonus = totalSkill - baseSkill
62 stats.skills[i + 1] = {
63 total = totalSkill,
64 bonus = bonus,
65-- percent = skillPercent
66 }
67 end
68 local baseMagic = target:getBaseMagicLevel()
69 local totalMagic = target:getMagicLevel()
70 stats.skills[#stats.skills + 1] = {
71 total = totalMagic,
72 bonus = totalMagic - baseMagic,
73-- percent = target:getMagicLevelPercent()
74 }
75 stats.stats = {}
76
77 player:sendExtendedOpcode(OPCODE_TESTPROFILE, json.encode({action = "stats", data = stats}))
78 player:setExhaustion(PlayerStorageKeys.inspectProfileOpcodeExhaustion, 4)
79
80 for slot = CONST_SLOT_HEAD, CONST_SLOT_RING do
81 local item = target:getSlotItem(slot)
82 if item then
83 player:sendExtendedOpcode(OPCODE_TESTPROFILE, json.encode({action = "item", data = {slot = slot, item = item:getType():getClientId()}}))
84 else
85 player:sendExtendedOpcode(OPCODE_TESTPROFILE, json.encode({action = "item", data = {slot = slot}}))
86 end
87 end
88
89 end
90end
91
92LoginEvent:type("login")
93LoginEvent:register()
94ExtendedEvent:type("extendedopcode")
95ExtendedEvent:register()