Cod: Selectaţi tot
define NUMBER_TITLES table.getn(TITLE_NAMES)
define TABLE_NAME "title_system"
define TITLE_LEVEL "level"Cod: Selectaţi tot
define NUMBER_TITLES table.getn(TITLE_NAMES)
define TABLE_NAME "title_system"
define TITLE_LEVEL "level"
quest title_system begin
state start begin
function getTitles()
return pc.getqf_table(TABLE_NAME)
end
function isTitleUnlocked(idx)
return pc.getqf_table_idx(TABLE_NAME, idx) != TABLEQF_DEFAULT
end
function unlockTitle(idx)
if title_system.isTitleUnlocked(idx) then return end
notice("Du hast den Titel \'"..TITLE_NAMES[idx][1].."\' freigeschaltet. Herzlichen Glückwunsch!")
pc.setqf_table(TABLE_NAME, idx, 1)
end
function init()
pc.initialize_table(TABLE_NAME, NUMBER_TITLES)
title_system.unlockTitle(TITLE_FRISCHLING)
end
function getCurrentTitle()
return pc.getqf(TITLE_LEVEL)
end
function setCurrentTitle(idx)
pc.setqf(TITLE_LEVEL, idx-1)
pc.set_title_level(idx-1)
end
when login begin
local table_len = pc.getqf_table_length(TABLE_NAME)
-- initialize table for existing characters
if table_len == 0 then
title_system.init()
-- check if new titles got added
elseif NUMBER_TITLES > table_len then
pc.extend_table(TABLE_NAME, NUMBER_TITLES)
end
-- bugfix for wrong titles
if pc.getqf("bug")==0 then
local temp1 = title_system.isTitleUnlocked(TITLE_DRACHENTOTER)
local temp2 = title_system.isTitleUnlocked(TITLE_DT)
if temp1 and not temp2 then
pc.setqf_table(TABLE_NAME, TITLE_DT, 1)
pc.setqf_table(TABLE_NAME, TITLE_DRACHENTOTER, -1)
if title_system.getCurrentTitle()==TITLE_DRACHENTOTER-1 then
title_system.setCurrentTitle(TITLE_DT)
end
end
if temp2 and not temp1 then
pc.setqf_table(TABLE_NAME, TITLE_DT, -1)
pc.setqf_table(TABLE_NAME, TITLE_DRACHENTOTER, 1)
if title_system.getCurrentTitle()==TITLE_DT-1 then
title_system.setCurrentTitle(TITLE_DRACHENTOTER)
end
end
end
pc.setqf("bug", 1)
-- send current level
pc.set_title_level(title_system.getCurrentTitle())
-- generate quest scroll
--send_letter("Titel auswählen")
-- send quest index to client
cmdchat("titleqid "..q.getcurrentquestindex())
-- timer that checks if titles got unlocked
loop_timer("check_titles", 1)
end
when check_titles.timer begin
table.foreach(TITLE_NAMES, function(i,p)
if p[4] != -1 and pc.getqf(p[3])>=p[4] then
title_system.unlockTitle(i)
pc.delqf(p[3])
end
end)
if pc.get_real_alignment()<=-20000 then
title_system.unlockTitle(TITLE_GEHASST)
end
end
when kill begin
if npc.is_pc() and npc.get_level()>=pc.get_level()-10 then
pc.setqf(TITLE_NAMES[TITLE_SCHLACHTER][3], pc.getqf(TITLE_NAMES[TITLE_SCHLACHTER][3])+1)
else
if npc.get_level()>=pc.get_level()-10 then
pc.setqf(TITLE_NAMES[TITLE_ZERSTORER][3], pc.getqf(TITLE_NAMES[TITLE_ZERSTORER][3])+1)
end
if npc.get_race()==101 then
pc.setqf(TITLE_NAMES[TITLE_TIERQUALER][3], pc.getqf(TITLE_NAMES[TITLE_TIERQUALER][3])+1)
end
if npc.get_race()==1192 then
pc.setqf(TITLE_NAMES[TITLE_HALBGOTT][3], pc.getqf(TITLE_NAMES[TITLE_HALBGOTT][3])+1)
end
end
end
when button or info begin
local tTitle = title_system.getTitles()
local tText = {}
local nState = {}
local tIndex = {}
local tBlockedTitles = {TITLE_FARMER, TITLE_KONIG, TITLE_ERFORSCHER}
-- generate text array for selection, memorize blocked titles
for i=1, NUMBER_TITLES do
if not table_is_in(tBlockedTitles, i) then
if title_system.isTitleUnlocked(i) then
table.insert(tText, TITLE_NAMES[i][1])
table.insert(nState, 1)
else
table.insert(tText, "(BLOCKIERT) "..TITLE_NAMES[i][1])
table.insert(nState, -1)
end
table.insert(tIndex, i)
end
end
table.insert(tText, "Abbrechen")
local sel = ingame_support.sel(tText, "", "Titel auswählen")
if sel==table.getn(tText) then return end
local idx = tIndex[sel]
-- either change the title if it is unlocked or give out information
if nState[sel] != -1 then
title_system.setCurrentTitle(idx)
syschat("Du hast deinen Titel erfolgreich geändert!")
else
say_title("Titel auswählen: "..TITLE_NAMES[idx][1])
if TITLE_NAMES[idx][3] == "" then
say(TITLE_NAMES[idx][2])
else
if idx == TITLE_SCHLACHTER then
say(string.format(TITLE_NAMES[idx][2], pc.getqf(TITLE_NAMES[idx][3])/2, TITLE_NAMES[idx][4]/2))
else
say(string.format(TITLE_NAMES[idx][2], pc.getqf(TITLE_NAMES[idx][3]), TITLE_NAMES[idx][4]))
end
end
wait()
end
-- generate quest scroll
send_letter("Titel auswählen")
end
when 33002.chat."GM: titel cheaten" with pc.is_gm() begin
pc.setqf("bug", 0)
local tTitle = title_system.getTitles()
local tText = {}
for i=1, NUMBER_TITLES do
tText[i] = TITLE_NAMES[i][1]
end
local sel = ingame_support.sel(tText, "", "Titel auswählen")
title_system.setCurrentTitle(sel)
syschat("Du hast deinen Titel erfolgreich geändert!")
end
end
end



.
