look it's my npcs.lua :
Mehr
NPCs = {
[1] = {"Morgon", pos={1713, 1624}, rot=180, image="npc5", trade={{307,225},{310,300},{311,500},{312,400},{306,90},{305,200},{300,85},{312,240},{313,150}}},
[2] = {"Jack", pos={2076, 1578, rot=180, image="npc5", trade={{320,750},{321,1230},{322,700},{323,450},{324,950},{325,670},{10,25},{12,240},{11,150}}},
[3] = {"Nikolas", pos={1896, 2291}, rot=0, image="npc6", trade={{5,150},{4,150}}},
[4] = {"Antonio", pos={189, 147}, rot=180, image="npc5", trade={{1,25},{2,100},{4,50},{5,100},{6,90},{7,200},{10,25},{12,240},{11,150}}},
[5] = {"Guess", pos={561, 435}, rot=0, image="npc3", trade={{304,175},{303,75}}},
[6] = {"Table seller", pos=1635, 819}, rot=0, image="npc6", trade={{218,150},{219,150}}},
[7] = {"Bro Antonio", pos={1666, 2188}, rot=0, image="npc5", trade={{1,25},{2,100},{4,50},{5,100},{6,90},{7,200},{10,25},{12,240},{11,150}}},
[8] = {"Guard", pos={1697, 307}, rot=180, image="npc5", trade={{307,300},{316,600},{326,900},{334,9500},{338,12300},{339,12200},{337,16000},{12,240},{11,150}}},
[9] = {"Dark man", pos={4208, 5040}, rot=90, image="npc3", trade={{-210,75},{-214,75}}},
[10] = {"Man", pos={3888, 4880}, rot=270, image="npc6", trade={{-218,150},{-219,150}}},
[11] = {"Serious Man", pos={3888, 5040}, rot=270, image="npc5", trade={{-220,300},{-221,300},{-222,300},{-223,300}}},
[12] = {"BlackSmith", pos={2384, 1488}, rot=180, image="npc3", trade={{300,75},{301,150},{302,150},{303,100},{304,150},{305,200},{306,175},{307,300}}},
[13] = {"Joe", pos={416, 196}, rot=270, image="npc1"},
[14] = {"Food Seller", pos={1363, 2349}, rot=270, image="npc5", trade={{-1,25},{-4,50},{-6,100},{-7,100},{-8,50}}},
[15] = {"Rune Seller", pos={2089, 780}, rot=0, image="npc4", trade={{100,100},{101,100},{102,75},{103,100},{104,100},{105,100},{106,100}}},
[16] = {"Horse Trader", pos={2220, 2183}, rot=270, image="npc1", trade={{400,1000},{401,1000},{402,1000},{403,1000},{-400,1000},{-401,1000},{-402,1000},{-403,1000}}},
[17] = {"Sweet Seller", pos={6240, 1024}, rot=270, image="npc6", trade={{7,250},{9,25},{10,50},{11,100},{12,150},{13,200},{14,100},{15,150},{16,200}}},
}
for i, j in ipairs(NPCs) do
j.image = image("gfx/weiwen/" .. (j.image or "npc1") .. ".png", 0, 0, 0)
imagepos(j.image, j.pos[1], j.pos[2], j.rot)
if j.trade then
local text = j[1] .. ","
for k, l in ipairs(j.trade) do
local itemid
if l[1] < 0 then
itemid = -l[1]
text = text .. "sell "
else
itemid = l[1]
text = text .. "buy "
end
text = text .. ITEMS[itemid].name .. "1" .. l[2] .. "."
end
j.menu = text
end
end
function contains(words, text) words = words:lower(); return words == text or words:find(text .. " ") or words:find(" " .. text) end
function NPCspeak(npcid, words) return radiusmsg(string.format("©255255100%s %s says : %s", os.date'%X', NPCs[npcid][1], words), NPCs[npcid].pos[1], NPCs[npcid].pos[2]) end
function setNPCpos(npcid, x, y, rot)
NPCs[npcid].rot = rot or NPCs[npcid].rot
NPCs[npcid].pos = (x and y) and {x*32+16, y*32+16} or NPCs[npcid].pos
imagepos(NPCs[npcid].image, NPCs[npcid].pos[1], NPCs[npcid].pos[2], NPCs[npcid].rot)
end
addhook("say", "NPCsay")
function NPCsay(id, words)
words = words:lower()
if PLAYERS[id].tmp.npcstate then
local v = NPCs[PLAYERS[id].tmp.npcstate[1]]
if inarea(player(id, "x"), player(id, "y"), v.pos[1]-96, v.pos[2]-96, v.pos[1]+96, v.pos[2]+96) then
NPCs[PLAYERS[id].tmp.npcstate[1]].func(PLAYERS[id].tmp.npcstate[1], id, words, PLAYERS[id].tmp.npcstate[2])
return
else
PLAYERS[id].tmp.npcstate = nil
end
end
if contains(words, "hi") or contains(words, "hello") or contains(words, "siema") or contains(words, "hey") then
for k, v in ipairs(NPCs) do
if inarea(player(id, "x"), player(id, "y"), v.pos[1]-96, v.pos[2]-96, v.pos[1]+96, v.pos[2]+96) then
if v.func then
v.func(k, id, "hi")
elseif v.menu then
menu(id, v.menu)
else
NPCspeak(k, "Hello, I'm busy right now, speak to me later.")
break
end
if v.greet then
NPCspeak(k, string.format(v.greet, player(id, "name")))
end
break
end
end
end
end
addhook("menu", "NPCmenu")
function NPCmenu(id, title, button)
for i, v in ipairs(NPCs) do
if title == v[1] then
if button == 0 then
if v.bye then
NPCspeak(i, v.bye)
end
return
end
local itemid = math.abs(v.trade[button][1])
if itemid then
print(itemid)
radiusmsg(string.format("©255255100%s %s says : %s %s", os.date'%X', player(id, 'name'), v.trade[button][2] > 0 and "buy" or "sell", ITEMS[itemid].name), player(id, 'x'), player(id, 'y'))
if v.trade[button][1] < 0 then
if removeitem(id, itemid, 1, true) then
addmoney(id, itemid, v.trade[button][2])
message(id, "You have recieved $" .. v.trade[button][2] .. ".", "255255255")
msg2(id, "You have sold " .. ITEMS[itemid].article .. " " .. ITEMS[itemid].name .. " for $" .. v.trade[button][2] .. ".")
return menu(id, NPCs[i].menu)
end
msg2(id, "You do not have " .. ITEMS[itemid].article .. " " .. ITEMS[itemid].name .. " to sell.")
return
elseif addmoney(id, -v.trade[button][2]) then
if additem(id, itemid, 1, true) then
message(id, "You have lost $" .. v.trade[button][2] .. ".", "255255255")
msg2(id, "You have bought " .. ITEMS[itemid].article .. " " .. ITEMS[itemid].name .. " for $" .. v.trade[button][2] .. ".")
return menu(id, NPCs[i].menu)
end
msg2(id, "You do not have enough capacity.")
return
end
msg2(id, "You do not have enough money.")
end
return
end
end
end
[1] = {"Morgon", pos={1713, 1624}, rot=180, image="npc5", trade={{307,225},{310,300},{311,500},{312,400},{306,90},{305,200},{300,85},{312,240},{313,150}}},
[2] = {"Jack", pos={2076, 1578, rot=180, image="npc5", trade={{320,750},{321,1230},{322,700},{323,450},{324,950},{325,670},{10,25},{12,240},{11,150}}},
[3] = {"Nikolas", pos={1896, 2291}, rot=0, image="npc6", trade={{5,150},{4,150}}},
[4] = {"Antonio", pos={189, 147}, rot=180, image="npc5", trade={{1,25},{2,100},{4,50},{5,100},{6,90},{7,200},{10,25},{12,240},{11,150}}},
[5] = {"Guess", pos={561, 435}, rot=0, image="npc3", trade={{304,175},{303,75}}},
[6] = {"Table seller", pos=1635, 819}, rot=0, image="npc6", trade={{218,150},{219,150}}},
[7] = {"Bro Antonio", pos={1666, 2188}, rot=0, image="npc5", trade={{1,25},{2,100},{4,50},{5,100},{6,90},{7,200},{10,25},{12,240},{11,150}}},
[8] = {"Guard", pos={1697, 307}, rot=180, image="npc5", trade={{307,300},{316,600},{326,900},{334,9500},{338,12300},{339,12200},{337,16000},{12,240},{11,150}}},
[9] = {"Dark man", pos={4208, 5040}, rot=90, image="npc3", trade={{-210,75},{-214,75}}},
[10] = {"Man", pos={3888, 4880}, rot=270, image="npc6", trade={{-218,150},{-219,150}}},
[11] = {"Serious Man", pos={3888, 5040}, rot=270, image="npc5", trade={{-220,300},{-221,300},{-222,300},{-223,300}}},
[12] = {"BlackSmith", pos={2384, 1488}, rot=180, image="npc3", trade={{300,75},{301,150},{302,150},{303,100},{304,150},{305,200},{306,175},{307,300}}},
[13] = {"Joe", pos={416, 196}, rot=270, image="npc1"},
[14] = {"Food Seller", pos={1363, 2349}, rot=270, image="npc5", trade={{-1,25},{-4,50},{-6,100},{-7,100},{-8,50}}},
[15] = {"Rune Seller", pos={2089, 780}, rot=0, image="npc4", trade={{100,100},{101,100},{102,75},{103,100},{104,100},{105,100},{106,100}}},
[16] = {"Horse Trader", pos={2220, 2183}, rot=270, image="npc1", trade={{400,1000},{401,1000},{402,1000},{403,1000},{-400,1000},{-401,1000},{-402,1000},{-403,1000}}},
[17] = {"Sweet Seller", pos={6240, 1024}, rot=270, image="npc6", trade={{7,250},{9,25},{10,50},{11,100},{12,150},{13,200},{14,100},{15,150},{16,200}}},
}
for i, j in ipairs(NPCs) do
j.image = image("gfx/weiwen/" .. (j.image or "npc1") .. ".png", 0, 0, 0)
imagepos(j.image, j.pos[1], j.pos[2], j.rot)
if j.trade then
local text = j[1] .. ","
for k, l in ipairs(j.trade) do
local itemid
if l[1] < 0 then
itemid = -l[1]
text = text .. "sell "
else
itemid = l[1]
text = text .. "buy "
end
text = text .. ITEMS[itemid].name .. "1" .. l[2] .. "."
end
j.menu = text
end
end
function contains(words, text) words = words:lower(); return words == text or words:find(text .. " ") or words:find(" " .. text) end
function NPCspeak(npcid, words) return radiusmsg(string.format("©255255100%s %s says : %s", os.date'%X', NPCs[npcid][1], words), NPCs[npcid].pos[1], NPCs[npcid].pos[2]) end
function setNPCpos(npcid, x, y, rot)
NPCs[npcid].rot = rot or NPCs[npcid].rot
NPCs[npcid].pos = (x and y) and {x*32+16, y*32+16} or NPCs[npcid].pos
imagepos(NPCs[npcid].image, NPCs[npcid].pos[1], NPCs[npcid].pos[2], NPCs[npcid].rot)
end
addhook("say", "NPCsay")
function NPCsay(id, words)
words = words:lower()
if PLAYERS[id].tmp.npcstate then
local v = NPCs[PLAYERS[id].tmp.npcstate[1]]
if inarea(player(id, "x"), player(id, "y"), v.pos[1]-96, v.pos[2]-96, v.pos[1]+96, v.pos[2]+96) then
NPCs[PLAYERS[id].tmp.npcstate[1]].func(PLAYERS[id].tmp.npcstate[1], id, words, PLAYERS[id].tmp.npcstate[2])
return
else
PLAYERS[id].tmp.npcstate = nil
end
end
if contains(words, "hi") or contains(words, "hello") or contains(words, "siema") or contains(words, "hey") then
for k, v in ipairs(NPCs) do
if inarea(player(id, "x"), player(id, "y"), v.pos[1]-96, v.pos[2]-96, v.pos[1]+96, v.pos[2]+96) then
if v.func then
v.func(k, id, "hi")
elseif v.menu then
menu(id, v.menu)
else
NPCspeak(k, "Hello, I'm busy right now, speak to me later.")
break
end
if v.greet then
NPCspeak(k, string.format(v.greet, player(id, "name")))
end
break
end
end
end
end
addhook("menu", "NPCmenu")
function NPCmenu(id, title, button)
for i, v in ipairs(NPCs) do
if title == v[1] then
if button == 0 then
if v.bye then
NPCspeak(i, v.bye)
end
return
end
local itemid = math.abs(v.trade[button][1])
if itemid then
print(itemid)
radiusmsg(string.format("©255255100%s %s says : %s %s", os.date'%X', player(id, 'name'), v.trade[button][2] > 0 and "buy" or "sell", ITEMS[itemid].name), player(id, 'x'), player(id, 'y'))
if v.trade[button][1] < 0 then
if removeitem(id, itemid, 1, true) then
addmoney(id, itemid, v.trade[button][2])
message(id, "You have recieved $" .. v.trade[button][2] .. ".", "255255255")
msg2(id, "You have sold " .. ITEMS[itemid].article .. " " .. ITEMS[itemid].name .. " for $" .. v.trade[button][2] .. ".")
return menu(id, NPCs[i].menu)
end
msg2(id, "You do not have " .. ITEMS[itemid].article .. " " .. ITEMS[itemid].name .. " to sell.")
return
elseif addmoney(id, -v.trade[button][2]) then
if additem(id, itemid, 1, true) then
message(id, "You have lost $" .. v.trade[button][2] .. ".", "255255255")
msg2(id, "You have bought " .. ITEMS[itemid].article .. " " .. ITEMS[itemid].name .. " for $" .. v.trade[button][2] .. ".")
return menu(id, NPCs[i].menu)
end
msg2(id, "You do not have enough capacity.")
return
end
msg2(id, "You do not have enough money.")
end
return
end
end
end
Error is bold ( text = text .. ITEMS[itemid].name .. "1" .. l[2] .. ".")
Please help
LUA ERROR: sys/lua/cs2dtibia/npcs.lua:34: attempt to concatenate field '?' (a nil value)
2× editiert, zuletzt 04.08.11 16:45:57