우리가 만든 체력바를 좀 더 응용해 봅시다
리소스팩을 다운로드해 주세요
모드 섭이나 퀄리티 있는 HUD를 보게 되면 체력바 가운데에 플레이어 머리가 나오는 모습을 알 수 있습니다
오늘은 이 플레이어 머리를 체력바에 등록하는 법을 알아봅시다
요 녀석을 이용하여 플레이어 머리를 보이게 할 겁니다
models > item > skull이라는 파일이 생겼을 텐데
이 파일을 이용해서 gui 부분에 위치값을 조절해 주시면 됩니다
translation z값을 수정할 때 앞쪽 이미지랑 뒤쪽 이미지를 잘 구분해서 수정해 주세요
현재 8번 슬롯에 머리 부분으로 들어갑니다
9번 : 체력바
이것도 슬롯 1칸을 차지하는 단점이 있습니다..
아이템 위치도 입맛대로 수정하시면 됩니다
이제 스크립트랑 연동하시면 됩니다
여기서 이 머리를 이용해서 HUD 등록하면 머리 스킨이 보일까?라는 의문이 들 텐데
이 부분을 스크립트로 보안하면 됩니다
버전은 지난 강좌와 동일합니다
function setbar(p: player):
set {_a} to iron hoe with nbt "{Unbreakable:1,HideFlags:6}"
set slot 8 of {_p} to {_a} named "&f"
wait 1 ticks
set slot 7 of {_p} to skull of {_p} named "&f" // 7번째 슬롯에 플레이어에 머리로 설정합니다
wait 1 ticks
set {_c} to gold hoe with nbt "{Unbreakable:1,HideFlags:6}"
set durability of {_c} to 1
set slot 9 of {_p} to {_c} named "&f"
function reloadhealthbar(p: player):
set durability of slot 8 of {_p} to 102-(({_p}'s health/{_p}'s max health)*100)
set {health::%{_p}%} to round down (({_p}'s health/{_p}'s max health)*100)
every 0.1 second:
loop all players:
set {_p} to loop-player
if {health::%{_p}%} is not round down (({_p}'s health/{_p}'s max health)*100):
reloadhealthbar(loop-player)
on inventory close:
setbar(player)
reloadhealthbar(player)
on inventory open:
set {_b} to iron hoe with nbt "{Unbreakable:1,HideFlags:6}"
set durability of {_b} to 1
set slot 8 of player to {_b} named "&f"
set {_a} to gold hoe with nbt "{Unbreakable:1,HideFlags:6}"
set durability of {_a} to 0
set slot 9 of player to {_a} named "&f"
set slot 7 of player to air // 머리가 상자를 가리는 현상을 방지하기 위해 추가했습니다
on tool change:
if name of player's tool is "&f":
if item type is iron hoe or gold hoe or skull of player: // 타입만 추가
cancel event
on inventory click:
if name of click item is "&f":
if item type is iron hoe or gold hoe or skull of player:
cancel event
on drop:
if name of player's tool is "&f":
if item type is iron hoe or gold hoe or skull of player:
cancel event
on death:
loop all items in player's inventory:
if name of loop-item is "&f":
if item type is iron hoe or gold hoe or skull of player:
remove loop-item from drops
머리 부분도 마찬가지로 E키를 눌렀을때 인벤토리를 가리는 현상이 있어서
인벤토리 모델 아이템을 적용한 상태에서 추가하셔야합니다!
현재 skinsrestorer 플러그인이 서버에 적용되지 않아서 알렉스 스킨으로 보이는데
skinsrestorer 플러그인이 적용되어 있다면
정상적으로 해당 플레이어에 머리 스킨으로 보일 겁니다
[ 적용 상태 ]
8번 슬롯 : 플레이어 머리 ( skull of player )
9번 슬롯 : 체력바 모델
이렇게 1.12.2에서 체력바를 적용하는 방법과 응용법에 대해 알아봤습니다
감사합니다