fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
d16d89b
gui
1local memory =require ( "memory.watcher" ) 2 3require ( "smash.enums" ) 4 5local util =require ( "smash.util" ) 6 7local melee ={} 8 9function melee . getTeamColor ( id ) 10return TEAM_COLORS [ id ] or TEAM_COLORS [ 0x04 ] 11end 12 13function melee . getPlayer ( id ) 14return memory . player [ id ] 15end 16 17function melee . getPortColor ( port ) 18if not port then return TEAM_COLORS [ 4 ] end 19local player =memory . player [ port ] 20return memory . teams and TEAM_COLORS [ player . select . team ] or PLAYER_COLORS [ port - 1 ] 21end 22 23function melee . getPlayerColor ( player ) 24if not player or not player . team then return TEAM_COLORS [ 4 ] end 25return memory . teams and TEAM_COLORS [ player . team ] or PLAYER_COLORS [ player . port ] 26end 27 28function melee . getPlayerEntityColor ( entity ) 29if not entity or not entity . team then return TEAM_COLORS [ 4 ] end 30return memory . teams and TEAM_COLORS [ entity . team ] or PLAYER_COLORS [ entity . port ] 31end 32 33function melee . getPlayerCharacterName ( player ) 34if not player then return "NULL" end 35local entity =melee . getEntity ( player ) 36return melee . getPlayerEntityCharacterName ( entity ) 37end 38 39function melee . getPlayerEntityCharacterName ( entity ) 40if not entity then return "NULL" end 41return util . getInternalCharacterName ( entity . character ) 42end 43 44function melee . getPlayerEntity ( id ) 45return melee . getEntity ( melee . getPlayer ( id )) 46end 47 48function melee . isPlayerTransformed ( player ) 49return player . transformed == 256 50end 51 52function melee . getPlayerEntityAttacker ( entity ) 53if entity . attacker < 0 or entity . attacker >= 6 then 54return entity -- They killed themselves 55end 56local port =entity . attacker + 1 57return melee . getEntity ( melee . getPlayer ( port )), port 58end 59 60function melee . getActiveEntityName ( player ) 61local character =player . character 62local transformed =player . transformed == 256 63if ( 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 67return "partner" 68else 69return "entity" 70end 71end 72 73function melee . getEntity ( player ) 74return 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 ) 83return entity and entity . action_state and entity . action_state ~= 0xB 84end 85 86function melee . isEntityAlive ( entity ) 87return entity and entity . action_state and entity . action_state > 0xB 88end 89 90function melee . isEntityRespawning ( entity ) 91return entity and entity . action_state and entity . action_state >= 0xC and entity . action_state <= 0xD 92end 93 94function melee . isEntityOffCamera ( entity ) 95if entity then 96local offset =memory . stage . offset 97local camera =memory . camera . limit 98local x , y =entity . position . x - offset . x , entity . position . y - offset . y 99if x <= camera . left or x >= camera . right or y <= camera . bottom or y >= camera . top then 100return true 101end 102end 103return false 104end 105 106function melee . setNametag ( slot , string ) 107-- Size of slot = 0x1A4 108-- Slot 1 = 0x0045D850 109-- Slot 2 = 0x0045D9F4 110memory . writeString ( 0x8045D850 + ( 0x1A4 * slot ), string : sub ( 0 , 8 )) 111end 112 113function melee . getActivePlayers () 114local active ={} 115 116-- Add all active controller ports to a table.. 117for port , player in pairs ( memory . player ) do 118if player . select . mode ~= PLAYER . DISABLED then 119table . insert ( active , port ) 120end 121end 122 123return active 124end 125 126function melee . getActiveTeams () 127local teams ={} 128 129-- Add all active teams to a table 130for port , player in pairs ( memory . player ) do 131local team =player . select . team 132if player . select . mode ~= PLAYER . DISABLED and not table . hasValue ( teams , team ) then 133table . insert ( teams , team ) 134end 135end 136 137return teams 138end 139 140return melee