Spoiler 

NPCs = {
[1] = {"Ship captain [Old island]", pos={3248, 2640}, rot=180, image="npc4"},
[2] = {"Ship captain [House island]", pos={5008, 4720}, rot=180, image="npc4"},
[3] = {"Ship captain [New island]", pos={4400, 1008}, rot=180, image="npc4"},
[4] = {"Bed seller", pos={3920, 4592}, rot=180, image="npc5", trade={{200,100},{202,100},{203,100},{204,100},{205,100},{206,100},{207,100},{208,100},{209,100}}},
[5] = {"Chair seller", pos={4176, 4592}, rot=180, image="npc3", trade={{210,75},{214,75}}},
[6] = {"Table seller", pos={4464, 4880}, rot=270, image="npc6", trade={{218,150},{219,150}}},
[7] = {"Doll seller", pos={4432, 4592}, rot=180, image="npc5", trade={{220,300},{221,300},{222,300},{223,300}}},
[8] = {"Bed buyer", pos={4208, 4880}, rot=90, image="npc1", trade={{-200,100},{-202,100},{-203,100},{-204,100},{-205,100},{-206,100},{-207,100},{-208,100},{-209,100}}},
[9] = {"Chair buyer", pos={4208, 5040}, rot=90, image="npc3", trade={{-210,75},{-214,75}}},
[10] = {"Table buyer", pos={3888, 4880}, rot=270, image="npc6", trade={{-218,150},{-219,150}}},
[11] = {"Doll buyer", 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={2768, 1552}, rot=0, image="npc1"},
[14] = {"Food Buyer", pos={6000, 912}, rot=180, image="npc5", trade={{-1,25},{-4,50},{-6,100},{-7,100},{-8,50}}},
[15] = {"Rune Seller", pos={6000, 1168}, rot=0, image="npc4", trade={{100,100},{101,100},{102,75},{103,100},{104,100},{105,100},{106,100}}},
[16] = {"Horse Trader", pos={2144, 2319}, rot=180, 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}}},
[18] = {"Ship captain [Secret island]", pos={752, 8624}, rot=90, image="npc4"},
}
NPCs[1].func = function(npc, id, words, state)
if words == "hi" then
NPCspeak(npc, "Welcome! Are you want to sail somewhere ?")
PLAYERS[id].tmp.npcstate = {npc, 1}
elseif state == 1 then
if words=="no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
NPCspeak(npc, "So where you want to sail:")
NPCspeak(npc, "[1] <- New island")
NPCspeak(npc, "[2] <- House island")
NPCspeak(npc, "[3] <- Secret island")
PLAYERS[id].tmp.npcstate = {npc, 2}
end
elseif state == 2 then
if words == "anywhere" or words == "nowhere" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "1" then
NPCspeak(npc, "So you want sail to new island.")
NPCspeak(npc, "It's cost only 100$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 3}
elseif words == "2" then
NPCspeak(npc, "So you want sail to house island.")
NPCspeak(npc, "It's cost only 50$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 4}
elseif words == "3" then
NPCspeak(npc, "So you want sail to Secret island.")
NPCspeak(npc, "It's cost only 500$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 5}
end
elseif state == 3 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-100) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 4400 1040')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 4 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 5008 4752')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 5 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-500) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 784 8624')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
end
end
NPCs[2].func = function(npc, id, words, state)
if words == "hi" then
NPCspeak(npc, "Welcome! Are you want to sail somewhere ?")
PLAYERS[id].tmp.npcstate = {npc, 1}
elseif state == 1 then
if words=="no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
NPCspeak(npc, "So where you want to sail:")
NPCspeak(npc, "[1] <- Old island")
NPCspeak(npc, "[2] <- New island")
NPCspeak(npc, "[3] <- Secret island")
PLAYERS[id].tmp.npcstate = {npc, 2}
end
elseif state == 2 then
if words == "anywhere" or words == "nowhere" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "1" then
NPCspeak(npc, "So you want sail to old island.")
NPCspeak(npc, "It's cost only 50$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 3}
elseif words == "2" then
NPCspeak(npc, "So you want sail to new island.")
NPCspeak(npc, "It's cost only 50$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 4}
elseif words == "3" then
NPCspeak(npc, "So you want sail to Secret island.")
NPCspeak(npc, "It's cost only 500$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 5}
end
elseif state == 3 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 3248 2672')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 4 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 4400 1040')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 5 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-500) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 784 8624')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
end
end
NPCs[18].func = function(npc, id, words, state)
if words == "hi" then
NPCspeak(npc, "Welcome! Are you want to sail somewhere ?")
PLAYERS[id].tmp.npcstate = {npc, 1}
elseif state == 1 then
if words=="no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
NPCspeak(npc, "So where you want to sail:")
NPCspeak(npc, "[1] <- Old island")
NPCspeak(npc, "[2] <- New island")
NPCspeak(npc, "[3] <- House island")
PLAYERS[id].tmp.npcstate = {npc, 2}
end
elseif state == 2 then
if words == "anywhere" or words == "nowhere" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "1" then
NPCspeak(npc, "So you want sail to old island.")
NPCspeak(npc, "It's cost only 100$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 3}
elseif words == "2" then
NPCspeak(npc, "So you want sail to new island.")
NPCspeak(npc, "It's cost only 50$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 4}
elseif words == "3" then
NPCspeak(npc, "So you want sail to House island.")
NPCspeak(npc, "It's cost only 100$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 5}
end
elseif state == 3 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-100) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 3248 2672')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 4 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 4400 1040')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 5 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-100) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 5007 4758')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
end
end
NPCs[3].func = function(npc, id, words, state)
if words == "hi" then
NPCspeak(npc, "Welcome! Are you want to sail somewhere ?")
PLAYERS[id].tmp.npcstate = {npc, 1}
elseif state == 1 then
if words=="no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
NPCspeak(npc, "So where you want to sail:")
NPCspeak(npc, "[1] <- Old island")
NPCspeak(npc, "[2] <- House island")
NPCspeak(npc, "[3] <- Secret island")
PLAYERS[id].tmp.npcstate = {npc, 2}
end
elseif state == 2 then
if words == "anywhere" or words == "nowhere" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "1" then
NPCspeak(npc, "So you want sail to old island.")
NPCspeak(npc, "It's cost only 100$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 3}
elseif words == "2" then
NPCspeak(npc, "So you want sail to house island.")
NPCspeak(npc, "It's cost only 50$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 4}
elseif words == "3" then
NPCspeak(npc, "So you want sail to Secret island.")
NPCspeak(npc, "It's cost only 500$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 5}
end
elseif state == 3 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-100) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 3248 2672')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 4 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 5008 4752')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 5 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-500) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 784 8624')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
end
end
NPCs[13].func = function(npc, id, words, state)
if words == "hi" then
NPCspeak(npc, "Hi do you want rest it's cost only $50 ?")
PLAYERS[id].tmp.npcstate = {npc, 1}
elseif state == 1 then
if words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Have good rest !")
parse('setpos '..id..' 2736 1648')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
elseif words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
end
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 .. "|" .. 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, "yo") 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] = {"Ship captain [Old island]", pos={3248, 2640}, rot=180, image="npc4"},
[2] = {"Ship captain [House island]", pos={5008, 4720}, rot=180, image="npc4"},
[3] = {"Ship captain [New island]", pos={4400, 1008}, rot=180, image="npc4"},
[4] = {"Bed seller", pos={3920, 4592}, rot=180, image="npc5", trade={{200,100},{202,100},{203,100},{204,100},{205,100},{206,100},{207,100},{208,100},{209,100}}},
[5] = {"Chair seller", pos={4176, 4592}, rot=180, image="npc3", trade={{210,75},{214,75}}},
[6] = {"Table seller", pos={4464, 4880}, rot=270, image="npc6", trade={{218,150},{219,150}}},
[7] = {"Doll seller", pos={4432, 4592}, rot=180, image="npc5", trade={{220,300},{221,300},{222,300},{223,300}}},
[8] = {"Bed buyer", pos={4208, 4880}, rot=90, image="npc1", trade={{-200,100},{-202,100},{-203,100},{-204,100},{-205,100},{-206,100},{-207,100},{-208,100},{-209,100}}},
[9] = {"Chair buyer", pos={4208, 5040}, rot=90, image="npc3", trade={{-210,75},{-214,75}}},
[10] = {"Table buyer", pos={3888, 4880}, rot=270, image="npc6", trade={{-218,150},{-219,150}}},
[11] = {"Doll buyer", 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={2768, 1552}, rot=0, image="npc1"},
[14] = {"Food Buyer", pos={6000, 912}, rot=180, image="npc5", trade={{-1,25},{-4,50},{-6,100},{-7,100},{-8,50}}},
[15] = {"Rune Seller", pos={6000, 1168}, rot=0, image="npc4", trade={{100,100},{101,100},{102,75},{103,100},{104,100},{105,100},{106,100}}},
[16] = {"Horse Trader", pos={2144, 2319}, rot=180, 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}}},
[18] = {"Ship captain [Secret island]", pos={752, 8624}, rot=90, image="npc4"},
}
NPCs[1].func = function(npc, id, words, state)
if words == "hi" then
NPCspeak(npc, "Welcome! Are you want to sail somewhere ?")
PLAYERS[id].tmp.npcstate = {npc, 1}
elseif state == 1 then
if words=="no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
NPCspeak(npc, "So where you want to sail:")
NPCspeak(npc, "[1] <- New island")
NPCspeak(npc, "[2] <- House island")
NPCspeak(npc, "[3] <- Secret island")
PLAYERS[id].tmp.npcstate = {npc, 2}
end
elseif state == 2 then
if words == "anywhere" or words == "nowhere" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "1" then
NPCspeak(npc, "So you want sail to new island.")
NPCspeak(npc, "It's cost only 100$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 3}
elseif words == "2" then
NPCspeak(npc, "So you want sail to house island.")
NPCspeak(npc, "It's cost only 50$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 4}
elseif words == "3" then
NPCspeak(npc, "So you want sail to Secret island.")
NPCspeak(npc, "It's cost only 500$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 5}
end
elseif state == 3 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-100) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 4400 1040')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 4 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 5008 4752')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 5 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-500) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 784 8624')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
end
end
NPCs[2].func = function(npc, id, words, state)
if words == "hi" then
NPCspeak(npc, "Welcome! Are you want to sail somewhere ?")
PLAYERS[id].tmp.npcstate = {npc, 1}
elseif state == 1 then
if words=="no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
NPCspeak(npc, "So where you want to sail:")
NPCspeak(npc, "[1] <- Old island")
NPCspeak(npc, "[2] <- New island")
NPCspeak(npc, "[3] <- Secret island")
PLAYERS[id].tmp.npcstate = {npc, 2}
end
elseif state == 2 then
if words == "anywhere" or words == "nowhere" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "1" then
NPCspeak(npc, "So you want sail to old island.")
NPCspeak(npc, "It's cost only 50$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 3}
elseif words == "2" then
NPCspeak(npc, "So you want sail to new island.")
NPCspeak(npc, "It's cost only 50$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 4}
elseif words == "3" then
NPCspeak(npc, "So you want sail to Secret island.")
NPCspeak(npc, "It's cost only 500$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 5}
end
elseif state == 3 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 3248 2672')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 4 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 4400 1040')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 5 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-500) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 784 8624')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
end
end
NPCs[18].func = function(npc, id, words, state)
if words == "hi" then
NPCspeak(npc, "Welcome! Are you want to sail somewhere ?")
PLAYERS[id].tmp.npcstate = {npc, 1}
elseif state == 1 then
if words=="no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
NPCspeak(npc, "So where you want to sail:")
NPCspeak(npc, "[1] <- Old island")
NPCspeak(npc, "[2] <- New island")
NPCspeak(npc, "[3] <- House island")
PLAYERS[id].tmp.npcstate = {npc, 2}
end
elseif state == 2 then
if words == "anywhere" or words == "nowhere" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "1" then
NPCspeak(npc, "So you want sail to old island.")
NPCspeak(npc, "It's cost only 100$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 3}
elseif words == "2" then
NPCspeak(npc, "So you want sail to new island.")
NPCspeak(npc, "It's cost only 50$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 4}
elseif words == "3" then
NPCspeak(npc, "So you want sail to House island.")
NPCspeak(npc, "It's cost only 100$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 5}
end
elseif state == 3 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-100) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 3248 2672')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 4 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 4400 1040')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 5 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-100) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 5007 4758')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
end
end
NPCs[3].func = function(npc, id, words, state)
if words == "hi" then
NPCspeak(npc, "Welcome! Are you want to sail somewhere ?")
PLAYERS[id].tmp.npcstate = {npc, 1}
elseif state == 1 then
if words=="no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
NPCspeak(npc, "So where you want to sail:")
NPCspeak(npc, "[1] <- Old island")
NPCspeak(npc, "[2] <- House island")
NPCspeak(npc, "[3] <- Secret island")
PLAYERS[id].tmp.npcstate = {npc, 2}
end
elseif state == 2 then
if words == "anywhere" or words == "nowhere" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "1" then
NPCspeak(npc, "So you want sail to old island.")
NPCspeak(npc, "It's cost only 100$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 3}
elseif words == "2" then
NPCspeak(npc, "So you want sail to house island.")
NPCspeak(npc, "It's cost only 50$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 4}
elseif words == "3" then
NPCspeak(npc, "So you want sail to Secret island.")
NPCspeak(npc, "It's cost only 500$.")
NPCspeak(npc, "Do you want sail ?")
PLAYERS[id].tmp.npcstate = {npc, 5}
end
elseif state == 3 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-100) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 3248 2672')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 4 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 5008 4752')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
elseif state == 5 then
if words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
elseif words == "yes" then
if addmoney(id,-500) then
NPCspeak(npc, "Bon Voyage.")
parse('setpos '..id..' 784 8624')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
end
end
NPCs[13].func = function(npc, id, words, state)
if words == "hi" then
NPCspeak(npc, "Hi do you want rest it's cost only $50 ?")
PLAYERS[id].tmp.npcstate = {npc, 1}
elseif state == 1 then
if words == "yes" then
if addmoney(id,-50) then
NPCspeak(npc, "Have good rest !")
parse('setpos '..id..' 2736 1648')
PLAYERS[id].tmp.npcstate = {npc, 0}
else
NPCspeak(npc, "You don't have enought money bye !")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
elseif words == "no" then
NPCspeak(npc, "Bye then.")
PLAYERS[id].tmp.npcstate = {npc, 0}
end
end
end
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 .. "|" .. 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, "yo") 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
edited 3×, last 14.04.11 06:42:38 pm