개인 자료란 (JE)

  서버 커뮤니티

Profile 서별 대표칭호 없음

West_Star f543101ea67e43d1a17dc0d45101dec3

Profile

이해도 초보자(스크립트 구성요소나 기본문법은 알아요) 
게임버전 (JE) 1.12.2 
게임버전 (BE) 관련없음 
스크립트 버전 2.5.3 
스크립트 애드온 없음(바닐라) 

options:
    SHOP.NAMETAG: "█"
    SHOP.STONE.SLOT: 0
    SHOP.DIRT.SLOT: 1
    SHOP.ANDESITE.SLOT: 2
    SHOP.STONE.PRICE: 49
    SHOP.DIRT.PRICE: 40
    SHOP.ANDESITE.PRICE: 51

on join:
    set {gui::%player%::shop} to chest inventory with 6 rows named {@MENU.SHOP.NAME}
    set {gui::%player%::shop::{@SHOP.STONE.SLOT}} to stone named getItemName( "STONE.TEST" , {@SHOP.STONE.PRICE} )
    set {gui::%player%::shop::{@SHOP.DIRT.SLOT}} to dirt named getItemName( "DIRT.TEST" , {@SHOP.DIRT.PRICE} )
    set {gui::%player%::shop::{@SHOP.ANDESITE.SLOT}} to andesite named getItemName( "ANDESITE.TEST" , {@SHOP.ANDESITE.PRICE} )
    updateGui( player , "shop" )

command /open.gui [<text="menu">]:
    trigger:
        updateGui( player , arg-1 )
        open getGui( player , arg-1 ) to player
        
command /update.gui [<text="menu">]:
    trigger:
        updateGui( player , arg-1 )

function getGui(p:player, type:text) :: inventory:
    # [Assumption] {_p}: gui를 get할 플레이어, {_type}: Gui의 타입
    # [Guarantees] {_p}의 {_type}에 해당하는 inventory를 return한다.    
    updateGui( {_p} , {_type} )
    set {_gui} to {gui::%{_p}%::%{_type}%}
    return {_gui}
    
function updateGui(p:player, type:text):
    # [Assumption] {_p}: gui를 create할 플레이어, {_type}: Gui의 타입
    # [Guarantees] {_p}의 {_type}에 해당하는 gui를 update한다.    
    loop {gui::%{_p}%::%{_type}%::*}:
        set {_slot} to loop-index parsed as integer
        set slot {_slot} of {gui::%{_p}%::%{_type}%} to loop-value
    
function openGui(p:player, type:text):
    # [Assumption] {_p}: gui를 open할 플레이어, {_type}: Gui의 타입
    # [Guarantees] {_p}의 현재 inventory를 닫고, 새로운 Gui를 열어준다.
    close inventory of {_p}
    updateGui( {_p} , {_type} )
    open getGui( {_p} , {_type} ) to {_p}
    
function getItemName(origin:text, price:integer) :: text:
    # [Assumption] {_origin}: 원래 이름
    # [Guarantees] {_origin}의 앞에 {@SHOP.NAMETAG}를 붙여 return한다.
    set {_nametag} to {@SHOP.NAMETAG}
    return "<cyan><bold>%{_nametag}% %{_origin}%(<light cyan><bold>%{_price}%<cyan><bold>원)"
    
function getPriceFromItemName(name:text) :: integer:
    # [Assumption] {_name}: 아이템 이름(getItemName으로 구현되어 있어야 함)
    # [Guarantees] {_name}으로부터 가격을 출력함 ex: 돌(500원) -> 500
    set {_name::*} to split {_name} at "<light cyan><bold>"
    set {_int::*} to split {_name::2} at "<cyan><bold>"
    set {_price} to {_int::1} parsed as integer
    return {_price}

on inventory click:
    name of clicked inventory is {@MENU.SHOP.NAME}
    cancel event
    if click type is left mouse button:
    
        set {_item} to clicked slot
        set {_itemtype} to type of {_item} 
        
        if name of {_item} contains {@SHOP.NAMETAG}:
            set {_price} to getPriceFromItemName( name of {_item} )
            sellItem( player , {_itemtype} , 1 , {_price} )
            
    if click type is right mouse button:
        
        set {_item} to clicked slot
        set {_itemtype} to type of {_item}
        
        if name of {_item} contains {@SHOP.NAMETAG}:
            set {_price} to getPriceFromItemName( name of {_item} )
            set {_holding} to "%number of {_itemtype} in player's inventory%" parsed as integer
            sellItem( player , {_itemtype} , {_holding} , {_price} )


도움이 될지는 모르겠지만, 우선 코드를 첨부해봅니다.

GUI 상점을 스크립트로 구현하였는데, 돌(stone), 화강암(granite), 안산암(andesite) 등이 모두 stone block으로 취급되어 다음과 같은 상황이 발생합니다.

1. GUI에서 안산암(andesite)을 클릭하면, 안산암이 판매되는 것이 아니라 돌(stone)이 판매됨

2. 예를 들어 안산암(andesite)을 32개 갖고 있다고 가정하였을 때, GUI에서 안산암을 클릭하였을 때 안산암 32개만큼의 돈을 획득하지만, 정작 안산암은 판매(remove)되지 않음(즉 무한 판매가 가능함)

아마 stone이 아니라 log에 대해서도 이와 같은 현상이 발생할 것 같은데, 이 중복 문제를 어떻게 해결할 수 있을까요?

Warning
댓글이 없습니다.

새로운 댓글을 등록해 주세요!

뉴스 및 창작물
/files/thumbnails/576/775/003/262x150.crop.jpg?20240426232553

아티클

이달의 블록: 단단한 진흙

학교가기싫다

2024-04-26

0

/files/thumbnails/115/774/003/262x150.crop.jpg?20240428135129

업데이트

마인크래프트 1.20.5 정식 업데이트

학교가기싫다

2024-04-24

0

/files/thumbnails/762/770/003/262x150.crop.jpg?20240418073724

레드스톤

T.B.H (고민중독) | 노트블럭 버전 | NoteBlock Cover [한국어 영어 중국어 가사 추가]

노트블럭전문가

2024-04-18

0

/files/thumbnails/218/767/003/262x150.crop.jpg?20240412130213

레드스톤

우리의 꿈 - 원피스 오프닝

노트블럭전문가

2024-04-12

0

/files/thumbnails/505/766/003/262x150.crop.jpg?20240411122306

레드스톤

기동전사 건담 수성의 마녀 | 노트블럭 커버 1

노트블럭전문가

2024-04-11

1