Mod scripting guide : Investment - Tiny-Metro/Poly-Metro GitHub Wiki
๊ฐ์
๋ณธ ๋ฌธ์๋ ํฌ์ ๋ฏธ์ ์ ๋ชจ๋ฉ์ ์ฌ์ฉ๋๋ ์คํฌ๋ฆฝํธ ํ์ผ์ ๊ตฌ์กฐ๋ฅผ ์ค๋ช ํฉ๋๋ค.
์ฃผ์ ์ฌํญ
ํด๋น ํญ๋ชฉ์ Mod scripting guide : Event์ ์ค๋ณต๋๋ ๋ด์ฉ์ ๋ด๊ณ ์์ต๋๋ค. ์คํฌ๋ฆฝํธ ์์ฑ ์ ์ฃผ์ํด์ผ ํ ์ฌํญ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- 0000๋ฒ ์คํฌ๋ฆฝํธ๋ฅผ ํตํด ํ์ธ ๊ฐ๋ฅํ ํ ํ๋ฆฟ์ด ์ง์ผ์ ธ์ผ ํฉ๋๋ค.
- Lua์์ ๊ธฐ๋ณธ์ ์ผ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ ๋ผ์ด๋ธ๋ฌ๋ฆฌ(math, string ๋ฑ)๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.
- API๋ ์ ์ ํ ์ฉ๋์ ๋ง๊ฒ ์ฌ์ฉ๋์ด์ผ ํฉ๋๋ค. (ex. Investment์์ Event์ API๋ฅผ ์ฌ์ฉํ ์ ์์ต๋๋ค.)
- ๊ฐ์ ์นดํ
๊ณ ๋ฆฌ ๋ด ์คํฌ๋ฆฝํธ ํ์ผ์ ์ ์ญ๋ณ์๋ ๋ชจ๋ ๊ณต์ ๋ฉ๋๋ค. ๋ฐ๋ผ์, ๋ณ์ ์ ์ธ์ ๋ค์๊ณผ ๊ฐ์ Convention์ ๊ถ์ฅํฉ๋๋ค.
- {VariableName}_{ScriptId}
- ex. Investment.1234.luaํ์ผ์ n์ด๋ผ๋ ๋ณ์๋ฅผ ์ฌ์ฉํ ๊ฒฝ์ฐ, n_1234๋ผ๋ ์ด๋ฆ์ ๊ถ์ฅํฉ๋๋ค.
์ฝ๋ ๋ณธ๋ฌธ (Investment.0000.lua)
-- Investment condition
function InvestmentData()
Data = {}
Data.message = 'Mission require text'
Data.time_require = 0
Data.award = 'Reward text'
return Data
end
-- Call when investment start
-- Used save info when start
function Start()
end
-- Investment appear condition
function Appearance()
return true
end
-- Investment success condition
function Process()
return continue
end
-- Investment award
function Award()
end
InvestmentDataStruct = {}
InvestmentDataStruct.InvestmentData = InvestmentData
InvestmentDataStruct.Start = Start
InvestmentDataStruct.Appearance = Appearance
InvestmentDataStruct.Process = Process
InvestmentDataStruct.Award = Award
return InvestmentDataStruct
์ ์คํฌ๋ฆฝํธ๋ Investment.0000.luaํ์ผ์ ์ฝ๋์ ๋๋ค. ์ดํ ์ฐธ์กฐ์ ์ฉ์ดํ๋๋ก, ์ํ์ ๋ชฉ์ ์ผ๋ก ๋ฐฐ์นํ์ต๋๋ค. ํฌ์ ๋ฏธ์ ์ ์ ์คํฌ๋ฆฝํธ๋ฅผ ์์ , ์ถ๊ฐํ๋ ๊ฒ์ผ๋ก ๊ตฌํ๋ฉ๋๋ค. ๊ฐ ์คํฌ๋ฆฝํธ๋ฅผ ์กฐ๊ธ ๋ ์๊ฒ ๋๋์ด ์ดํด๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
InvestmentData
์คํฌ๋ฆฝํธ ์ค InvestmentData ํญ๋ชฉ์ ๋๋ค.
-- Investment condition
function InvestmentData()
Data = {}
Data.message = 'Mission require text'
Data.time_require = 0
Data.award = 'Reward text'
return Data
end
Data์ ๊ฐ ์์ฑ์ ๋ค์๊ณผ ๊ฐ์ ์ญํ ์ ์ํํฉ๋๋ค.
- Data.message
- ํฌ์ ๋ฏธ์ ์ ๋ด์ฉ์ ๋ํ๋ ๋๋ค.
- Data.time_require
- ํฌ์ ๋ฏธ์ ์ ์ํ ๊ธฐํ์ ๋ํ๋ ๋๋ค. ๋จ์๋ ์ผ(Day)์ ๋๋ค.
- Data.award
- ํฌ์ ๋ฏธ์ ์ ๋ณด์์ ๋ํ๋ ๋๋ค.
์ ์์ฑ๋ค๊ณผ ํ ์คํธ ์ค time_require๋ฅผ ์ ์ธํ๋ฉด UI์ ๋ ธ์ถ๋๋ ์ค๋ช ์ด๋ฉฐ, ์ค์ ๊ธฐ๋ฅ๊ณผ๋ ๋ฌด๊ดํฉ๋๋ค. ์ ์ค๋ช ๋ค์ ๋ง์ถฐ ์๋ ํจ์๋ค์ ๊ตฌํํด์ผ ํฌ์ ๋ฏธ์ ์ ์ถ๊ฐ๊ฐ ์๋ฃ๋ฉ๋๋ค.
Start
์คํฌ๋ฆฝํธ ์ค Start ํญ๋ชฉ์ ๋๋ค.
-- Call when investment start
function Start()
end
ํฌ์ ๋ฏธ์ ์ ์์ ์ ํธ์ถ๋๋ ํจ์์ ๋๋ค. ์์๊ณผ ํจ๊ป ์คํ๋์ด์ผ ํ๋ ํจ์, ํธ์ถ๋์ด์ผ ํ๋ API๊ฐ ์์ ๊ฒฝ์ฐ ์ถ๊ฐํ ์ ์์ต๋๋ค.
Appearance
์คํฌ๋ฆฝํธ ์ค Appearance ํญ๋ชฉ์ ๋๋ค.
-- Investment appear condition
function Appearance()
return true
end
ํฌ์ ๋ฏธ์ ์ ๋ ธ์ถ ์กฐ๊ฑด์ ์ง์ ํ๋ ํจ์์ ๋๋ค. return์ผ๋ก ๋ฐํํ ์ ์๋ ๊ฐ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- true
- ํฌ์ ๋ฏธ์ ์ด ๋ ธ์ถ๋ฉ๋๋ค.
- false
- ํฌ์ ๋ฏธ์ ์ด ๋ ธ์ถ๋์ง ์์ต๋๋ค. (๋ํ๋์ง ์์ต๋๋ค)
Process
์คํฌ๋ฆฝํธ ์ค Process ํญ๋ชฉ์ ๋๋ค.
-- Investment success condition
function Process()
return continue
end
ํฌ์ ๋ฏธ์ ์ ์ํ ๊ณผ์ ์ ๊ฒ์ฌํ๋ ํจ์์ ๋๋ค. ํฌ์ ๋ฏธ์ ์ ์์ ์ดํ (Startํจ์ ํธ์ถ ์ดํ) ์ง์์ ์ผ๋ก(๋งค ํ๋ ์๋ง๋ค) ํธ์ถ๋ฉ๋๋ค. return์ผ๋ก ๋ฐํํ ์ ์๋ ๊ฐ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
- continue
- ํฌ์ ๋ฏธ์ ์ ์งํ์ ์ด์์ด ์์ต๋๋ค.
- success
- ํฌ์ ๋ฏธ์ ์ด ์ฑ๊ณตํฉ๋๋ค. ์ดํ Awardํจ์๊ฐ ํธ์ถ๋ฉ๋๋ค.
- fail
- ํฌ์ ๋ฏธ์ ์ด ์คํจํ์ต๋๋ค. ํฌ์ ๋ฏธ์ ์ด ์ข ๋ฃ๋ฉ๋๋ค.
Award
์คํฌ๋ฆฝํธ ์ค Award ํญ๋ชฉ์ ๋๋ค.
-- Investment award
function Award()
end
ํฌ์ ๋ฏธ์ ์ฑ๊ณต ์ ํธ์ถ๋๋ ํจ์์ ๋๋ค. ํฌ์ ๋ฏธ์ ์ ๋ณด์์ ์ง๊ธํ๋ ๊ธฐ๋ฅ์ ๊ตฌํํ ์ ์์ต๋๋ค.
InvestmentDataStruct
InvestmentDataStruct= {}
InvestmentDataStruct.InvestmentData = InvestmentData
InvestmentDataStruct.Start = Start
InvestmentDataStruct.Appearance = Appearance
InvestmentDataStruct.Process = Process
InvestmentDataStruct.Award = Award
return InvestmentDataStruct
์ฝ๋์ ๋ง์ง๋ง์ ์๋ InvestmentDataStruct๋ฐ return๊ตฌ๋ฌธ์ ๋๋ค. ์์ง์์ ์คํฌ๋ฆฝํธ๋ฅผ ์ฝ์ด๋ค์ด๊ธฐ ์ํด ๋ฐ๋์ ํ์ํ ๊ตฌ๋ฌธ์ผ๋ก, ์ถ๊ฐ์ ์ธ ํธ์ง์ ๋ถํ์ํฉ๋๋ค.
์ํ ์ฝ๋
๋ค์ ๋ฌธ์๋ Lua์คํฌ๋ฆฝํ ์ ๊ด๋ จ๋ ์ํ ์ฝ๋๋ฅผ ์ฒจ๋ถํ๊ณ ์์ต๋๋ค.