local lev = pc . getqf ( "current" ) 
if lev == 0 then return end 
if pc . getqf ( "buttonstate" ) == 3 then 
if pc . getqf ( "complete" ) ~= lev then 
pc . setqf ( "complete" , lev ) 
local s = pc . getqf ( "select" ) 
if s == 0 then s = 1 end 
say_title ( string . format ( gameforge . levelup . _50_sayTitle , lev ) ) 
say ( gameforge . levelup . _60_say ) 
say ( "" ) 
if lev <= 20 then 
if lev <= table . getn ( special . levelup_reward1 ) then 
pc . give_item ( gameforge . levelup . _64_give .. lev .. gameforge . levelup . _65_give , 
special . levelup_reward1 [ lev ] [ pc . job + 1 ] ) 
else 
local v = number ( 1 , 100 ) 
if v <= special . levelup_reward3 [ 1 ] [ 1 ] then 
pc . give_item ( gameforge . levelup . _64_give .. lev .. gameforge . levelup . _65_give , special . levelup_reward3 [ 1 ] [ 2 ] , special . levelup_reward3 [ 1 ] [ 3 ] ) 
elseif v <= special . levelup_reward3 [ 2 ] [ 1 ] then 
pc . give_item ( gameforge . levelup . _64_give .. lev .. gameforge . levelup . _65_give , special . levelup_reward3 [ 2 ] [ 2 ] , special . levelup_reward3 [ 2 ] [ 3 ] ) 
elseif v <= special . levelup_reward3 [ 3 ] [ 1 ] then 
pc . give_item ( gameforge . levelup . _64_give .. lev .. gameforge . levelup . _65_give , special . levelup_reward3 [ 3 ] [ 2 ] , special . levelup_reward3 [ 3 ] [ 3 ] ) 
elseif v <= special . levelup_reward3 [ 4 ] [ 1 ] then 
pc . give_item ( gameforge . levelup . _64_give .. lev .. gameforge . levelup . _65_give , special . levelup_reward3 [ 4 ] [ 2 ] , special . levelup_reward3 [ 4 ] [ 3 ] ) 
else 
pc . give_item ( gameforge . levelup . _64_give .. lev .. gameforge . levelup . _65_give , special . levelup_reward3 [ 5 ] [ 2 ] , special . levelup_reward3 [ 5 ] [ 3 ] ) 
end 
end 
pc . give_exp_perc ( gameforge . levelup . _64_give .. lev .. gameforge . levelup . _66_give , lev , special . levelup_quest [ lev ] [ 5 ] ) 
if lev == 12 or lev == 14 or lev == 16 or lev == 18 or lev == 20 then 
pc . give_item2 ( 50083 ) 
say_reward ( string . format ( gameforge . levelup . _70_sayReward , item_name ( 50083 ) ) ) 
wait ( ) 
end 
else 
local ll = lev - 20 
if lev < 26 then 
local n = table . getn ( special . levelup_reward_item_21 [ ll ] ) 
local t = special . levelup_reward_item_21 [ ll ] [ number ( 1 , n ) ] 
say_reward ( gameforge . levelup . _80_sayReward ) 
if type ( t ) == "table" then 
pc . give_item2 ( t [ 1 ] , t [ 2 ] ) 
say_reward ( string . format ( gameforge . levelup . _90_sayReward , item_name ( t [ 1 ] ) .. " " .. t [ 2 ] ) ) 
else 
pc . give_item2 ( t ) 
say_reward ( string . format ( gameforge . levelup . _100_sayReward , item_name ( t ) ) ) 
end 
end 
local reward_gold = special . levelup_reward_gold21 local reward_exp = special . levelup_reward_exp21 if lev >= 31 and lev <= 40 then 
reward_gold = special . levelup_reward_gold31 reward_exp = special . levelup_reward_exp31 elseif lev >= 41 and lev <= 50 then 
reward_gold = special . levelup_reward_gold41 reward_exp = special . levelup_reward_exp41 elseif lev >= 51 and lev <= 83 then 
reward_gold = special . levelup_reward_gold51 reward_exp = special . levelup_reward_exp51 elseif lev >= 84 and lev <= 90 then 
reward_gold = special . levelup_reward_gold51 reward_exp = special . levelup_reward_exp84 end 
n = number ( 0 , 99 ) 
local i = 0 
for i = 1 , table . getn ( reward_gold ) begin 
if n < reward_gold [ i ] [ 2 ] then 
pc . change_money ( reward_gold [ i ] [ 1 ] ) 
say_reward ( string . format ( gameforge . levelup . _110_sayReward , reward_gold [ i ] [ 1 ] ) ) 
break 
else 
n = n - reward_gold [ i ] [ 2 ] 
end 
end 
n = number ( 0 , 99 ) 
i = 0 
for i = 1 , table . getn ( reward_exp ) begin 
if n < reward_exp [ i ] [ 2 ] then 
pc . give_exp_perc ( gameforge . levelup . _64_give .. lev .. gameforge . levelup . _66_give , lev , reward_exp [ i ] [ 1 ] ) 
say_reward ( string . format ( gameforge . levelup . _120_sayReward , reward_exp [ i ] [ 1 ] ) ) 
break 
else 
n = n - reward_exp [ i ] [ 2 ] 
end 
end 
say ( "" ) 
wait ( ) 
end 
end 
local old_lev = lev 
lev = lev + 1 
if lev > 1 and lev < 90 and pc . level >= lev then 
pc . setqf ( "buttonstate" , 2 ) 
makequestbutton ( string . format ( gameforge . levelup . _130_makequestbutton , lev ) ) 
pc . setqf ( "current" , lev ) 
pc . setqf ( "select" , 1 ) 
pc . setqf ( "remain" , special . levelup_quest [ lev ] [ 2 ] ) 
setskin ( NOWINDOW ) 
return 
else 
pc . setqf ( "current" , 0 ) 
q . done ( ) 
end 
elseif pc . getqf ( "buttonstate" ) == 2 then 
local lev = pc . getqf ( "current" ) 
if lev == 0 then 
q . done ( ) 
end 
say_title ( gameforge . levelup . _140_sayTitle ) 
say ( gameforge . levelup . _150_say ) 
local sel = select ( 
mob_name ( special . levelup_quest [ lev ] [ 1 ] ) .. " " .. special . levelup_quest [ lev ] [ 2 ] .. gameforge . levelup . _155_say , 
mob_name ( special . levelup_quest [ lev ] [ 3 ] ) .. " " .. special . levelup_quest [ lev ] [ 4 ] .. gameforge . levelup . _155_say ) 
setskin ( SCROLL ) 
setbgimage ( "level_bg.tga" ) 
say ( "" ) 
say ( "" ) 
say ( "" ) 
pc . setqf ( "select" , sel ) 
addimage ( 20 , 12 , special . levelup_img [ special . levelup_quest [ lev ] [ sel * 2 - 1 ] ] ) 
setcolor ( 0 , 0 , 0 ) 
say ( string . format ( gameforge . levelup . _20_say , mob_name ( special . levelup_quest [ lev ] [ sel * 2 - 1 ] ) ) ) 
say ( string . format ( gameforge . levelup . _26_say , special . levelup_quest [ lev ] [ sel * 2 ] ) ) 
say ( string . format ( gameforge . levelup . _27_say , special . levelup_quest [ lev ] [ 5 ] ) ) 
if lev <= table . getn ( special . levelup_reward1 ) then 
raw_script ( ", " .. item_name ( special . levelup_reward1 [ lev ] [ pc . job + 1 ] ) ) 
elseif lev > table . getn ( special . levelup_reward1 ) and lev < 26 then 
raw_script ( ", " .. locale . levelup . random_item ) 
end 
if lev >= 21 then 
raw_script ( ", " .. locale . gold ) 
end 
raw_script ( newline ) 
levelup . show_mob_pos ( lev ) 
local s = select ( gameforge . levelup . _160_select ) 
if s == 1 then 
setskin ( NOWINDOW ) 
pc . setqf ( "remain" , special . levelup_quest [ lev ] [ sel * 2 ] ) 
syschat ( string . format ( gameforge . levelup . _170_chat , mob_name ( special . levelup_quest [ lev ] [ sel * 2 - 1 ] ) , " " .. special . levelup_quest [ lev ] [ sel * 2 ] ) ) 
q . set_title ( string . format ( gameforge . levelup . _180_qSetTitle , mob_name ( special . levelup_quest [ lev ] [ sel * 2 - 1 ] ) ) ) 
q . set_counter ( gameforge . levelup . _250_say , pc . getqf ( "remain" ) ) 
q . start ( ) 
end 
setskin ( NOWINDOW ) 
clearmapsignal ( ) 
elseif pc . getqf ( "buttonstate" ) == 1 then 
local s = pc . getqf ( "select" ) 
if s == 0 then s = 1 end 
local lev = pc . getqf ( "current" ) 
if lev ~= 0 then 
say_title ( gameforge . levelup . _140_sayTitle ) 
say ( string . format ( gameforge . levelup . _190_say , pc . getqf ( "remain" ) .. gameforge . levelup . _195_say .. mob_name ( special . levelup_quest [ lev ] [ s * 2 - 1 ] ) ) ) 
local ss = select ( gameforge . levelup . _200_select , gameforge . locale . levelup . prev_quest_go ) 
if ss == 1 then 
setskin ( SCROLL ) 
setbgimage ( "level_bg.tga" ) 
say ( "" ) 
say ( "" ) 
say ( "" ) 
addimage ( 20 , 12 , special . levelup_img [ special . levelup_quest [ lev ] [ s * 2 - 1 ] ] ) 
setcolor ( 0 , 0 , 0 ) 
say ( string . format ( gameforge . levelup . _20_say , mob_name ( special . levelup_quest [ lev ] [ s * 2 - 1 ] ) ) ) 
say ( string . format ( gameforge . levelup . _26_say , special . levelup_quest [ lev ] [ s * 2 ] ) ) 
raw_script ( string . format ( gameforge . levelup . _27_say , special . levelup_quest [ lev ] [ 5 ] ) ) 
say ( "" ) 
if lev <= table . getn ( special . levelup_reward1 ) then 
raw_script ( "," .. item_name ( special . levelup_reward1 [ lev ] [ pc . job + 1 ] ) ) 
elseif lev > table . getn ( special . levelup_reward1 ) and lev < 26 then 
raw_script ( "," .. locale . levelup . random_item ) 
end 
if lev >= 21 then 
raw_script ( "," .. locale . gold ) 
end 
raw_script ( newline ) 
select ( gameforge . locale . confirm ) 
setskin ( NOWINDOW ) 
clearmapsignal ( ) 
end 
setskin ( NOWINDOW ) 
q . set_title ( string . format ( gameforge . levelup . _180_qSetTitle , mob_name ( special . levelup_quest [ lev ] [ s * 2 - 1 ] ) ) ) 
q . set_counter ( gameforge . levelup . _250_say , pc . getqf ( "remain" ) ) 
q . start ( ) 
end 
end 
pc . setqf ( "buttonstate" , - 1 ) 
