fork/m-overlay

git clone https://git.julia.blue/fork/m-overlay

blackops7799Added MiniMap panel for offscreen player display More work on PlayerPercent to make it show Nana's percentd16d89b

GUI
3.8 KiB140 linesraw
1local memory = require("memory.watcher")
2
3require("smash.enums")
4
5local util = require("smash.util")
6
7local melee = {}
8
9function melee.getTeamColor(id)
10	return TEAM_COLORS[id] or TEAM_COLORS[0x04]
11end
12
13function melee.getPlayer(id)
14	return memory.player[id]
15end
16
17function melee.getPortColor(port)
18	if not port then return TEAM_COLORS[4] end
19	local player = memory.player[port]
20	return memory.teams and TEAM_COLORS[player.select.team] or PLAYER_COLORS[port-1]
21end
22
23function melee.getPlayerColor(player)
24	if not player or not player.team then return TEAM_COLORS[4] end
25	return memory.teams and TEAM_COLORS[player.team] or PLAYER_COLORS[player.port]
26end
27
28function melee.getPlayerEntityColor(entity)
29	if not entity or not entity.team then return TEAM_COLORS[4] end
30	return memory.teams and TEAM_COLORS[entity.team] or PLAYER_COLORS[entity.port]
31end
32
33function melee.getPlayerCharacterName(player)
34	if not player then return "NULL" end
35	local entity = melee.getEntity(player)
36	return melee.getPlayerEntityCharacterName(entity)
37end
38
39function melee.getPlayerEntityCharacterName(entity)
40	if not entity then return "NULL" end
41	return util.getInternalCharacterName(entity.character)
42end
43
44function melee.getPlayerEntity(id)
45	return melee.getEntity(melee.getPlayer(id))
46end
47
48function melee.isPlayerTransformed(player)
49	return player.transformed == 256
50end
51
52function melee.getPlayerEntityAttacker(entity)
53	if entity.attacker < 0 or entity.attacker >= 6 then
54		return entity -- They killed themselves
55	end
56	local port = entity.attacker + 1
57	return melee.getEntity(melee.getPlayer(port)), port
58end
59
60function melee.getActiveEntityName(player)
61	local character = player.character
62	local transformed = player.transformed == 256
63	if (character == CHARACTER.ZELDA or character == CHARACTER.SHEIK) and transformed then
64		-- If the character started as zelda or shiek, and they transformed
65		-- return their partner entity (Which is the active entity)
66		-- A player can start as Sheik by holding A when loading in, so their character ID would be Shiek instead of Zelda
67		return "partner"
68	else
69		return "entity"
70	end
71end
72
73function melee.getEntity(player)
74	return player[melee.getActiveEntityName(player)]
75end
76
77-- action_state 0x0-0xA means the player is dead
78-- action_state 0xB = Sleep (Dead/Waiting to respawn)
79-- action_state 0xC = Respawning
80-- action_state 0xD = Waiting on respawn platform
81
82function melee.isEntityActive(entity)
83	return entity and entity.action_state and entity.action_state ~= 0xB
84end
85
86function melee.isEntityAlive(entity)
87	return entity and entity.action_state and entity.action_state > 0xB
88end
89
90function melee.isEntityRespawning(entity)
91	return entity and entity.action_state and entity.action_state >= 0xC and entity.action_state <= 0xD
92end
93
94function melee.isEntityOffCamera(entity)
95	if entity then
96		local offset = memory.stage.offset
97		local camera = memory.camera.limit
98		local x, y = entity.position.x - offset.x, entity.position.y - offset.y
99		if x <= camera.left or x >= camera.right or y <= camera.bottom or y >= camera.top then
100			return true
101		end
102	end
103	return false
104end
105
106function melee.setNametag(slot, string)
107	-- Size of slot = 0x1A4
108	-- Slot 1 = 0x0045D850
109	-- Slot 2 = 0x0045D9F4
110	memory.writeString(0x8045D850 + (0x1A4 * slot), string:sub(0,8))
111end
112
113function melee.getActivePlayers()
114	local active = {}
115
116	-- Add all active controller ports to a table..
117	for port, player in pairs(memory.player) do
118		if player.select.mode ~= PLAYER.DISABLED then
119			table.insert(active, port)
120		end
121	end
122
123	return active
124end
125
126function melee.getActiveTeams()
127	local teams = {}
128
129	-- Add all active teams to a table
130	for port, player in pairs(memory.player) do
131		local team = player.select.team
132		if player.select.mode ~= PLAYER.DISABLED and not table.hasValue(teams, team) then
133			table.insert(teams, team)
134		end
135	end
136
137	return teams
138end
139
140return melee