개인 자료란 (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/268/789/003/262x150.crop.jpg?20240515192032

레드스톤

벌레먹은 돌 빠르게 제거하는 법

GlassesFilm

2024-05-15

0

/files/thumbnails/797/788/003/262x150.crop.jpg?20240515090924

건축

마인크래프트로 구현한 카르카손 보드게임

Warak

2024-05-15

1

/files/thumbnails/487/784/003/262x150.crop.jpg?20240508233607

모드

Windows Borderless 모드에서 악성코드 발견

학교가기싫다

2024-05-08

1

/files/thumbnails/384/778/003/262x150.crop.jpg?20240512002324

업데이트

마인크래프트 자바 에디션 스냅샷 24w18a

학교가기싫다

2024-05-06

0

/files/thumbnails/855/781/003/262x150.crop.jpg?20240505141129

레드스톤

레이저 클리너

GlassesFilm

2024-05-05

1