What's new

NPC Nowy System NPC

Status
Not open for further replies.

Lopus

Advanced User
Joined
Jun 17, 2011
Messages
206
Reaction score
9
W data/lib/050-function.lua szukamy funkcji:
PHP:
function getItemWeightById(itemid, count, precision)
I ca?? usuwamy.
Potem w data/lib/050-function.lua dodajemy:
PHP:
function getExhausted(cid, storage)
return os.time() > getCreatureStorage(cid, storage) and true
end
function setExhausted(cid, storage, cooldown)
return doCreatureSetStorage(cid, storage, os.time() + cooldown - 1)
end
function getItemWeightById(itemid, count, precision)
local item, count, precision = getItemInfo(itemid), count or 1, precision or false
if(not item) then
return false
end
local weight = item.weight * count
if precision then
local s = tonumber(string.sub(weight, 3, 4))
local w = tonumber(string.sub(weight, 0, 1))
if s ~= nil then
if s >= 5 and s <= 9 then
weight = w + math.ceil(s/100)/10
elseif s >= 0 and s < 5 then
weight = w + math.floor(s/100)/10
else
weight = w + (s/100)
end
return weight
end
end
return weight
end
Do data/NPC/lib/npc.lua doklejamy now? funkcj?:
PHP:
function showOffert(cid, itemy, stor, cooldown)
local npc, msgs = getNpcCid(), ''
for i = 1, #itemy do
v = itemy[i]
if v.voc == nil or isInArray(v.voc, getPlayerVocation(cid)) then
if getCreatureStorage(npc, v.s) == -1 or getExhausted(npc, stor) then
doCreatureSetStorage(npc, v.s, math.random(v.c[1],v.c[2]))
end
if v.buy == 0 then x = 'brak' else x = math.floor(v.buy) .. ' miedzianych monet' end
if v.sell == 0 then y = 'brak' else y = math.floor(v.sell) .. ' miedzianych monet' end
if getCreatureStorage(npc, v.s) == 0 then z = 'brak' else z = getCreatureStorage(npc, v.s) end
msgs = msgs .. 'Nazwa: '..getItemNameById(v.id)..'\nWaga: '..getItemWeightById(v.id, 1, true)..' uncji\nSkup: '..y..'\nSprzeda?: '..x..'\nIlo??: '..z..'\n\n'
else
if i == #itemy and msgs == '' then
msgs = 'Brak dost?pnych przedmiot?w.'
return msgs
end
end
if getExhausted(npc, stor) and i == #itemy then
setExhausted(npc, stor, cooldown)
end
end
msgs = msgs .. 'Nowa dostawa za oko?o '..math.ceil((getCreatureStorage(npc, stor)-os.time())/60) ..' minut.'
return msgs
end
function openTradeWindow(cid, itemy, stor, cooldown)
local npc = getNpcCid()
local items, msgs = {}, ''
for i = 1, #itemy do
v = itemy[i]
if getCreatureStorage(npc, v.s) == -1 or getExhausted(npc, stor) then
doCreatureSetStorage(npc, v.s, math.random(v.c[1],v.c[2]))
if i == 1 then
setExhausted(npc, stor, cooldown)
end
end
items[v.id] = {storage = v.s, item_id = v.id, buyPrice = v.buy, sellPrice = v.sell, subType = 0, realName = v.name}
end
local onBuy = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if getCreatureStorage(npc, items[item].storage) - amount >= 0 then
doCreatureSetStorage(npc, items[item].storage, getCreatureStorage(npc, items[item].storage) - amount)
if inBackpacks == true then
bp = doPlayerAddItem(cid, 2000)
end
if isItemStackable(item) then
if inBackpacks == true then
doAddContainerItem(bp, item, amount)
else
doPlayerAddItem(cid, item, amount)
end
else
for i = 1, amount do
if inBackpacks == true then
doAddContainerItem(bp, item, 1)
else
doPlayerAddItem(cid, item, 1)
end
end
end
doPlayerRemoveMoney(cid, amount * items[item].buyPrice)
return selfSay('Kupiles '..amount..' '..items[item].realName..' za '..items[item].buyPrice * amount..' sztuk miedzi.', cid)
else
return selfSay('Nie mam tyle '..items[item].realName..' na sk?adzie.', cid)
end
end
local onSell = function(cid, item, subType, amount, ignoreCap, inBackpacks)
if getCreatureStorage(npc, items[item].storage) + amount <= 100 or isItemStackable(item) then
doCreatureSetStorage(npc, items[item].storage, getCreatureStorage(npc, items[item].storage) + amount)
doPlayerRemoveItem(cid, item, amount)
doPlayerAddMoney(cid, items[item].sellPrice * amount)
return selfSay('Sprzedales '..amount..' '..items[item].realName..' za '..items[item].sellPrice * amount..' sztuk miedzi.', cid)
else
return selfSay('Nie mam tyle miejsca w sk?adzie.', cid)
end
end
return openShopWindow(cid, itemy, onBuy, onSell)
end
Czym si? charakteryzuje ta funkcja? Ot?? dzi?ki niej mo?emy ustali? ilo?? przedmiot?w w magazynie naszego NPCta. Je?li kto? wykupi ca?y asortyment to gracz musi czeka? na nast?pn? dostaw? z towarem. Dodatkowo przedmioty stackable mo?na sprzedawa? bez ogranicze?, za? te no stackable (pancerze, tarcze itd) NPC pomie?ci maksymalnie 100 sztuk danego przedmiotu.
Druga z funkcji pokazuje nam ofert? NPCta, nazwa przedmiot?w w ofercie, wag?, ilo?? sztuk na sk?adzie, cena skupu i sprzeda?y oraz czas do nast?pnej dostawy.
Oto przyk?ad takiego NPCta.
PHP:
local keywordHandler = KeywordHandler:new()
local npcHandler = NpcHandler:new(keywordHandler)
NpcSystem.parseParameters(npcHandler)
local talkState = {}
function onCreatureAppear(cid) npcHandler:onCreatureAppear(cid) end
function onCreatureDisappear(cid) npcHandler:onCreatureDisappear(cid) end
function onCreatureSay(cid, type, msg) npcHandler:onCreatureSay(cid, type, msg) end
function onThink() npcHandler:onThink() end
local storage = 1000
function creatureSayCallback(cid, type, msg)
if(not npcHandler:isFocused(cid)) then
return false
end
local talkUser = NPCHANDLER_CONVBEHAVIOR == CONVERSATION_DEFAULT and 0 or cid
local i_g, m, d, w, w_130, d_80, d_50, w_80, w_50, m_80, m_50 = getOnlinePlayers(), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
local D, M, W, S, Ww, Mm = 0, 0, 0, 0, 1, 1
if isInArray({1,2,5,6}, getPlayerVocation(cid)) then
M = 1
Ww = 0
elseif isInArray({3,7}, getPlayerVocation(cid)) then
D = 1
elseif isInArray({4,8}, getPlayerVocation(cid)) then
W = 1
Mm = 0
end
for i = 1, #i_g do
local player = getPlayerByName(i_g[i])
if isInArray({1,2,5,6}, getPlayerVocation(player)) then
if getPlayerLevel(player) >= 50 then
if getPlayerLevel(player) >= 80 then
m_80 = m_80 + 1
end
m_50 = m_50 + 1
end
m = m + 1
elseif isInArray({3,7}, getPlayerVocation(player)) then
if getPlayerLevel(player) >= 50 then
if getPlayerLevel(player) >= 80 then
d_80 = d_80 + 1
end
d_50 = d_50 + 1
end
d = d + 1
elseif isInArray({4,8}, getPlayerVocation(player)) then
if getPlayerLevel(player) >= 50 then
if getPlayerLevel(player) >= 80 then
w_80 = w_80 + 1
if getPlayerLevel(player) >= 130 then
w_130 = w_130 + 1
end
end
w_50 = w_50 + 1
end
w = w + 1
end
end
local MP_HP = {#i_g*300,#i_g*400}
local SMP = {(d_50*120)+(m_50*200),(d_50*160)+(m_50*320)}
local GMP = {m_80*190,m_80*230}
local SHP = {(d_50*140)+(w_50*180),(d_50*220)+(w_50*260)}
local GHP = {w_80*190,w_80*230}
local UHP = {w_130*170,w_130*210}
local GSP = {d_80*180,d_80*260}
local itemy = {
{s=1100, c=MP_HP, id=7620, buy=50-math.floor(#i_g/50), sell=15+math.floor(#i_g/50), name='lekka mikstura many'},
{s=1101, c=SMP, id=7589, buy=((80-math.floor((m_50+d_50)/25))*((m_50+d_50)/(m_50+d_50)))*Mm, sell=25+math.floor((m_50+d_50)/30), name='mikstura many'},
{s=1102, c=GMP, id=7590, buy=((120-math.floor(m_80/10))*(m_80/m_80))*M, sell=35+math.floor(m_80/20), name='silna mikstura many'},
{s=1103, c=MP_HP, id=7618, buy=45-math.floor(#i_g/50), sell=13+math.floor(#i_g/50), name='lekka mikstura ?ycia'},
{s=1104, c=SHP, id=7588, buy=((100-math.floor((d_50+w_50)/25))*((d_50+w_50)/(d_50+w_50)))*Ww, sell=30-math.floor((d_50+w_50)/30), name='mikstura ?ycia'},
{s=1105, c=GHP, id=7591, buy=((190-math.floor(w_80/10))*(w_80/w_80))*W, sell=60-math.floor(w_80/20), name='silna mikstura ?ycia'},
{s=1106, c=UHP, id=8473, buy=((310-math.floor(w_130/10))*(w_130/w_130))*W, sell=100-math.floor(w_130/15), name='pot??na mikstura ?ycia'},
{s=1107, c=GSP, id=8472, buy=((190-math.floor(d_80/15))*(d_80/d_80))*D, sell=60+math.floor(d_80/25), name='silna mikstura wytrzyma?o?ci'}
}
if msg:lower() == 'trade' then
selfSay('Oto moja oferta.', cid)
return openTradeWindow(cid, itemy, storage, math.random(120,240) * 60)
elseif msg:lower() == 'oferta' then
selfSay('Oto moja oferta.', cid)
return doShowTextDialog(cid, 8473, showOffert(cid, itemy, storage, math.random(120,240) * 60))
end
end
npcHandler:setMessage(MESSAGE_GREET, "Witaj |PLAYERNAME|! Moja osoba znana jest z produkcji najlepszych mikstur w Arydii. Co Ci? do mnie sprowadza?")
npcHandler:setCallback(CALLBACK_MESSAGE_DEFAULT, creatureSayCallback)
npcHandler:addModule(FocusModule:new())
Ilo?? przedmiot?w w sk?adzie zale?na jest od ilo?ci graczy online. Dodatkowo np ilo?? GMP jest liczona wed?ug graczy, kt?rzy mog? jej u?ywa?, czyli im wi?cej os?b mog?cych u?ywa? GMP tym wi?cej ich sztuk w sk?adzie.
Ceny s? zale?ne od ilo?ci graczy online. Im wi?cej os?b tym ceny sprzeda?y ta?sze, a skupu dro?sze.
Mo?na tak?e ustawi?, kt?re przedmioty pojawiaj? si? w okienku trade dla danych profesji.
Jednym s?owem - mn?stwo opcji, ?wietna zabawa i funkcjonalno??.
 

Raa

Senior User
Joined
Aug 9, 2009
Messages
715
Reaction score
50
Age
29
Odp: Nowy System NPC

I mo?na by?o to napisa? w o wiele lepszy spos?b.
+tabulatory pls.
 

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
Odp: Nowy System NPC

Nie wiem sk?d zer?n??e? ten kod. Nie przypominam sobie ?ebym kiedykolwiek go udost?pnia?.
 

Lopus

Advanced User
Joined
Jun 17, 2011
Messages
206
Reaction score
9
Odp: Nowy System NPC

Synku jestem na innym levelu :)
 

Zbizu

Luakami
Joined
Mar 13, 2010
Messages
719
Reaction score
104
Age
28
Odp: Nowy System NPC

s?aby i d?ugi ten kod
w dodatku Oskar twierdzi ?e wrzucony bez zgody autora
no ale co mi tam... jak kto? skasuje temat to piszcie mi pw to napisz? swoj? wersj? od zera i wrzuc?

npcsystem Jiddo jest dobry i nie widz? sensu go zmienia? (ten kod i tak tego nie robi a jedynie go rozszerza)
 
Last edited:

Oskar

Forum friend
Joined
Jan 24, 2009
Messages
2,256
Reaction score
331
Odp: Nowy System NPC

npcHandler:setMessage(MESSAGE_GREET, "Witaj |PLAYERNAME|! Moja osoba znana jest z produkcji najlepszych mikstur w Arydii. Co Ci? do mnie sprowadza?")
Przypadkiem m?j pustynny kontynent si? tak nazywa? NPC z kt?rego to zer?n??e? nazywa? si? Rhenna, mo?esz sobie sprawdzi?. Nie lubi? jak mi wciska si? kit.
 

pxgift2

Active User
Joined
Jun 7, 2015
Messages
86
Reaction score
0
Odp: Nowy System NPC

Co ty si? tak Oskar puszysz, napisz do admina o usuni?cie, albo si? nie pusz. Dla mnie jeste? zwyk?y frajer i tyle.
 
Status
Not open for further replies.
Top