Skip to content

Instantly share code, notes, and snippets.

@keewon
Created November 20, 2014 15:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save keewon/588fb09d9df9ca6b17db to your computer and use it in GitHub Desktop.
Save keewon/588fb09d9df9ca6b17db to your computer and use it in GitHub Desktop.
AION 하우징 스크립트 - 경마 게임
-- 아이온 하우징 스크립트 경마 게임
-- 최종수정일: 2011-12-17
-- 자유롭게 수정 배포 가능함
-- 한번에 이동할 거리
STEP = 0.18;
-- 최대 20회 움직임
RUN = 20;
-- 결승점 지정
GOAL = 45;
-- 말 개수, 최대 9개까지만
COUNT = 5;
-- 시상식 횟수
RESULT = RUN+9;
-- 이동한 거리를 저장할 변수
value = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-- 사용자 선택을 저장할 변수
choice = 0;
-- state
ST_BET = 0;
ST_READY = 1;
state = ST_BET;
function OnInit()
-- 말 몇 마리 쓸지 지정
H.SetOutletCount(COUNT);
-- 메뉴 등록
H.RegisterMenu("경마 ", 7);
end
-- 메뉴 등록
function OnMenu(menuNum)
if (menuNum == 7) then
Main("경마");
end
end
-- 사용자가 채팅을 하면 호출됩니다.
function OnUserSay(str)
Main(str);
end
function Main(str)
-- "경마" 라고 말하면 베팅 시작
-- "1" ~ "9" 라고 말하면 게임 시작
if string.find(str, "경마") then
Bet();
state = ST_READY;
elseif string.find("123456789", string.sub(str, 1, 1)) then
if state == ST_READY then
choice = tonumber( string.sub(str, 1, 1) );
if choice <= COUNT then
-- 매번 다른 결과가 나오도록 랜덤 초기화
math.randomseed(os.time());
-- 게임 실행
Game();
state = ST_BET;
else
H.PlaySound(0, "r[1]");
H.StartAnimation(0, 1, H.Emotion.no);
H.Say(1, "1에서 " .. COUNT .. " 중 하나를 선택해서 채팅 창에 입력하세요~");
end
end
end
end
function Bet()
text = "";
for label=1,COUNT+1 do
text = text .. "r1[" .. label .. "]";
end
H.PlaySound(0, text);
for label=1,COUNT do
H.Glow(label, label, 1, 255, 0, 0);
H.Say(label, label .. "번말~");
H.StartAnimation(0, label, H.Emotion.point);
end
H.Say(COUNT+1, "저 앞에 상자로 된 1번말에서 " ..
COUNT .. "번말까지 보이시죠? " ..
"1에서 " .. COUNT .. " 중 하나를 선택하세요~");
end
function Game()
-- 경기 결과 초기화
for outlet=1,COUNT do
value[outlet] = 0;
end
track = "";
-- 경기에 대한 label 설정
for i=1,RUN do
track = track .. "r0.5[" .. i .. "] "
end
-- 시상에 대한 label 설정
for i=RUN+1, RESULT do
track = track .. "r0.5[" .. i .. "]"
end
-- 경기/시상 label 설정
H.PlaySound(0, track);
-- 경주
reach = false;
RUN1 = RUN;
for label =1,RUN do
for outlet=1,COUNT do
value[outlet] = value[outlet] + Dice();
if value[outlet] >= GOAL then
reach = true;
end
H.SetPos(outlet, label,
STEP * value[outlet], 0, 0, 1);
end
if reach == true then
RUN1 = label;
break;
end
end
-- 등수 매기기
rank = {};
for i=1, COUNT do
rank[i] = i;
end
table.sort(rank, CompareValue);
-- 집사는 춤을 춘다
H.StartAnimation(0, 1, H.Emotion.dance);
-- 등수를 집사의 대화로
rankstr = "";
for i = 1, COUNT do
rankstr = rankstr .. i .. "등 " .. rank[i] ..
"번말 " ;
-- 디버그 하려면 다음 문장 사용
-- rankstr = rankstr .. i .. "등 " .. rank[i] ..
-- "번말 " .. value[rank[i]] .. "m" ;
if 1 <= i and i <= 4 then
rankstr = rankstr .. ",";
end
end
-- 집사 말하기
H.Say(RUN1+1, rankstr);
if rank[1] == choice then
H.Say(RUN1+2, "축하합니다~~~");
H.StartAnimation(0, RUN1+2, H.Emotion.victory);
end
-- 시상식: 반짝이기, 점프
H.Glow(rank[1], RUN1, RESULT-RUN1, 255, 255, 255);
for label=RUN+1, RESULT do
H.SetPos(rank[1], label,
STEP * value[rank[1]], 0, label , 1);
end
end
-- sort 에 사용하는 함수
function CompareValue(v1, v2)
return value[v1] >= value[v2];
end
-- 주사위 함수
function Dice()
return math.random(4);
end
---------------------- 여기까지 넣으시면 됩니다~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment